]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
fixed first pass at function parsing
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 14 Jun 2018 17:14:13 +0000 (13:14 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 14 Jun 2018 17:14:13 +0000 (13:14 -0400)
example.src
source/lexer.l
source/parser.c

index 1d63d64704bf598ba34711b66b4662c1e855759a..583ac3e29380cc7dea88eb53748af0c01310125e 100644 (file)
@@ -22,5 +22,9 @@ var const_string string = ""
 # type type_intptrptr int**
 # type type_intref int&
 
+fun main() int {
+}
+
+
 
 
index 659355b06ce87fd8140f2847b6e08a8a130cd66e..f7cb95243a016bfd73e4995b6be13852ea1cd20f 100644 (file)
@@ -33,8 +33,6 @@ NOSPACE [^ \t\r\n]
 [ \t\r\n] { /* whitespace is insignificant */ }
 #.*[\r\n] { /* skip line comments */ }
 
-<<EOF>>   { return T_END_FILE; }
-
 "package"  { return T_PACKAGE;  }
 "requires" { return T_REQUIRES; }
 "provides" { return T_PROVIDES; }
@@ -115,6 +113,8 @@ false {
     return T_ID;
 }
 
+<<EOF>> { return T_END_FILE; }
+
 . { return T_ERROR; }
 
 %%
index 39ac254dcdf47e0873ea6c94fbffab509202f1b7..859412bf3ee67f12216ba7f4addbe223515a6a92 100644 (file)
@@ -103,11 +103,11 @@ static void provide_list(Parser* p) {
 static AST* definition_list(Parser* p) {
     while (!matches(p, T_END_FILE)) {
         TokType type = peek(p)->type;
-        if (accept(p, T_LET) || accept(p, T_VAR)) {
+        if (matches(p, T_LET) || matches(p, T_VAR)) {
             const_definition(p, (type == T_LET));
-        } else if (accept(p, T_TYPE)) {
+        } else if (matches(p, T_TYPE)) {
             type_definition(p);
-        } else if (accept(p, T_FUN)) {
+        } else if (matches(p, T_FUN)) {
             func_definition(p);
         } else {
             error(p, "only definitions are allowed at the toplevel");
@@ -117,6 +117,8 @@ static AST* definition_list(Parser* p) {
 }
 
 static AST* const_definition(Parser* p, bool constant) {
+    if (!accept(p, T_LET) && !accept(p, T_VAR))
+        error(p, "constant or variable definition expected");
     Tok* id = expect_val(p, T_ID);
     Type* type = type_annotation(p);
     expect(p, T_ASSIGN);
@@ -135,6 +137,13 @@ static AST* type_definition(Parser* p) {
 }
 
 static AST* func_definition(Parser* p) {
+    expect(p, T_FUN);
+    expect(p, T_ID);
+    expect(p, T_LPAR);
+    expect(p, T_RPAR);
+    type_expression(p);
+    expect(p, T_LBRACE);
+    expect(p, T_RBRACE);
     return NULL;
 }