Euphoria's grammar
- Posted by Andreas Rumpf <pfropfen at gmx.net> Jul 20, 2003
- 577 views
I wrote Euphoria's grammar in EBNF and I'd like to know wether it is correct. Robert, please have a look at it. {} means zero or more occurences [] means one or no occurence | means "or" ident ::= letter { "_" | digit | letter } -- allowed identifiers number ::= ["+" | "-"] digit ["." {digit} [ ("e"|"E" ) ["+"|"-"] digit {digit} ] ] program ::= { toplevel | statement } toplevel ::= "include" filename ["as" ident] | ("with" | "without") ("type_check" | "profile" | "profile_time" | "warning") | ["global"] func_decl | proc_decl | const_decl | var_decl | type_decl | statements statement ::= assignable ("=" | "+=" | "-=" | "/=" | "*=" | "&=") expr | "if" expr "then" statements { "elsif" statements } ["else" statements ] "end" "if" | proc_call | "while" expr "do" statements "end" "while" | "for" ident "=" expr "to" expr ["by" expr] "do" statements "end" "for" | var_decl | "?" expr | "exit" -- in loops only | "return" [expr] -- in type | function | procedure only statements ::= {statement} -- zero or more statements proc_call ::= [ident ":" ] ident "(" [args] ")" func_call ::= [ident ":" ] ident "(" [args] ")" type_call ::= [ident ":" ] ident "(" expr ")" args ::= expr {"," expr} formal_param ::= ident ident -- type identifier formal_params ::= formal_param { "," formal_param } func_decl ::= "function" ident "(" [formal_params] ")" statements "end" "function" proc_decl ::= "procedure" ident "(" [formal_params] ")" statements "end" "procedure" type_decl ::= "type" ident "(" formal_param ")" statements "end" "type" const_decl ::= ident "=" expr {"," ident "=" expr} var_decl ::= [ident ":"] ident ident {"," ident} -- variable declaration: lib:type_ x, y assignable ::= [ident ":"] ident { "[" expr [".." expr] "]" } -- This is what the manual says: -- highest precedence: function/type calls -- unary- unary+ not -- * / -- + - -- & -- < > <= >= = != -- and or xor -- lowest precedence: { , , , } expr ::= bool_op | seq seq ::= "{" expr { "," expr } "}" | string_constant bool_op ::= comparison { ( "and"| "or" | "xor" ) comparison } comparison ::= concat { ("<" | ">" | "<=" | ">=" | "=" | "!=" ) concat } concat ::= sum { "&" sum } sum ::= term { ("-" | "+") term } term ::= factor { ("*" | "/") factor } factor ::= assignable | number | "(" expr ")" | ("not" | "-" | "+") factor | func_call | type_call Regards Andreas Rumpf