-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPP.cf
68 lines (48 loc) · 1.61 KB
/
CPP.cf
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
entrypoints Program;
PDefs. Program ::= [Def] ;
DFun. Def ::= Type Id "(" [Arg] ")" "{" [Stm] "}" ;
terminator Def "" ;
ADecl. Arg ::= Type Id ;
separator Arg "," ;
SExp. Stm ::= Exp ";" ;
SDecls. Stm ::= Type [Id] ";" ;
SInit. Stm ::= Type Id "=" Exp ";" ;
SReturn. Stm ::= "return" Exp ";" ;
SReturnVoid. Stm ::= "return" ";" ;
SWhile. Stm ::= "while" "(" Exp ")" Stm ;
SBlock. Stm ::= "{" [Stm] "}" ;
SIfElse. Stm ::= "if" "(" Exp ")" Stm "else" Stm ;
terminator Stm "" ;
ETrue. Exp15 ::= "true" ;
EFalse. Exp15 ::= "false" ;
EInt. Exp15 ::= Integer ;
EDouble. Exp15 ::= Double ;
EString. Exp15 ::= String ;
EId. Exp15 ::= Id ;
EApp. Exp15 ::= Id "(" [Exp] ")" ;
EPIncr. Exp14 ::= Id "++" ;
EPDecr. Exp14 ::= Id "--" ;
EIncr. Exp13 ::= "++" Id ;
EDecr. Exp13 ::= "--" Id ;
ETimes. Exp12 ::= Exp12 "*" Exp13 ;
EDiv. Exp12 ::= Exp12 "/" Exp13 ;
EPlus. Exp11 ::= Exp11 "+" Exp12 ;
EMinus. Exp11 ::= Exp11 "-" Exp12 ;
ELt. Exp9 ::= Exp9 "<" Exp10 ;
EGt. Exp9 ::= Exp9 ">" Exp10 ;
ELtEq. Exp9 ::= Exp9 "<=" Exp10 ;
EGtEq. Exp9 ::= Exp9 ">=" Exp10 ;
EEq. Exp8 ::= Exp8 "==" Exp9 ;
ENEq. Exp8 ::= Exp8 "!=" Exp9 ;
EAnd. Exp4 ::= Exp4 "&&" Exp5 ;
EOr. Exp3 ::= Exp3 "||" Exp4 ;
EAss. Exp2 ::= Id "=" Exp2 ;
internal ETyped. Exp15 ::= "(" Exp ":" Type ")" ;
coercions Exp 15 ;
separator Exp "," ;
rules Type ::= "bool" | "int" | "double" | "void" | "string" ;
token Id (letter (letter | digit | '_')*) ;
separator nonempty Id "," ;
comment "#" ;
comment "//" ;
comment "/*" "*/" ;