best grammar for handling optional symbols?

jmichae3@yahoo.com
Fri, 15 Aug 2008 18:41:28 -0700 (PDT)

          From comp.compilers

Related articles
best grammar for handling optional symbols? jmichae3@yahoo.com (2008-08-15)
Re: best grammar for handling optional symbols? max@gustavus.edu (Max Hailperin) (2008-08-16)
Re: best grammar for handling optional symbols? jaluber@gmail.com (Johannes) (2008-08-17)
Re: best grammar for handling optional symbols? jmichae3@yahoo.com (2008-08-18)
Re: best grammar for handling optional symbols? cfc@shell01.TheWorld.com (Chris F Clark) (2008-08-19)
| List of all articles for this month |

From: jmichae3@yahoo.com
Newsgroups: comp.compilers
Date: Fri, 15 Aug 2008 18:41:28 -0700 (PDT)
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 15 Aug 2008 22:28:45 EDT

I've been using BNF.
up until now, things have been OK with the optional symbols.


what is the proper way to implement an optional symbol where <code40>
is optional?
<b> ::= <code40> "r" | "r"
but I would prefer
<b> ::= <a> "r"
<a> ::= <code40> | <nullsymbol???>


I don't know. I don't think this is right when it occurs 0 or 1
times. I seem to remember there was a symbol in BNF used to represent
the null terminal or something - it's not listed in wikipedia (lousy
wikipedia). what was it?


Anyway, the problem I am up against is that I have to define a symbol
that has 18 options. fully expanded, that makes 2^18 options, and I
have 200 more symbols to define for autocad, many with more options...


[Either is OK for optional symbols. For your Autocad problem, I would
suggest a much looser grammar that just accepts a list of symbols, and
check semantically to knock out duplicates. That both keeps the
grammar managable, and lets you produce much better errors, e.g.
"duplicate foo" or "foo not allowed after bar" rather than just
"syntax error". -John]



Post a followup to this message

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