X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=44a6cb4284db6eb0d08e95ec53423cccab7f8eb8;hp=de173e86a1fc5cd4f98b837cdd8b3622478bf0b2;hb=HEAD;hpb=9d0e3c89b286456549c68a816d0729f193498f6a diff --git a/syntax.cf b/syntax.cf index de173e8..44a6cb4 100644 --- a/syntax.cf +++ b/syntax.cf @@ -1,40 +1,65 @@ -- 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. Program ::= [FuncStm] ; + + +SExp. Stm ::= Exp ";" ; +SBlock. Stm ::= "{" [Stm] "}" ; +SDecl. Stm ::= Type Ident "=" Exp ";" ; +SDeclD. Stm ::= Type Ident ";" ; + + +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 ";" ; +SReturn. Stm ::= "return" 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 ; +EBool. Exp3 ::= Bool ; + ENeg. Exp3 ::= "-" Exp3 ; ENot. Exp3 ::= "!" Exp3 ; -EBool. Exp3 ::= Bool ; + EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; +EFunc. Exp3 ::= Ident "(" [Exp] ")" ; + + + coercions Exp 3 ; @@ -43,7 +68,23 @@ coercions Exp 3 ; terminator Stm "" ; -Program. Stms ::= [Stm] ; +separator Exp "," ; + +Decl. Decl ::= Type Ident ; + +separator Decl "," ; + +Func. Func ::= Type Ident "(" [Decl] ")" "{" [Stm] "}" ; + +separator Func "" ; + +S. FuncStm ::= Stm ; +F. FuncStm ::= Func ; + +separator FuncStm "" ; + +-- E1. Exps ::= Exp ; +-- E2. Exps ::= Exp "," Exps ; Lt. Op0 ::= "<" ; ELt. Op0 ::= "<=" ; @@ -62,20 +103,17 @@ _. Op ::= Op2; _. Op ::= Op0; - -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 ::= ; + comment "/*" "*/" ; comment "//" ; -entrypoints Stms, Exp ; +entrypoints Program;