forked from sadegh-majidi/compiler-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar_rules.txt
78 lines (78 loc) · 3.07 KB
/
grammar_rules.txt
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
Program -> Declaration-list $
Declaration-list -> Declaration Declaration-list
Declaration-list -> EPSILON
Declaration -> Declaration-initial Declaration-prime
Declaration-initial -> @save_type Type-specifier @assign_type ID
Declaration-prime -> @ass_func_role Fun-declaration-prime
Declaration-prime -> @ass_var_role Var-declaration-prime
Var-declaration-prime -> @assign_len ;
Var-declaration-prime -> [ @assign_len NUM ] ;
Fun-declaration-prime -> ( @inc_scope Params @ass_fun_attrs ) Compound-stmt #stackframe #return_seq_callee @dec_scope
Type-specifier -> int
Type-specifier -> void
Params -> @save_type @save_param int @assign_type ID @assign_param_role Param-prime Param-list
Params -> void
Param-list -> , @save_param Param Param-list
Param-list -> EPSILON
Param -> Declaration-initial @assign_param_role Param-prime
Param-prime -> @assign_len [ ]
Param-prime -> @assign_len EPSILON
Compound-stmt -> { Declaration-list Statement-list }
Statement-list -> Statement Statement-list
Statement-list -> EPSILON
Statement -> Expression-stmt
Statement -> Compound-stmt
Statement -> Selection-stmt
Statement -> Iteration-stmt
Statement -> Return-stmt
Expression-stmt -> Expression #end_stmt ;
Expression-stmt -> @check_break #break_jp_save break ;
Expression-stmt -> ;
Selection-stmt -> if ( Expression ) #save Statement Else-stmt
Else-stmt -> endif #endif
Else-stmt -> else #else Statement endif #if_else
Iteration-stmt -> @push_until repeat #label #init_rep_until Statement until ( Expression ) #until @pop_until
Return-stmt -> return Return-stmt-prime #set_retval #return_seq_callee
Return-stmt-prime -> ;
Return-stmt-prime -> Expression ;
Expression -> Simple-expression-zegond
Expression -> @check_decl @save_func @save_type_check #pid ID B
B -> = Expression @type_check #assign
B -> @index_array [ Expression ] #index_array @index_array_pop H
B -> Simple-expression-prime
H -> = Expression @type_check #assign
H -> G D C
Simple-expression-zegond -> Additive-expression-zegond C
Simple-expression-prime -> Additive-expression-prime C
C -> #save_op Relop Additive-expression @type_check #relop
C -> EPSILON
Relop -> <
Relop -> ==
Additive-expression -> Term D
Additive-expression-prime -> Term-prime D
Additive-expression-zegond -> Term-zegond D
D -> #save_op Addop Term @type_check #addop D
D -> EPSILON
Addop -> +
Addop -> -
Term -> Factor G
Term-prime -> Factor-prime G
Term-zegond -> Factor-zegond G
G -> * Factor @type_check #mult G
G -> EPSILON
Factor -> ( Expression )
Factor -> @check_decl @save_func @save_type_check #pid ID Var-call-prime
Factor -> @save_type_check #pconst NUM
Var-call-prime -> @push_arg_stack ( Args @check_args ) #call_seq_caller @pop_arg_stack
Var-call-prime -> Var-prime
Var-prime -> @index_array [ Expression ] #index_array @index_array_pop
Var-prime -> EPSILON
Factor-prime -> @push_arg_stack ( Args @check_args ) #call_seq_caller @pop_arg_stack
Factor-prime -> EPSILON
Factor-zegond -> ( Expression )
Factor-zegond -> @save_type_check #pconst NUM
Args -> Arg-list
Args -> EPSILON
Arg-list -> @save_arg Expression Arg-list-prime
Arg-list-prime -> , @save_arg Expression Arg-list-prime
Arg-list-prime -> EPSILON