X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=313fa556810e0dff5de9602959cdb74cd81073b5;hp=28e93f9a4f1afb152c4ecb6997953411bc7d9b56;hb=6103c0359b95557566aa9154efa5bcd4d9c996f6;hpb=a05f5aee2ceddec9721ce04ae596734524b80940 diff --git a/syntax.cf b/syntax.cf index 28e93f9..313fa55 100644 --- a/syntax.cf +++ b/syntax.cf @@ -16,20 +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; - -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 ; -EIncr. Exp3 ::= Ident "++" ; -EDecr. 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 ; +-- ENot. Exp3 ::= "!" Exp3 ; EBool. Exp3 ::= Bool ; EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; @@ -37,19 +38,19 @@ 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 ::= "-" ; @@ -58,6 +59,7 @@ Div. Op2 ::= "/" ; _. Op ::= Op1; _. Op ::= Op2; +_. Op ::= Op0; @@ -69,8 +71,9 @@ TBool. Type ::= "bool" ; internal ExpT. Exp ::= Type Exp ; internal SNoop. Stm ::= ; internal EDefault. Exp ::= ; -internal OpExp. Exp ::= Exp Op Exp ; +internal BiOpExp. Exp ::= Exp Op Exp ; internal NoType. Type ::= ; +internal EPost. Exp ::= Ident Op1 ; comment "/*" "*/" ; comment "//" ;