]> ruin.nu Git - proglang.git/blob - syntax.cf
replace E with in
[proglang.git] / syntax.cf
1
2 -- ordinary rules
3
4
5 True.     Bool ::= "true" ;
6 False.    Bool ::= "false" ;
7
8 TInt.   Type  ::= "int" ;
9 TBool.  Type  ::= "bool" ;
10
11 Program.  Stms ::= [Stm] ;
12
13
14 SExp.      Stm      ::= Exp ";" ;
15 SBlock.    Stm      ::= "{" [Stm] "}" ;
16 SDecl. Stm ::= Type Ident "=" Exp ";" ;
17 SDeclD. Stm ::= Type Ident ";" ;
18
19
20 SWhile.   Stm      ::= "while" "(" Exp ")" Stm ;
21 SIf.     Stm      ::= "if" "(" Exp ")" Stm "else" Stm ;
22 if.      Stm      ::= "if" "(" Exp ")" Stm ;
23 define if e s = SIf e s SNoop ;
24
25 -- SFor.     Stm      ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
26 SPrint.   Stm      ::= "print" Exp ";" ;
27
28
29
30 EAss.     Exp     ::= Ident "=" Exp;
31
32 compExp.  Exp     ::= Exp1 Op0 Exp1 ;
33 define compExp e1 o e2 = BiOpExp e1 o e2 ;
34
35 op1.      Exp1    ::= Exp1 Op1 Exp2 ;
36 define op1 e1 o e2 = BiOpExp e1 o e2 ;
37
38 op2.      Exp2    ::= Exp2 Op2 Exp3 ;
39 define op2 e1 o e2 = BiOpExp e1 o e2 ;
40
41 postIncr. Exp3    ::= Ident "++" ;
42 define postIncr i = EPost i Plus ;
43
44 postDecr.    Exp3    ::= Ident "--" ;
45 define postDecr i = EPost i Minus ;
46
47 EVar.     Exp3    ::= Ident ;
48 EInt.     Exp3    ::= Integer ;
49 EBool.    Exp3    ::= Bool ;
50
51 ENeg.     Exp3    ::= "-" Exp3 ;
52 ENot.     Exp3    ::= "!" Exp3 ;
53
54 EReadI.   Exp3    ::= "readInt" ;
55 EReadB.   Exp3    ::= "readBool" ;
56
57
58 coercions Exp 3 ;
59
60
61 -- _.        Stm     ::= Stm ";" ;
62
63
64 terminator Stm "" ;
65
66
67 Lt.  Op0 ::= "<" ;
68 ELt. Op0 ::= "<=" ;
69 Gt.  Op0 ::= ">" ;
70 EGt. Op0 ::= ">=" ;
71 Eq.  Op0 ::= "==" ;
72 NEq. Op0 ::= "!=" ;
73
74 Plus.  Op1 ::= "+" ;
75 Minus. Op1 ::= "-" ;
76 Times. Op2 ::= "*" ;
77 Div.   Op2 ::= "/" ;
78
79 _. Op ::= Op1;
80 _. Op ::= Op2;
81 _. Op ::= Op0;
82
83
84 -- pragmas
85
86 -- internal ExpT. Exp ::= Type Exp ;
87 -- internal EDefault. Exp ::= ;
88 internal BiOpExp. Exp ::= Exp Op Exp ;
89 -- internal NoType. Type ::= ;
90 internal EPost. Exp ::= Ident Op1 ;
91
92 internal SNoop. Stm ::= ;
93
94 comment "/*" "*/" ;
95 comment "//" ;
96
97 entrypoints Stms, Exp ;