-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPP.cf
More file actions
77 lines (57 loc) · 1.95 KB
/
CPP.cf
File metadata and controls
77 lines (57 loc) · 1.95 KB
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
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 ;
-- Requires define for (see below)
-- The type of for. is a bit hacky-wacky
for. Stm ::= "for" "(" Stm Exp ";" Stm ")" Stm ;
SBlock. Stm ::= "{" [Stm] "}" ;
SIfElse. Stm ::= "if" "(" Exp ")" Stm Else ;
EElse. Else ::= "else" Stm ;
EEmpty. Else ::= ;
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 ::= Exp15 "++" ;
EPDecr. Exp14 ::= Exp15 "--" ;
EIncr. Exp13 ::= "++" Exp14 ;
EDecr. Exp13 ::= "--" Exp14 ;
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 ;
ECast. Exp2 ::= "(" Type ")" Exp3 ;
EAss. Exp1 ::= Exp2 "=" Exp1 ;
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 "/*" "*/" ;
-- Only exporting Program
entrypoints Program ;
-- Syntax sugar for 'for'
define for i c s b = SBlock [i, SWhile c (SBlock [b, s])] ;