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