-
Notifications
You must be signed in to change notification settings - Fork 0
/
bison_spl_y_top.y
129 lines (97 loc) · 2.97 KB
/
bison_spl_y_top.y
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* $Id: bison_spl_y_top.y,v 1.2 2024/10/09 18:18:55 leavens Exp $ */
%code top {
#include <stdio.h>
}
%code requires {
/* Including "ast.h" must be at the top, to define the AST type */
#include "ast.h"
#include "machine_types.h"
#include "parser_types.h"
#include "lexer.h"
/* Report an error to the user on stderr */
extern void yyerror(const char *filename, const char *msg);
} /* end of %code requires */
%verbose
%define parse.lac full
%define parse.error detailed
/* the following passes file_name to yyerror,
and declares it as an formal parameter of yyparse. */
%parse-param { char const *file_name }
%token <ident> identsym
%token <number> numbersym
%token <token> plussym "+"
%token <token> minussym "-"
%token <token> multsym "*"
%token <token> divsym "/"
%token <token> periodsym "."
%token <token> semisym ";"
%token <token> eqsym "="
%token <token> commasym ","
%token <token> becomessym ":="
%token <token> lparensym "("
%token <token> rparensym ")"
%token <token> constsym "const"
%token <token> varsym "var"
%token <token> procsym "proc"
%token <token> callsym "call"
%token <token> beginsym "begin"
%token <token> endsym "end"
%token <token> ifsym "if"
%token <token> thensym "then"
%token <token> elsesym "else"
%token <token> whilesym "while"
%token <token> dosym "do"
%token <token> readsym "read"
%token <token> printsym "print"
%token <token> divisiblesym "divisible"
%token <token> bysym "by"
%token <token> eqeqsym "=="
%token <token> neqsym "!="
%token <token> ltsym "<"
%token <token> leqsym "<="
%token <token> gtsym ">"
%token <token> geqsym ">="
%type <block> program
%type <block> block
%type <const_decls> constDecls
%type <const_decl> constDecl
%type <const_def_list> constDefList
%type <const_def> constDef
%type <var_decls> varDecls
%type <var_decl> varDecl
%type <ident_list> identList
%type <proc_decls> procDecls
%type <proc_decl> procDecl
%type <stmts> stmts
%type <empty> empty
%type <stmt_list> stmtList
%type <stmt> stmt
%type <assign_stmt> assignStmt
%type <call_stmt> callStmt
%type <if_stmt> ifStmt
%type <while_stmt> whileStmt
%type <read_stmt> readStmt
%type <print_stmt> printStmt
%type <block_stmt> blockStmt
%type <condition> condition
%type <db_condition> dbCondition
%type <rel_op_condition> relOpCondition
%type <token> relOp
%type <expr> expr
%type <expr> term
%type <expr> factor
%start program
%code {
/* extern declarations provided by the lexer */
extern int yylex(void);
/* The AST for the program, set by the semantic action
for the nonterminal program. */
block_t progast;
/* Set the program's ast to be t */
extern void setProgAST(block_t t);
}
%%
/* Write your grammar rules below and before the next %% */
%%
// Set the program's ast to be ast
void setProgAST(block_t ast) { progast = ast; }