X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=26408246305de004f448085d22bb717adca8736b;hp=7b84054391014ef81d22f0f03d8e8866af3049ce;hb=565fbd61dca527c23888e08783d0d91cee458524;hpb=3cee522d1f54b39a1efa654da364c6c939cbcf1f diff --git a/syntax.cf b/syntax.cf index 7b84054..2640824 100644 --- a/syntax.cf +++ b/syntax.cf @@ -1,14 +1,27 @@ -- ordinary rules + +True. Bool ::= "true" ; +False. Bool ::= "false" ; + +TInt. Type ::= "int" ; +TBool. Type ::= "bool" ; + Program. Stms ::= [Stm] ; -SExp. Stm ::= Exp ";" ; -SBlock. Stm ::= "{" [Stm] "}" ; -SDecl. Stm ::= Type Ident "=" Exp ";" ; -decl. Stm ::= Type Ident ";" ; -define decl t v = SDecl t v EDefault ; +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 ; @@ -74,21 +87,17 @@ _. Op ::= Op2; _. Op ::= Op0; -True. Bool ::= "true" ; -False. Bool ::= "false" ; - -TInt. Type ::= "int" ; -TBool. Type ::= "bool" ; - -- pragmas -internal ExpT. Exp ::= Type Exp ; -internal SNoop. Stm ::= ; -internal EDefault. Exp ::= ; +-- internal ExpT. Exp ::= Type Exp ; +-- internal EDefault. Exp ::= ; internal BiOpExp. Exp ::= Exp Op Exp ; -internal NoType. Type ::= ; +-- internal NoType. Type ::= ; internal EPost. Exp ::= Ident Op1 ; +internal SNoop. Stm ::= ; +internal SDecl. Stm ::= Type Ident "=" Exp ";" ; + comment "/*" "*/" ; comment "//" ;