X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=44a6cb4284db6eb0d08e95ec53423cccab7f8eb8;hp=7b84054391014ef81d22f0f03d8e8866af3049ce;hb=HEAD;hpb=2c2f90fca1005f6dedc69ee7f3d7c5072e5c123b diff --git a/syntax.cf b/syntax.cf index 7b84054..44a6cb4 100644 --- a/syntax.cf +++ b/syntax.cf @@ -1,14 +1,21 @@ -- ordinary rules -Program. Stms ::= [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 ";" ; -decl. Stm ::= Type Ident ";" ; -define decl t v = SDecl t v EDefault ; +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 ; @@ -18,6 +25,8 @@ define if e s = SIf e s SNoop ; -- SFor. Stm ::= "for" "(" Stm Exp ";" Exp ")" Stm ; SPrint. Stm ::= "print" Exp ";" ; +SReturn. Stm ::= "return" Exp ";" ; + EAss. Exp ::= Ident "=" Exp; @@ -47,6 +56,9 @@ ENot. Exp3 ::= "!" Exp3 ; EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; +EFunc. Exp3 ::= Ident "(" [Exp] ")" ; + + coercions Exp 3 ; @@ -56,6 +68,23 @@ coercions Exp 3 ; terminator 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 ::= "<=" ; @@ -74,22 +103,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 ::= ; + comment "/*" "*/" ; comment "//" ; -entrypoints Stms, Exp ; +entrypoints Program;