]> ruin.nu Git - proglang.git/blobdiff - syntax.cf
streamlining the abstract syntax
[proglang.git] / syntax.cf
index 7e4740eaed3a448c6a2f8c3f7bc6dea7721c95ed..28e93f9a4f1afb152c4ecb6997953411bc7d9b56 100644 (file)
--- a/syntax.cf
+++ b/syntax.cf
@@ -1,38 +1,36 @@
 
 -- ordinary rules
 
-BTrue. BoolT ::= "true" ;
-BFalse. BoolT ::= "false" ;
+True. Bool ::= "true" ;
+False. Bool ::= "false" ;
 
-SDecl.    Stm      ::= Typ Var ";" ;
---SAss.     Stm      ::= Ident "=" Exp  ";"  ;
+SDecl.   Stm      ::= Type Ident "=" Exp ";" ;
+decl.    Stm      ::= Type Ident ";" ;
+define decl t v = SDecl t  v EDefault ;
 SExp.     Stm      ::= Exp ";" ;
 SBlock.   Stm      ::= "{" [Stm] "}" ;
-SIf.      Stm      ::= "if" "(" Exp ")" Stm ;
-SIfE.     Stm      ::= "if" "(" Exp ")" Stm "else" Stm ;
+if.      Stm      ::= "if" "(" Exp ")" Stm ;
+SIf.     Stm      ::= "if" "(" Exp ")" Stm "else" Stm ;
+define if e s = SIf e s SNoop ;
 SWhile.   Stm      ::= "while" "(" Exp ")" Stm ;
 -- SFor.     Stm      ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
 SPrint.   Stm      ::= "print" Exp ";" ;
 
-VVar.     Var      ::= Ident ;
-VAss.     Var      ::= Ident "=" Exp;
-
-ELt.      Exp     ::= Exp1 "<" Exp1 ;
-EELt.     Exp     ::= Exp1 "<=" Exp1 ;
-EGt.      Exp     ::= Exp1 ">" Exp1 ;
-EEGt.     Exp     ::= Exp1 ">=" Exp1 ;
-EEq.      Exp     ::= Exp1 "==" Exp1 ;
-ENEq.     Exp     ::= Exp1 "!=" Exp1 ;
-EPlus.    Exp1    ::= Exp1 "+" Exp2 ;
-EMinus.   Exp1    ::= Exp1 "-" Exp2 ;
-ETimes.   Exp2    ::= Exp2 "*" Exp3 ;
-EDiv.     Exp2    ::= Exp2 "/" Exp3 ;
+-- VVar.     Var      ::= Ident ;
+-- VAss.     Var      ::= Ident "=" Exp;
+
+BExp.     Exp     ::= Exp1 BOp Exp1 ;
+op1.      Exp1    ::= Exp1 Op1 Exp2 ;
+define op1 e1 o e2 = OpExp e1 o e2 ;
+op2.      Exp2    ::= Exp2 Op2 Exp3 ;
+define op2 e1 o e2 = OpExp e1 o e2 ;
 EIncr.    Exp3    ::= Ident "++" ;
 EDecr.    Exp3    ::= Ident "--" ;
-EVar.     Exp3    ::= Var ;
+EVar.     Exp3    ::= Ident ;
+EAss.     Exp3    ::= Ident "=" Exp;
 EInt.     Exp3    ::= Integer ;
 ENeg.     Exp3    ::= "-" Exp3 ;
-EBool.    Exp3    ::= BoolT ;
+EBool.    Exp3    ::= Bool ;
 EReadI.   Exp3    ::= "readInt" ;
 EReadB.   Exp3    ::= "readBool" ;
 
@@ -46,13 +44,33 @@ terminator Stm "" ;
 
 Program.  Stms ::= [Stm] ;
 
+Lt.  BOp ::= "<" ;
+ELt. BOp ::= "<=" ;
+Gt.  BOp ::= ">" ;
+EGt. BOp ::= ">=" ;
+Eq.  BOp ::= "==" ;
+NEq. BOp ::= "!=" ;
+
+Plus.  Op1 ::= "+" ;
+Minus. Op1 ::= "-" ;
+Times. Op2 ::= "*" ;
+Div.   Op2 ::= "/" ;
+
+_. Op ::= Op1;
+_. Op ::= Op2;
+
+
 
-TInt.     Typ  ::= "int" ;
-TBool.  Typ  ::= "bool" ;
+TInt.     Type  ::= "int" ;
+TBool.  Type  ::= "bool" ;
 
 -- pragmas
 
-internal ExpT. Exp ::= Typ Exp ;
+internal ExpT. Exp ::= Type Exp ;
+internal SNoop. Stm ::= ;
+internal EDefault. Exp ::= ;
+internal OpExp. Exp ::= Exp Op Exp ;
+internal NoType. Type ::= ;
 
 comment "/*" "*/" ;
 comment "//" ;