]> ruin.nu Git - proglang.git/blobdiff - syntax.cf
initial commit of interpreter
[proglang.git] / syntax.cf
index a0e69538f58bb9a72899ec801b68366d11e3f808..d09a25c33849d524632a0b352994da59b2cf60b6 100644 (file)
--- a/syntax.cf
+++ b/syntax.cf
@@ -4,8 +4,8 @@
 True. Bool ::= "true" ;
 False. Bool ::= "false" ;
 
-SDecl.   Stm      ::= Typ Ident "=" Exp ";" ;
-decl.    Stm      ::= Typ Ident ";" ;
+SDecl.   Stm      ::= Type Ident "=" Exp ";" ;
+decl.    Stm      ::= Type Ident ";" ;
 define decl t v = SDecl t  v EDefault ;
 SExp.     Stm      ::= Exp ";" ;
 SBlock.   Stm      ::= "{" [Stm] "}" ;
@@ -16,25 +16,21 @@ 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 ;
-EIncr.    Exp3    ::= Ident "++" ;
-EDecr.    Exp3    ::= Ident "--" ;
+EAss.     Exp     ::= Ident "=" Exp;
+compExp.  Exp     ::= Exp1 Op0 Exp1 ;
+define compExp e1 o e2 = BiOpExp e1 o e2 ;
+op1.      Exp1    ::= Exp1 Op1 Exp2 ;
+define op1 e1 o e2 = BiOpExp e1 o e2 ;
+op2.      Exp2    ::= Exp2 Op2 Exp3 ;
+define op2 e1 o e2 = BiOpExp e1 o e2 ;
+postIncr. Exp3    ::= Ident "++" ;
+define postIncr i = EPost i Plus ;
+postDecr.    Exp3    ::= Ident "--" ;
+define postDecr i = EPost i Minus ;
 EVar.     Exp3    ::= Ident ;
-EAss.     Exp3    ::= Ident "=" Exp;
 EInt.     Exp3    ::= Integer ;
 ENeg.     Exp3    ::= "-" Exp3 ;
+ENot.     Exp3    ::= "!" Exp3 ;
 EBool.    Exp3    ::= Bool ;
 EReadI.   Exp3    ::= "readInt" ;
 EReadB.   Exp3    ::= "readBool" ;
@@ -42,22 +38,42 @@ EReadB.   Exp3    ::= "readBool" ;
 coercions Exp 3 ;
 
 
-_.        Stm     ::= Stm ";" ;
+-- _.        Stm     ::= Stm ";" ;
 
 
 terminator Stm "" ;
 
 Program.  Stms ::= [Stm] ;
 
+Lt.  Op0 ::= "<" ;
+ELt. Op0 ::= "<=" ;
+Gt.  Op0 ::= ">" ;
+EGt. Op0 ::= ">=" ;
+Eq.  Op0 ::= "==" ;
+NEq. Op0 ::= "!=" ;
 
-TInt.     Typ  ::= "int" ;
-TBool.  Typ  ::= "bool" ;
+Plus.  Op1 ::= "+" ;
+Minus. Op1 ::= "-" ;
+Times. Op2 ::= "*" ;
+Div.   Op2 ::= "/" ;
+
+_. Op ::= Op1;
+_. Op ::= Op2;
+_. Op ::= Op0;
+
+
+
+TInt.   Type  ::= "int" ;
+TBool.  Type  ::= "bool" ;
 
 -- pragmas
 
-internal ExpT. Exp ::= Typ Exp ;
+internal ExpT. Exp ::= Type Exp ;
 internal SNoop. Stm ::= ;
 internal EDefault. Exp ::= ;
+internal BiOpExp. Exp ::= Exp Op Exp ;
+internal NoType. Type ::= ;
+internal EPost. Exp ::= Ident Op1 ;
 
 comment "/*" "*/" ;
 comment "//" ;