]> ruin.nu Git - proglang.git/blob - syntax.cf
removed NoType and EDefault and added assert
[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 declIntE.  Stm      ::= "int" Ident "=" Exp ";" ;
17 declBoolE. Stm      ::= "bool" Ident "=" Exp ";" ;
18 define declIntE x e = SDecl TInt x e;
19 define declBoolE x e = SDecl TBool x e;
20 declInt. Stm ::= "int" Ident ";" ;
21 declBool. Stm ::= "bool" Ident ";" ;
22 define declInt x  = SDecl TInt x (EInt 0);
23 define declBool x = SDecl TBool x (EBool False);
24
25
26 SWhile.   Stm      ::= "while" "(" Exp ")" Stm ;
27 SIf.     Stm      ::= "if" "(" Exp ")" Stm "else" Stm ;
28 if.      Stm      ::= "if" "(" Exp ")" Stm ;
29 define if e s = SIf e s SNoop ;
30
31 -- SFor.     Stm      ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
32 SPrint.   Stm      ::= "print" Exp ";" ;
33
34
35
36 EAss.     Exp     ::= Ident "=" Exp;
37
38 compExp.  Exp     ::= Exp1 Op0 Exp1 ;
39 define compExp e1 o e2 = BiOpExp e1 o e2 ;
40
41 op1.      Exp1    ::= Exp1 Op1 Exp2 ;
42 define op1 e1 o e2 = BiOpExp e1 o e2 ;
43
44 op2.      Exp2    ::= Exp2 Op2 Exp3 ;
45 define op2 e1 o e2 = BiOpExp e1 o e2 ;
46
47 postIncr. Exp3    ::= Ident "++" ;
48 define postIncr i = EPost i Plus ;
49
50 postDecr.    Exp3    ::= Ident "--" ;
51 define postDecr i = EPost i Minus ;
52
53 EVar.     Exp3    ::= Ident ;
54 EInt.     Exp3    ::= Integer ;
55 EBool.    Exp3    ::= Bool ;
56
57 ENeg.     Exp3    ::= "-" Exp3 ;
58 ENot.     Exp3    ::= "!" Exp3 ;
59
60 EReadI.   Exp3    ::= "readInt" ;
61 EReadB.   Exp3    ::= "readBool" ;
62
63
64 coercions Exp 3 ;
65
66
67 -- _.        Stm     ::= Stm ";" ;
68
69
70 terminator Stm "" ;
71
72
73 Lt.  Op0 ::= "<" ;
74 ELt. Op0 ::= "<=" ;
75 Gt.  Op0 ::= ">" ;
76 EGt. Op0 ::= ">=" ;
77 Eq.  Op0 ::= "==" ;
78 NEq. Op0 ::= "!=" ;
79
80 Plus.  Op1 ::= "+" ;
81 Minus. Op1 ::= "-" ;
82 Times. Op2 ::= "*" ;
83 Div.   Op2 ::= "/" ;
84
85 _. Op ::= Op1;
86 _. Op ::= Op2;
87 _. Op ::= Op0;
88
89
90 -- pragmas
91
92 -- internal ExpT. Exp ::= Type Exp ;
93 -- internal EDefault. Exp ::= ;
94 internal BiOpExp. Exp ::= Exp Op Exp ;
95 -- internal NoType. Type ::= ;
96 internal EPost. Exp ::= Ident Op1 ;
97
98 internal SNoop. Stm ::= ;
99 internal SDecl. Stm ::= Type Ident "=" Exp ";" ;
100
101 comment "/*" "*/" ;
102 comment "//" ;
103
104 entrypoints Stms, Exp ;