[antlr-interest] Re: LR problem with SQL92 parsing?

antlrlist antlrlist at yahoo.com
Tue Jun 17 09:28:00 PDT 2003


I'd use a syntactic predicate. Something like this:

id
: ("_")=> "_" char_set_name REGULAR_ID
| REGULAR_ID
;

I think that should work.

I have a suggestion: using so many (...)? in char_set_name and 
schema_name is a bit confusing. As I see it, char_set_name has one, 
two or three ids separated by points. I mean this:

char_set_name
: id
| id "." id
| id "." id "." id
;

This solution is k=4, I think. If you feel brave, you could put it 
down to k=1 with a counter:

char_set_name
{ int idCounter = 1; }
: id
  ( "." id
    {
      idCounter++;
      if (idCounter>3)
         throw new SemanticException ("too many ids...") ;
    }
  )*
;

I hope I could help you!

Enrique







--- In antlr-interest at yahoogroups.com, "Lubos Vnuk" <lubos.vnuk at r...> 
wrote:
> Hi,
> 
> I am new to ANTLR, I have read most of the docs but got stuck trying
> to parse SQL2: 
> 
> //Example 1
> class SQL2 extends Parser;
> options {k = 4;}
> id : REGULAR_ID;
> char_set_name : (schema_name ".")? id;
> schema_name : (id ".")? id;
> 
> So far so good. Using left factoring for <schema_name> I can even 
> reduce the lookahead to 3:
> //Example 2
> class SQL2 extends Parser;
> options {k = 3;}
> id : REGULAR_ID;
> char_set_name : (schema_name ".")? id;
> schema_name : id ("." id)?;
> 
> So far so good. But as I introduce the "_" for the <id>:
> //Example 3 - THE PROBLEM
> class SQL2 extends Parser;
> options {k = 3;}
> id : ("_" char_set_name)? REGULAR_ID;
> char_set_name : (schema_name ".")? id;
> schema_name : id ("." id)?;
> 
> I get two ambuguities. My question is: How can I best resolve the 
> issue? Is it:
> -> by specifying greedy subrules for char_set_name and schema_name 
> subrules?
> -> by using syntactic predicates?
> -> or else?
> 
> TIA,
> Lubos.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list