Re: Converting BNF grammar to EBNF

George Neuner <gneuner2@comcast.net>
11 Aug 2006 00:39:18 -0400

          From comp.compilers

Related articles
Converting BNF grammar to EBNF sandy.pec@gmail.com (Scorpio) (2006-08-09)
Re: Converting BNF grammar to EBNF gneuner2@comcast.net (George Neuner) (2006-08-11)
| List of all articles for this month |

From: George Neuner <gneuner2@comcast.net>
Newsgroups: comp.compilers
Date: 11 Aug 2006 00:39:18 -0400
Organization: Compilers Central
References: 06-08-039
Keywords: parse
Posted-Date: 11 Aug 2006 00:39:18 EDT

On 9 Aug 2006 00:00:35 -0400, "Scorpio" <sandy.pec@gmail.com> wrote:


>Hi
>
>I am a newbie with the parsing stuff, and I am trying to convert a BNF
>grammar to an EBNF one. I have a lexer rule which states Set ::= Set1 -
>Set2; I am using ANTLR v3.0 Beta 3 and unable to get how to convert
>this into the ANTLR grammar. ANTLR just rejects the "-" operation on
>sets. Please help!
>


It's been a while since I've done a parser with ANTLR so don't depend
on the syntax below.




Depending on what Set2 actually is, you may be able to use a syntactic
predicate like the following that proceeds only if the next token is
not from Set2.


      Set: ( ~Set2 )=> Set1;




There is also a way (but I forget how - check the manual) to
programmatically examine the token so you could write a semantic
predicate to check for and reject a token from Set2. Semantic
predicates throw an exception if they fail which you will have to
catch. Use an alternation like the following:


      Set: { /* code that returns false if token in Set2 */}?
                exception
                    catch [SemanticException ex]
                        { /* do nothing */}


            | Set1
            ;




Hope this helps.
George


Post a followup to this message

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