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