0

How can I interpret this as ENBF grammer?

<assign>--> <id> = <expr>

<id>--> A | B | C

<expr> --> <expr> * <expr>

<expr> --> <expr> + <expr>

| <id> + <expr>

|( <expr> )

| <id>

I can make parse tree and derivation of any statement using this grammer, but am having trouble with EBNF.

sick
  • 21
  • 3
  • 1
    Looks like its in BNF already (which is a subset of EBNF), so no changes are needed (though it is ambiguous). Is there a question here? What 'trouble' are you having with EBNF? – Chris Dodd Mar 18 '13 at 15:57

1 Answers1

0
<assign>--> <id> = <expr>

An assign is the sequence: id equals-sign expr.

<id>--> A | B | C

An id is one of A, B or C

<expr> --> <expr> * <expr>
<expr> --> <expr> + <expr>
| <id> + <expr>    
|( <expr> )    
| <id>

An expression can be:

  1. The product of two expressions (infix notation)
  2. The addition of two expression (infix notation)
  3. The addition of an identifier and an expression (which is a particular case of addition of two expressions, where the first expresion is just <id>)
  4. A parenthesized expression.
  5. An identifier.
Javier
  • 12,100
  • 5
  • 46
  • 57