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