BNF grammar interpretation

"valentin tihomirov" <>
3 Apr 2004 09:13:15 -0500

          From comp.compilers

Related articles
BNF grammar interpretation (valentin tihomirov) (2004-04-03)
Re: BNF grammar interpretation (2004-04-29)
| List of all articles for this month |

From: "valentin tihomirov" <>
Newsgroups: comp.compilers
Date: 3 Apr 2004 09:13:15 -0500
Organization: Compilers Central
Keywords: parse
Posted-Date: 03 Apr 2004 09:13:15 EST

[1] I have made an attemt to make an edif (LISP-like file)
parser/translator. I want it to make universal. The file is a tree of
identical elements.
        A ::= '(''plus' X Y')'

'plus' determines type of the expression, identifier is a terminal (string
token) and X and Y are imperative (non-optional). I was trying to make a
universal parser traveling through the tree and generating events to
translator. As far as I've seen the imperative sub-expressions in edif
grammar are usually defined like this:
        X ::= ( identifier | M | N )
        M ::= '(''m' identifier ')'
        N ::= '(''n' identifier ')'

As you see, the X selects one expression, whether terminal or M or N. This
conforms to the highr-level A expression that requires only one imperative
sub-expression. I could not find expressions like:
        X ::= { identifier | M }

But what is the way to parse it if the above declaration is encountered; the
{} braces mean optional expression in BNF? This looks like a paradox
(conflict) of declarations. X-element becomes optional as opposed to
A-parent element expectations.

[2] The second paradox is similar to the first one.
        A ::= ( identifier [X] [Y] )
        X ::= (identifier | B)
        Y ::= (identifier | C)
Here, expression A has 3 sub-expressions. The first child is simple terminal
identifier, second is optional X element followed by optional Y expression.
If X is optinal, how do I know that identifier returned by lexer at X
position is X element rather than Y?

I beleive that grammar allows more sinthax errors in general. What do you
recommend to read for preventing such stupid questions?

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.