]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added semicolons and = to type and value definitions
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 16 Jun 2018 02:34:33 +0000 (22:34 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 16 Jun 2018 02:34:33 +0000 (22:34 -0400)
example.src
source/lexer.l
source/parser.c
source/sclpl.h

index 583ac3e29380cc7dea88eb53748af0c01310125e..ed810ac83ebbedd32fabfb42c884f4d8316e97ef 100644 (file)
@@ -2,17 +2,17 @@ package main
 requires ("fmt")
 provides (main)
 
-let const_true bool = true
-let const_false bool = false
-let const_uint int = 123
-let const_string string = ""
+let const_true bool = true;
+let const_false bool = false;
+let const_uint int = 123;
+let const_string string = "";
 
-var const_true bool = true
-var const_false bool = false
-var const_uint int = 123
-var const_string string = ""
+var const_true bool = true;
+var const_false bool = false;
+var const_uint int = 123;
+var const_string string = "";
 
-# type type_int int
+type type_int = int;
 # type type_intary int[]
 # type type_intary42 int[42]
 # type type_intaryary int[][]
index f7cb95243a016bfd73e4995b6be13852ea1cd20f..9926b19db390bd553cf4e4924713688c1928e6f2 100644 (file)
@@ -39,6 +39,7 @@ NOSPACE [^ \t\r\n]
 "let"      { return T_LET;      }
 "var"      { return T_VAR;      }
 "fun"      { return T_FUN;      }
+"type"     { return T_TYPE;     }
 
 "if"   { return T_IF;     }
 "else" { return T_ELSE;   }
@@ -53,6 +54,7 @@ NOSPACE [^ \t\r\n]
 ":"    { return T_COLON;  }
 "&"    { return T_AMP;    }
 "="    { return T_ASSIGN; }
+";"    { return T_SEMI;   }
 
 \\.       { Value.character = yytext[1];    return T_CHAR; }
 \\space   { Value.character = ' ';          return T_CHAR; }
index 859412bf3ee67f12216ba7f4addbe223515a6a92..b15a47a2d6b83c0c548376c0bf27cd31cf89da37 100644 (file)
@@ -110,6 +110,7 @@ static AST* definition_list(Parser* p) {
         } else if (matches(p, T_FUN)) {
             func_definition(p);
         } else {
+            printf("%d\n", peek(p)->type);
             error(p, "only definitions are allowed at the toplevel");
         }
     }
@@ -123,16 +124,16 @@ static AST* const_definition(Parser* p, bool constant) {
     Type* type = type_annotation(p);
     expect(p, T_ASSIGN);
     AST* expr = const_expression(p);
-    sym_add(&(p->syms), (constant ? SF_CONSTANT : 0), id->value.text, type);
-    if (!types_equal(type, expr->datatype))
-        error(p, "type mismatch");
-    return Var(id, expr, constant);
+    expect(p, T_SEMI);
+    return NULL;
 }
 
 static AST* type_definition(Parser* p) {
     expect(p, T_TYPE);
     expect(p, T_ID);
+    expect(p, T_ASSIGN);
     type_expression(p);
+    expect(p, T_SEMI);
     return NULL;
 }
 
index c8e8e5d143619d23f5a0eebf9475d80d6356becd..7c8d3a9f3b81df501b944c4e532ce9c46a4d2d03 100644 (file)
@@ -44,7 +44,7 @@ typedef enum {
     T_PACKAGE, T_REQUIRES, T_PROVIDES, T_LET, T_VAR, T_FUN, T_TYPE,
     T_ID, T_CHAR, T_INT, T_FLOAT, T_BOOL, T_STRING,
     T_LBRACE, T_RBRACE, T_LBRACK, T_RBRACK, T_LPAR, T_RPAR, T_COMMA, T_SQUOTE,
-    T_DQUOTE, T_COLON, T_AMP, T_IF, T_ELSE, T_ASSIGN
+    T_DQUOTE, T_COLON, T_AMP, T_IF, T_ELSE, T_ASSIGN, T_SEMI
 } TokType;
 
 typedef struct {