1. Euphoria's grammar

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

new topic     » topic index » view message » categorize

2. Re: Euphoria's grammar

On Sun, 20 Jul 2003 12:19:53 +0000, Andreas Rumpf <pfropfen at gmx.net>
wrote:

>I wrote Euphoria's grammar in EBNF and I'd like to know wether it is=20
>correct.
Hi Andreas,
> Robert, please have a look at it.
That's not my name!  But I'm sure you won't mind me commenting blink

>number ::=3D ["+" | "-"] digit ["." {digit} [ ("e"|"E" ) ["+"|"-"] digit=
=20
>{digit} ]  ]
You need digit {digit} after the ".", eg  1.e1 is invalid in Euphoria=20
1e4 won't get through the above production either, move the last ] to
before the [("e", I think.
>program ::=3D { toplevel | statement }
>toplevel ::=3D "include" filename ["as" ident]
>  | ("with" | "without") ("type_check" | "profile" | "profile_time" |=20
>"warning")
You missed out trace. Also, some of the older "stamped" files have eg
"with 4987246573" ("stamping" is a discontinued practice that only RDS
could perform, [to permit debugging on the PD version] but you still
might stumble across such a thing some day)=20
>  | ["global"] func_decl | proc_decl | const_decl | var_decl | type_decl
>  | statements
I just had
program::=3D{toplevel}
toplevel::=3D<inc>|<with>|global etc,
    | statement
Is there any useful difference? Just asking
>
>statement ::=3D assignable ("=3D" | "+=3D" | "-=3D" | "/=3D" | "*=3D" | =
"&=3D") expr
>  | "if" expr "then" statements { "elsif" statements } ["else"=20
>statements ] "end" "if"
>  | proc_call
>  | "while" expr "do" statements "end" "while"
>  | "for" ident "=3D" expr "to" expr ["by" expr] "do" statements "end"=20
>"for"
>  | var_decl
>  | "?" expr
>  | "exit"           -- in loops only
>  | "return" [expr]  -- in type | function | procedure only
>statements ::=3D {statement} -- zero or more statements
>proc_call ::=3D [ident ":" ] ident "(" [args] ")"
>func_call ::=3D [ident ":" ] ident "(" [args] ")"
>type_call ::=3D [ident ":" ] ident "(" expr ")"
>args ::=3D expr {"," expr}
>
>formal_param ::=3D ident ident -- type identifier
In theory, the type could be namespaced. Never seen or tried it though
>formal_params ::=3D formal_param { "," formal_param }
>func_decl ::=3D "function"  ident "(" [formal_params] ")" statements =
"end"=20
>"function"
>proc_decl ::=3D "procedure" ident "(" [formal_params] ")" statements =
"end"=20
>"procedure"
>type_decl ::=3D "type" ident "(" formal_param ")" statements "end" =
"type"
>const_decl ::=3D ident "=3D" expr {"," ident "=3D" expr}
>
>var_decl ::=3D [ident ":"] ident ident {"," ident}
>-- variable declaration: lib:type_ x, y
>
>assignable ::=3D [ident ":"] ident { "[" expr [".." expr] "]" }
a[1..2][1..2] is not allowed
>
>-- This is what the manual says:
>--   highest precedence:     function/type calls
>--                           unary-  unary+  not
>--                           *  /
>--                           +  -
>--                           &
>--                           <  >  <=3D  >=3D  =3D  !=3D
>--                           and  or  xor
>--   lowest precedence:      { , , , }
>
>expr ::=3D bool_op | seq
>seq ::=3D "{" expr   { "," expr }   "}"  |  string_constant
Assuming string_constant permits [only] single characters in single
quotes (and nul or longer strings in double quotes).
>bool_op ::=3D comparison { ( "and"| "or" | "xor" ) comparison }
>comparison ::=3D concat { ("<" | ">" | "<=3D" | ">=3D" | "=3D" | "!=3D" =
) concat }
>concat ::=3D sum { "&" sum }
>sum ::=3D term { ("-" | "+") term }
>term ::=3D factor { ("*" | "/") factor }
>factor ::=3D assignable | number | "(" expr ")" | ("not" | "-" | "+")=20
>factor
>  | func_call | type_call
>
>
>Regards
>  Andreas Rumpf

You're welcome
May I ask what you are planning?

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu