]> ruin.nu Git - proglang.git/blob - syntax.cf
8bb36219c11d1b7daeeeeaf9065a534d37f8345b
[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 BExp.     Exp     ::= Exp1 BOp Exp1 ;
21 op1.      Exp1    ::= Exp1 Op1 Exp2 ;
22 define op1 e1 o e2 = OpExp e1 o e2 ;
23 op2.      Exp2    ::= Exp2 Op2 Exp3 ;
24 define op2 e1 o e2 = OpExp e1 o e2 ;
25 postIncr. Exp3    ::= Ident "++" ;
26 define postIncr i = EPost i Plus ;
27 postDecr.    Exp3    ::= Ident "--" ;
28 define postDecr i = EPost i Minus ;
29 EVar.     Exp3    ::= Ident ;
30 EInt.     Exp3    ::= Integer ;
31 ENeg.     Exp3    ::= "-" Exp3 ;
32 EBool.    Exp3    ::= Bool ;
33 EReadI.   Exp3    ::= "readInt" ;
34 EReadB.   Exp3    ::= "readBool" ;
35
36 coercions Exp 3 ;
37
38
39 -- _.        Stm     ::= Stm ";" ;
40
41
42 terminator Stm "" ;
43
44 Program.  Stms ::= [Stm] ;
45
46 Lt.  BOp ::= "<" ;
47 ELt. BOp ::= "<=" ;
48 Gt.  BOp ::= ">" ;
49 EGt. BOp ::= ">=" ;
50 Eq.  BOp ::= "==" ;
51 NEq. BOp ::= "!=" ;
52
53 Plus.  Op1 ::= "+" ;
54 Minus. Op1 ::= "-" ;
55 Times. Op2 ::= "*" ;
56 Div.   Op2 ::= "/" ;
57
58 _. Op ::= Op1;
59 _. Op ::= Op2;
60
61
62
63 TInt.     Type  ::= "int" ;
64 TBool.  Type  ::= "bool" ;
65
66 -- pragmas
67
68 internal ExpT. Exp ::= Type Exp ;
69 internal SNoop. Stm ::= ;
70 internal EDefault. Exp ::= ;
71 internal OpExp. Exp ::= Exp Op Exp ;
72 internal NoType. Type ::= ;
73 internal EPost. Exp ::= Ident Op1 ;
74
75 comment "/*" "*/" ;
76 comment "//" ;
77
78 entrypoints Stms, Exp ;