X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=26408246305de004f448085d22bb717adca8736b;hp=fae1234c287f73180e784eb039d7a68169a81bb8;hb=565fbd61dca527c23888e08783d0d91cee458524;hpb=cbe0bd3df1f1ddf458de751d28eb1df73708113c diff --git a/syntax.cf b/syntax.cf index fae1234..2640824 100644 --- a/syntax.cf +++ b/syntax.cf @@ -1,54 +1,81 @@ -- ordinary rules -True. Bool ::= "true" ; -False. Bool ::= "false" ; - -SDecl. Stm ::= Type Ident "=" Exp ";" ; -decl. Stm ::= Type Ident ";" ; -define decl t v = SDecl t v EDefault ; -SExp. Stm ::= Exp ";" ; -SBlock. Stm ::= "{" [Stm] "}" ; -if. Stm ::= "if" "(" Exp ")" Stm ; + +True. Bool ::= "true" ; +False. Bool ::= "false" ; + +TInt. Type ::= "int" ; +TBool. Type ::= "bool" ; + +Program. Stms ::= [Stm] ; + + +SExp. Stm ::= Exp ";" ; +SBlock. Stm ::= "{" [Stm] "}" ; +declIntE. Stm ::= "int" Ident "=" Exp ";" ; +declBoolE. Stm ::= "bool" Ident "=" Exp ";" ; +define declIntE x e = SDecl TInt x e; +define declBoolE x e = SDecl TBool x e; +declInt. Stm ::= "int" Ident ";" ; +declBool. Stm ::= "bool" Ident ";" ; +define declInt x = SDecl TInt x (EInt 0); +define declBool x = SDecl TBool x (EBool False); + + +SWhile. Stm ::= "while" "(" Exp ")" Stm ; SIf. Stm ::= "if" "(" Exp ")" Stm "else" Stm ; +if. Stm ::= "if" "(" Exp ")" 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 ";" ; -BExp. Exp ::= Exp1 BOp Exp1 ; + + +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 = OpExp e1 o e2 ; +define op1 e1 o e2 = BiOpExp e1 o e2 ; + op2. Exp2 ::= Exp2 Op2 Exp3 ; -define op2 e1 o e2 = OpExp e1 o e2 ; -postIncr. Exp3 ::= Ident "++" ; +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 ; EBool. Exp3 ::= Bool ; + +ENeg. Exp3 ::= "-" Exp3 ; +ENot. Exp3 ::= "!" Exp3 ; + EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; + coercions Exp 3 ; -_. Stm ::= Stm ";" ; +-- _. Stm ::= Stm ";" ; terminator Stm "" ; -Program. Stms ::= [Stm] ; -Lt. BOp ::= "<" ; -ELt. BOp ::= "<=" ; -Gt. BOp ::= ">" ; -EGt. BOp ::= ">=" ; -Eq. BOp ::= "==" ; -NEq. BOp ::= "!=" ; +Lt. Op0 ::= "<" ; +ELt. Op0 ::= "<=" ; +Gt. Op0 ::= ">" ; +EGt. Op0 ::= ">=" ; +Eq. Op0 ::= "==" ; +NEq. Op0 ::= "!=" ; Plus. Op1 ::= "+" ; Minus. Op1 ::= "-" ; @@ -57,21 +84,20 @@ Div. Op2 ::= "/" ; _. Op ::= Op1; _. Op ::= Op2; +_. Op ::= Op0; - -TInt. Type ::= "int" ; -TBool. Type ::= "bool" ; - -- pragmas -internal ExpT. Exp ::= Type Exp ; -internal SNoop. Stm ::= ; -internal EDefault. Exp ::= ; -internal OpExp. Exp ::= Exp Op Exp ; -internal NoType. Type ::= ; +-- internal ExpT. Exp ::= Type Exp ; +-- internal EDefault. Exp ::= ; +internal BiOpExp. Exp ::= Exp Op Exp ; +-- internal NoType. Type ::= ; internal EPost. Exp ::= Ident Op1 ; +internal SNoop. Stm ::= ; +internal SDecl. Stm ::= Type Ident "=" Exp ";" ; + comment "/*" "*/" ; comment "//" ;