X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=syntax.cf;h=44a6cb4284db6eb0d08e95ec53423cccab7f8eb8;hp=26408246305de004f448085d22bb717adca8736b;hb=HEAD;hpb=565fbd61dca527c23888e08783d0d91cee458524 diff --git a/syntax.cf b/syntax.cf index 2640824..44a6cb4 100644 --- a/syntax.cf +++ b/syntax.cf @@ -8,19 +8,13 @@ False. Bool ::= "false" ; TInt. Type ::= "int" ; TBool. Type ::= "bool" ; -Program. Stms ::= [Stm] ; +Program. Program ::= [FuncStm] ; 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); +SDecl. Stm ::= Type Ident "=" Exp ";" ; +SDeclD. Stm ::= Type Ident ";" ; SWhile. Stm ::= "while" "(" Exp ")" Stm ; @@ -31,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; @@ -60,6 +56,9 @@ ENot. Exp3 ::= "!" Exp3 ; EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ; +EFunc. Exp3 ::= Ident "(" [Exp] ")" ; + + coercions Exp 3 ; @@ -69,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 ::= "<=" ; @@ -96,9 +112,8 @@ internal BiOpExp. Exp ::= Exp Op Exp ; internal EPost. Exp ::= Ident Op1 ; internal SNoop. Stm ::= ; -internal SDecl. Stm ::= Type Ident "=" Exp ";" ; comment "/*" "*/" ; comment "//" ; -entrypoints Stms, Exp ; +entrypoints Program;