aboutsummaryrefslogtreecommitdiff
path: root/demos/sample-files/lbp.g
diff options
context:
space:
mode:
authorkartofen <kartofen.mail.0@protonmail.com>2025-09-13 15:24:28 +0300
committerkartofen <kartofen.mail.0@protonmail.com>2025-09-13 15:24:28 +0300
commitdb1b9c8dcb0d115217a33c2fe8e0760d49143e11 (patch)
treec93743adff3d78ea066c14879b7d2bfeb3ce42fb /demos/sample-files/lbp.g
parent46e786db9d1b48b8fbc3502e36f093b755f3e09f (diff)
ast nearly build and proper errors
Diffstat (limited to 'demos/sample-files/lbp.g')
-rw-r--r--demos/sample-files/lbp.g46
1 files changed, 31 insertions, 15 deletions
diff --git a/demos/sample-files/lbp.g b/demos/sample-files/lbp.g
index bc82cb3..1dd176c 100644
--- a/demos/sample-files/lbp.g
+++ b/demos/sample-files/lbp.g
@@ -8,28 +8,44 @@
-nonterminal S exprlist expr sym fieldlist basetype subtypelist.
+-stacktype { union {
+ int num;
+ char *str;
+
+ struct ast_vrbl vrbl;
+ struct ast_fiel fiel;
+ struct ast_decl decl;
+ struct ast_defn defn;
+ struct ast_oprn oprn;
+
+ struct ast_expr expr;
+ struct ast_strlist strlist;
+ struct list_head *list;
+ }}.
+
-left LPAREN;
-left COMMA SEMICOL.
-S: exprlist DOT {};
+S: exprlist DOT { v = A(0); };
-exprlist: expr {}
- | exprlist expr {}
- | exprlist COMMA exprlist {}
- | exprlist SEMICOL exprlist {};
+exprlist: expr { v = g_LST(A(0).expr); }
+ | expr exprlist { v = g_LST(A(0).expr); v.list->next = A(1).list; }
+ | exprlist COMMA exprlist { v = g_LST(NEW(expr, .type = AST_OPERATION, .operation = NEW(oprn, .optype = AST_OP_AND, .left_exprlist = A(0).list, .right_exprlist = A(2).list))); }
+ | exprlist SEMICOL exprlist { v = g_LST(NEW(expr, .type = AST_OPERATION, .operation = NEW(oprn, .optype = AST_OP_OR, .left_exprlist = A(0).list, .right_exprlist = A(2).list)));};
-expr: NUM {}
- | sym {}
- | sym fieldlist {}
- | sym TYPELIST_START basetype TYPELIST_END {}
- | sym TYPELIST_START basetype subtypelist TYPELIST_END {}
- | LBRACE exprlist DOT RBRACE {}
- | LPAREN exprlist RPAREN {};
+expr: NUM { v = g_NEW(expr, .type = AST_NUMBER, .number = A(0).num); }
+ | sym { v = g_NEW(expr, .type = AST_VARIABLE, .variable = A(0).vrbl); }
+ | sym fieldlist { v = g_NEW(expr, .type = AST_FIELDLIST, .fieldlist = NEW(fiel, .variable = A(0).vrbl, .fields_strlist = A(1).list)); }
+ | sym TYPELIST_START basetype TYPELIST_END { v = g_NEW(expr, .type = AST_VARIABLE, .variable = A(0).vrbl); }
+ | sym TYPELIST_START basetype subtypelist TYPELIST_END { v = g_NEW(expr, .type = AST_VARIABLE, .variable = A(0).vrbl); }
+ | LBRACE exprlist DOT RBRACE { v = g_NEW(expr, .type = AST_PARENLIST, .paren_exprlist = A(1).list); }
+ | LPAREN exprlist RPAREN { v = g_NEW(expr, .type = AST_PARENLIST, .paren_exprlist = A(1).list); };
-sym: IDEN {} | ATOM {};
+sym: IDEN { v = g_NEW(vrbl, .is_atom = 0, .iden = A(0).str); }
+ | ATOM { v = g_NEW(vrbl, .is_atom = 1, .iden = A(0).str); };
-fieldlist: COLON IDEN {}
- | fieldlist fieldlist {};
+fieldlist: COLON IDEN { v = g_LST(NEW(strlist, .str = A(1).str)); }
+ | fieldlist fieldlist { A(0).list->next = A(1).list; v = A(0); };
basetype: T_INT {}
| T_STRUCT {} | T_STRUCT LPAREN ATOM RPAREN {}