]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added array initialization
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 29 Mar 2019 02:09:21 +0000 (22:09 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 29 Mar 2019 02:09:21 +0000 (22:09 -0400)
example.src
source/lex.c
source/parser.c

index 6200d0d6369c418a697e7dd19087118b326530e7..0c6e5131fc2eee7c798c7f220d71ea3790b4f9b7 100644 (file)
@@ -1,16 +1,6 @@
 require ("fmt")
 provide (main)
 
-let const_true bool = true
-let const_false bool = false
-let const_uint int = 123
-let const_string string = ""
-
-var var_true bool = true
-var var_false bool = false
-var var_uint int = 123
-var var_string string = ""
-
 type type_int = int
 type type_intary = int[]
 type type_intaryary = int[][]
@@ -26,6 +16,18 @@ type type_union = union {
     bar = float
 }
 
+let const_true bool = true
+let const_false bool = false
+let const_uint int = 123
+let const_string string = ""
+let const_intary int[] = [123,321]
+
+var var_true bool = true
+var var_false bool = false
+var var_uint int = 123
+var var_string string = ""
+var var_intary int[] = [123,321]
+
 fun main(args string[]) int {
     let foo int = 123
     var bar int = 123
index de5bba9eaf9e3720c13d5b6a36f25a0f2df288a6..1351a9843dcf6e5bd16c5844805d4e8555d941ab 100644 (file)
@@ -215,7 +215,7 @@ void lex(Parser* ctx) {
     }
 }
 
-static LexFile* get_file(Parser* p, char* path) {
+static LexFile* get_file(Parser* p, char const* path) {
     LexFile* lf = p->file;
     while (lf && strcmp(lf->path, path))
         lf = lf->next;
index dd01fb2e9ee40ceca589cb528a11e1e31e275cf5..55a0ecc780f8436b50aae4c4e70ffe50c95a8437 100644 (file)
@@ -14,7 +14,7 @@ static AST* struct_fields(Parser* p);
 static AST* expression_block(Parser* p);
 static AST* if_expression(Parser* p);
 static AST* identifier(Parser* p);
-static AST* func_expr_list(Parser* p);
+static AST* expr_list(Parser* p, int firstc, int endc);
 
 /* Parsing Routines
  *****************************************************************************/
@@ -158,6 +158,8 @@ static AST* expression(Parser* p) {
         expect(p, '(');
         exp = expression(p);
         expect(p, ')');
+    } else if (matches(p, '[')) {
+        exp = expr_list(p, '[', ']');
     } else if (matches(p, '{')) {
         exp = expression_block(p);
     } else if (matches(p, T_IF)) {
@@ -170,10 +172,10 @@ static AST* expression(Parser* p) {
 
     /* determine if this is a function call */
     if (matches(p, '(')) {
-        exp = Apply(exp, func_expr_list(p));
+        exp = Apply(exp, expr_list(p, '(', ')'));
     } else if (accept(p, '.')) {
         AST* func = identifier(p);
-        AST* args = func_expr_list(p);
+        AST* args = expr_list(p, '(', ')');
         explist_prepend(args, exp);
         exp = Apply(func, args);
     }
@@ -274,15 +276,18 @@ static AST* identifier(Parser* p) {
     }
 }
 
-static AST* func_expr_list(Parser* p) {
-    expect(p, '(');
+static AST* expr_list(Parser* p, int firstc, int endc) {
+    expect(p, firstc);
     AST* list = ExpList();
-    while (!matches(p, ')')) {
+    while (!matches(p, endc)) {
         explist_append(list, expression(p));
-        if (!matches(p, ')'))
+        if (!matches(p, endc)) {
             expect(p, ',');
+            if (matches(p, endc))
+                error(p, "Expected an expression");
+        }
     }
-    expect(p, ')');
+    expect(p, endc);
     return list;
 }