]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
CP: Parser rewrite. Builds but not functional yet.
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Apr 2014 12:24:54 +0000 (08:24 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Apr 2014 12:24:54 +0000 (08:24 -0400)
source/slvm/main.c
source/slvm/parser.c
source/slvm/parser.h

index 708cf664d7b8b5fe30b99d781be4dbd0f85e485a..1af77d9d8c93233208d24199be3b6139d4503eb7 100644 (file)
@@ -5,6 +5,7 @@
 #include <errno.h>
 #include <limits.h>
 #include "slvm.h"
+#include "parser.h"
 
 /*
     Wish List:
@@ -147,13 +148,20 @@ defcode("fpeekc", _fpeekc, 0, &_fputc){
 
 /* Interpreter Words
  *****************************************************************************/
-// defcode("fetch",  , 0, &){}
-// defcode("parse",  , 0, &){}
+defcode("fetch", _fetch, 0, &_fpeekc){
+    ArgStackPtr++;
+    *(ArgStackPtr) = (val_t)fetch_token((FILE*)_stdin_val);
+}
+
+defcode("parse", _parse, 0, &_fetch){
+    ArgStackPtr++;
+    *(ArgStackPtr-1) = (val_t)parse( (char*)*(ArgStackPtr-1), ArgStackPtr );
+}
 // defcode("interp", , 0, &){}
 
 /* Input Words
  *****************************************************************************/
-defcode("getc", get_char, 0, &_fpeekc){
+defcode("getc", get_char, 0, &_parse){
     ArgStackPtr++;
     *(ArgStackPtr) = getc(stdin);
 }
index e6dce38fca9066e04071542cffb60cb234f9abcd..e98577ce579158645079b45a1cd6a79df643a109 100644 (file)
@@ -5,25 +5,28 @@
   $HeadURL$
   */
 #include "parser.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
 
 /* Fetching Tokens
  *****************************************************************************/
 static void skip_whitespace(FILE* input);
 static void skip_comment(FILE* input);
-static void parse_string(FILE* input);
-static void parse_token(FILE* input);
+static char* parse_string(FILE* input);
+static char* parse_token(FILE* input);
 static void grow_token(size_t* p_size, size_t* p_index, char** p_p_str, char ch);
 static bool is_whitespace(FILE* input);
 static char fpeekc(FILE* input);
 
-char* fetch(FILE* input)
+char* fetch_token(FILE* input)
 {
     char* result = NULL;
-    skip_whitespace();
+    skip_whitespace(input);
     switch(fpeekc(input))
     {
-        case '#':  skip_comment();
-                   result = fetch(input);
+        case '#':  skip_comment(input);
+                   result = fetch_token(input);
                    break;
         case '"':  result = parse_string(input);
                    break;
@@ -100,7 +103,7 @@ static void skip_comment(FILE* input)
 
 static bool is_whitespace(FILE* input)
 {
-    char ch = peekc(input);
+    char ch = fpeekc(input);
     return ((ch == ' ')  || (ch == '\t') ||
             (ch == '\r') || (ch == '\n'));
 }
@@ -119,9 +122,9 @@ static bool is_integer(val_t* p_val);
 static bool is_string(val_t* p_val);
 static bool is_char(val_t* p_val);
 
-ValueType_T parse(char* str, val_t* p_val)
+TokenType_T parse(char* str, val_t* p_val)
 {
-    ValueType_T type = ERROR;
+    TokenType_T type = ERROR;
     if(str != NULL)
     {
         if(!is_float(p_val) &&
index 099df11bbcc6fb2c07552455439937c9ead57acf..08beeb231b034cf04d4b2a77f7cc3ab829836c57 100644 (file)
@@ -8,6 +8,7 @@
 #define PARSER_H
 
 #include "slvm.h"
+#include <stdio.h>
 
 typedef enum {
     WORD = 0,
@@ -18,8 +19,8 @@ typedef enum {
     ERROR
 } TokenType_T;
 
-char* fetch(FILE* input);
+char* fetch_token(FILE* input);
 
-ValueType_T parse(char* str, val_t* p_val);
+TokenType_T parse(char* str, val_t* p_val);
 
 #endif /* PARSER_H */