]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added parsing rule for function calls and stubbed out hooks for if/for/while/do-while...
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 19 Jun 2018 18:58:00 +0000 (14:58 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 19 Jun 2018 18:58:00 +0000 (14:58 -0400)
example.src
source/parser.c

index 269ce457b212d8de6564123090d7776bab169d8f..2a2416d933511ac0229e4ad5468ff3d0595291dc 100644 (file)
@@ -33,6 +33,9 @@ fun main() int {
     {123;}
     123;
     (123);
+    foo();
+    bar(1);
+    baz(1,2);
     return bar;
 }
 
index 60f0feb319336158752508e46adbd144b484ec10..524df58bf98e89c188ea417c224100720eaa1191 100644 (file)
@@ -13,6 +13,7 @@ static AST* expression_block(Parser* p);
 static AST* statement(Parser* p);
 static AST* expression(Parser* p);
 static AST* definition(Parser* p, bool constant);
+static AST* func_expr_list(Parser* p);
 
 static AST* const_expression(Parser* p);
 static AST* identifier(Parser* p);
@@ -205,11 +206,17 @@ static AST* statement(Parser* p) {
     if (matches(p, '{')) {
         expression_block(p);
     } else {
-        if (accept(p, T_RETURN)) {
+        if (matches(p, T_LET) || matches(p, T_VAR)) {
+            definition(p, (peek(p)->type == T_LET));
+        } else if (accept(p, T_RETURN)) {
             expression(p);
             expect(p, ';');
-        } else if (matches(p, T_LET) || matches(p, T_VAR)) {
-            definition(p, (peek(p)->type == T_LET));
+//        } else if (matches(p, T_IF)) {
+//        } else if (matches(p, T_WHILE)) {
+//        } else if (matches(p, T_FOR)) {
+//        } else if (matches(p, T_DO)) {
+//        } else if (matches(p, T_SWITCH)) {
+//        } else if (matches(p, T_MATCH)) {
         } else {
             expression(p);
             expect(p, ';');
@@ -225,6 +232,8 @@ static AST* expression(Parser* p) {
         expect(p, ')');
     } else if (matches(p, T_ID)) {
         expr = identifier(p);
+        if (matches(p, '('))
+            func_expr_list(p);
     } else {
         expr = literal(p);
     }
@@ -237,12 +246,25 @@ static AST* definition(Parser* p, bool constant) {
     expect(p, T_ID);
     type_expression(p);
     expect(p, '=');
-    const_expression(p);
+    expression(p);
     expect(p, ';');
     return NULL;
 }
 
-
+static AST* func_expr_list(Parser* p) {
+    expect(p, '(');
+    if (!matches(p, ')')) {
+        while (true) {
+            expression(p);
+            if (!matches(p, ')'))
+                expect(p, ',');
+            else
+                break;
+        }
+    }
+    expect(p, ')');
+    return NULL;
+}