~kameliya/kyuubey

ref: d9a0d7a434006111c22850e83377d22d3f2f22eb kyuubey/lang.y -rw-r--r-- 1.3 KiB
d9a0d7a4 — Yuki Izumi exprs (should be expr_imm or sth), print wip 6 years ago
                                                                                
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
56
%{
    #include "parser.h"
%}

%parse-param {ast_t *ast}
%error-verbose

%union {
    ast_comment_t *comment;
    ast_token_t *token;
    ast_expr_t *expr;

    ast_stmt_t *stmt;
}

%token END_OF_FILE 0 "$end"

%token NL

%token <token> TOKEN
%token <expr> EXPR
%token <comment> COMMENT

%type <stmt> line stmt
%type <expr> exprlist opt_exprlist

%%

input:          /* empty */
              | input line { if ($2) { ast_append_stmt(ast, $2); } }
;

line_separator: NL
              | ':'
;

line:           line_separator          { $$ = 0; }
              | stmt line_separator     { $$ = $1; }
              | stmt END_OF_FILE        { $$ = $1; }
;

stmt:           TOKEN opt_exprlist      { $$ = ast_stmt_alloc(STMT_CALL); $$->call.target = $1; $$->call.args = $2; }
              | COMMENT                 { $$ = ast_stmt_alloc(STMT_COMMENT); $$->comment = $1; }
;

exprlist:       EXPR                    { $$ = $1; }
              | exprlist ',' EXPR       { $$ = $1; $1->next = $3; $1->nexttype = ','; }
              | exprlist ';' EXPR       { $$ = $1; $1->next = $3; $1->nexttype = ';'; }
              | exprlist EXPR           { $$ = $1; $1->next = $2; $1->nexttype = ';'; }
;

opt_exprlist:   /* empty */             { $$ = 0; }
              | exprlist                { $$ = $1; }
;

/* vim: set sw=4 et: */