-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammer.txt
45 lines (45 loc) · 2.33 KB
/
grammer.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
Program -> Declaration-list #at_the_end $
Declaration-list -> Declaration Declaration-list | EPSILON
Declaration -> Declaration-initial Declaration-prime
Declaration-initial -> Type-specifier #pid ID
Declaration-prime -> #save_first_func Fun-declaration-prime | Var-declaration-prime
Var-declaration-prime -> #set_tmp_value ; | [ NUM ] #set_tmp_addr #pop ;
Fun-declaration-prime -> #set_starting_line ( Params ) #declaration_after_header Compound-stmt #push_zero #declaration_after_return #after_func_declaration
Type-specifier -> int | void
Params -> int #pid ID Param-prime Param-list | void
Param-list -> , Param Param-list | EPSILON
Param -> Declaration-initial Param-prime
Param-prime -> [ ] | EPSILON
Compound-stmt -> { Declaration-list Statement-list }
Statement-list -> Statement Statement-list | EPSILON
Statement -> Expression-stmt | Compound-stmt | Selection-stmt | Iteration-stmt | Return-stmt | output ( Expression #output ) ;
Expression-stmt -> Expression ; #pop | #break break ; | ;
Selection-stmt -> if ( Expression ) #save Statement Else-stmt
Else-stmt -> endif #jpf | else #jpf_save Statement endif #jp
Iteration-stmt -> repeat #label Statement until ( Expression ) #until
Return-stmt -> return Return-stmt-prime
Return-stmt-prime -> #push_zero #declaration_after_return ; | Expression #declaration_after_return ;
Expression -> Simple-expression-zegond | #pid ID B
B -> = Expression #assign | [ Expression #parr ] H | Simple-expression-prime
H -> = Expression #assign | G D C
Simple-expression-zegond -> Additive-expression-zegond C
Simple-expression-prime -> Additive-expression-prime C
C -> #push Relop Additive-expression #comp_op | EPSILON
Relop -> < | ==
Additive-expression -> Term D
Additive-expression-prime -> Term-prime D
Additive-expression-zegond -> Term-zegond D
D -> #push Addop Term #add_op D | EPSILON
Addop -> + | -
Term -> Factor G
Term-prime -> Factor-prime G
Term-zegond -> Factor-zegond G
G -> * Factor #mult_op G | EPSILON
Factor -> ( Expression ) | #pid ID Var-call-prime | #pnum NUM
Var-call-prime -> ( #call_begin Args #call_end ) | Var-prime
Var-prime -> [ Expression #parr ] | EPSILON
Factor-prime -> ( #call_begin Args #call_end ) | EPSILON
Factor-zegond -> ( Expression ) | #pnum NUM
Args -> Arg-list | EPSILON
Arg-list -> Expression #call_add_args Arg-list-prime
Arg-list-prime -> , Expression #call_add_args Arg-list-prime | EPSILON