]> ruin.nu Git - proglang.git/blob - syntax.cf
a0e69538f58bb9a72899ec801b68366d11e3f808
[proglang.git] / syntax.cf
1
2 -- ordinary rules
3
4 True. Bool ::= "true" ;
5 False. Bool ::= "false" ;
6
7 SDecl.   Stm      ::= Typ Ident "=" Exp ";" ;
8 decl.    Stm      ::= Typ 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 ELt.      Exp     ::= Exp1 "<" Exp1 ;
23 EELt.     Exp     ::= Exp1 "<=" Exp1 ;
24 EGt.      Exp     ::= Exp1 ">" Exp1 ;
25 EEGt.     Exp     ::= Exp1 ">=" Exp1 ;
26 EEq.      Exp     ::= Exp1 "==" Exp1 ;
27 ENEq.     Exp     ::= Exp1 "!=" Exp1 ;
28 EPlus.    Exp1    ::= Exp1 "+" Exp2 ;
29 EMinus.   Exp1    ::= Exp1 "-" Exp2 ;
30 ETimes.   Exp2    ::= Exp2 "*" Exp3 ;
31 EDiv.     Exp2    ::= Exp2 "/" Exp3 ;
32 EIncr.    Exp3    ::= Ident "++" ;
33 EDecr.    Exp3    ::= Ident "--" ;
34 EVar.     Exp3    ::= Ident ;
35 EAss.     Exp3    ::= Ident "=" Exp;
36 EInt.     Exp3    ::= Integer ;
37 ENeg.     Exp3    ::= "-" Exp3 ;
38 EBool.    Exp3    ::= Bool ;
39 EReadI.   Exp3    ::= "readInt" ;
40 EReadB.   Exp3    ::= "readBool" ;
41
42 coercions Exp 3 ;
43
44
45 _.        Stm     ::= Stm ";" ;
46
47
48 terminator Stm "" ;
49
50 Program.  Stms ::= [Stm] ;
51
52
53 TInt.     Typ  ::= "int" ;
54 TBool.  Typ  ::= "bool" ;
55
56 -- pragmas
57
58 internal ExpT. Exp ::= Typ Exp ;
59 internal SNoop. Stm ::= ;
60 internal EDefault. Exp ::= ;
61
62 comment "/*" "*/" ;
63 comment "//" ;
64
65 entrypoints Stms, Exp ;