X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=syntax.cf;h=7b84054391014ef81d22f0f03d8e8866af3049ce;hb=98e238b8dd8c07705ab9681ff07c85e10eda9397;hp=313fa556810e0dff5de9602959cdb74cd81073b5;hpb=6103c0359b95557566aa9154efa5bcd4d9c996f6;p=proglang.git diff --git a/syntax.cf b/syntax.cf index 313fa55..7b84054 100644 --- a/syntax.cf +++ b/syntax.cf @@ -1,40 +1,53 @@ -- ordinary rules -True. Bool ::= "true" ; -False. Bool ::= "false" ; +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] "}" ; -if. Stm ::= "if" "(" Exp ")" Stm ; + +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 ";" ; + + 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 ; EInt. Exp3 ::= Integer ; -ENeg. Exp3 ::= "-" Exp3 ; --- ENot. Exp3 ::= "!" Exp3 ; EBool. Exp3 ::= Bool ; + +ENeg. Exp3 ::= "-" Exp3 ; +ENot. Exp3 ::= "!" Exp3 ; + EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; + coercions Exp 3 ; @@ -43,7 +56,6 @@ coercions Exp 3 ; terminator Stm "" ; -Program. Stms ::= [Stm] ; Lt. Op0 ::= "<" ; ELt. Op0 ::= "<=" ; @@ -62,8 +74,10 @@ _. Op ::= Op2; _. Op ::= Op0; +True. Bool ::= "true" ; +False. Bool ::= "false" ; -TInt. Type ::= "int" ; +TInt. Type ::= "int" ; TBool. Type ::= "bool" ; -- pragmas