[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(probably very naive) question regarding production grammar



Hiya. I'm very new to the lexer/parser/compiler world, so my question may
well not be appropriate in this forum. If so, I apologize; any resource
suggestions would be helpful.

I'm working on a grammar for SQL where clauses. The aim is to be able to
parse and walk an AST tree of a user-supplied where clause in order to mark
it in in HTML and allow individual portions of the clause to be editable
using form widgets and such. I based my grammar subset on a BNF grammar for
SQL that I found here:

http://cui.unige.ch/db-research/Enseignement/analyseinfo/SQL7/BNFindex.html

Their grammar allows for [] and {} sections in productions (see
http://cui.unige.ch/db-research/Enseignement/analyseinfo/AboutBNF.html),
which sablecc does not (at least not the {} sections). I didn't think it
would be hard to rewrite them as recursive rules, but I apparently must
have done something wrong because sablecc will not process the grammar
included below. It does not like the first rule in this production:

    logical_factor =
        {compare} exp_simple compare exp_simple |
        {condition} lparen condition rparen;

It says:

     [java]  -- Generating parser for grammar in
C:\cygwin\home\Dball\src\sqlparser\build\java
     [java] Verifying identifiers.
     [java] java.lang.RuntimeException: [39,38] Redefinition of
ACompareLogicalFactor.ExpSimple.

I can't figure out why sablecc does not like this grammar, perhaps someone
might offer some advice? Thanks in advance.

- donald

Package com.rhoworld.sqlparser;

Helpers

    digit = ['0' .. '9'];
    cr = 13;
    lf = 10;
    tab = 9;

Tokens

    plusminus = '+' | '-';
    starslash = '*' | '/';
    lparen = '(';
    rparen = ')';
    whitespace = (cr | lf | tab | ' ')+;
    integer = digit+;
    not = 'NOT';
    or = 'OR';
    and = 'AND';
    compare = '<' | '<=' | '=' | '>=' | '>';

Ignored Tokens

    whitespace;

Productions

    condition =
        {term} logical_term |
        {not} not logical_term |
        {or} condition or logical_term;

    logical_term =
        {factor} logical_factor |
        {and} logical_term and logical_factor;

    logical_factor =
        {compare} exp_simple compare exp_simple |
        {condition} lparen condition rparen;

    exp_simple =
        {term} term |
        {signedterm} plusminus term |
        {terms} exp_simple plusminus term;

    term =
        {factor} factor |
        {factors} term starslash factor;