aboutsummaryrefslogtreecommitdiff
path: root/demos/sample-files/lbp.g
blob: 1dd176c7d4252b8b58814a3301d4a8a158c23907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-terminal NUM IDEN ATOM
          COMMA SEMICOL DOT COLON
          RPAREN LPAREN RBRACE LBRACE

          TYPELIST_START TYPELIST_END
          T_INT T_ENUM T_STRUCT
          ST_FUNCTION ST_BIG ST_LITTLE ST_NATIVE;

-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 { v = A(0); };

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 { 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 { 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 { 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 {}
        | T_ENUM   {} | T_ENUM LPAREN ATOM RPAREN {};
subtypelist: ST_FUNCTION LPAREN exprlist RPAREN {}
           | ST_BIG {} | ST_LITTLE {} | ST_NATIVE {}
           | subtypelist subtypelist {}.