From: Michael D. Lowis Date: Mon, 18 Jun 2018 01:47:06 +0000 (-0400) Subject: stubbed out struct and union parsing X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=0ff653fb200e1f8327a5589ec507da44273aa06f;p=proto%2Fsclpl.git stubbed out struct and union parsing --- diff --git a/example.src b/example.src index 1b023c8..2ce3f21 100644 --- a/example.src +++ b/example.src @@ -12,6 +12,8 @@ var const_uint int = 123; var const_string string = ""; type type_int = int; +type type_struct = struct; +type type_union = union; # type type_intary int[] # type type_intary42 int[42] # type type_intaryary int[][] diff --git a/source/lexer.l b/source/lexer.l index 9916d4b..7276a7a 100644 --- a/source/lexer.l +++ b/source/lexer.l @@ -35,10 +35,12 @@ NOSPACE [^ \t\r\n] "require" { return T_REQUIRES; } "provide" { return T_PROVIDES; } -"let" { return T_LET; } -"var" { return T_VAR; } -"fun" { return T_FUN; } -"type" { return T_TYPE; } +"let" { return T_LET; } +"var" { return T_VAR; } +"fun" { return T_FUN; } +"type" { return T_TYPE; } +"struct" { return T_STRUCT; } +"union" { return T_UNION; } "if" { return T_IF; } "else" { return T_ELSE; } diff --git a/source/parser.c b/source/parser.c index 10952db..23f5c3b 100644 --- a/source/parser.c +++ b/source/parser.c @@ -70,12 +70,10 @@ static Tok* expect_val(Parser* p, TokType type) { /* Grammar Definition *****************************************************************************/ AST* toplevel(Parser* p) { - if (matches(p, T_REQUIRES)) { + if (matches(p, T_REQUIRES)) require_list(p); - } - if (matches(p, T_PROVIDES)) { + if (matches(p, T_PROVIDES)) provide_list(p); - } definition_list(p); return NULL; } @@ -160,7 +158,13 @@ static AST* const_expression(Parser* p) { } static AST* type_expression(Parser* p) { - expect(p, T_ID); + if (matches(p, T_STRUCT)) { + expect(p, T_STRUCT); + } else if (matches(p, T_UNION)) { + expect(p, T_UNION); + } else { + expect(p, T_ID); + } return NULL; } diff --git a/source/sclpl.h b/source/sclpl.h index 7c8d3a9..6d9c8f4 100644 --- a/source/sclpl.h +++ b/source/sclpl.h @@ -41,7 +41,8 @@ void vec_set(vec_t* vec, size_t index, void* data); *****************************************************************************/ typedef enum { T_NONE, T_ERROR, T_END_FILE, - T_PACKAGE, T_REQUIRES, T_PROVIDES, T_LET, T_VAR, T_FUN, T_TYPE, + T_PACKAGE, T_REQUIRES, T_PROVIDES, T_LET, T_VAR, T_FUN, T_TYPE, T_STRUCT, + T_UNION, 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_SEMI