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