[antlr-interest] Tree-Parser Grammer Question

mzukowski at yci.com mzukowski at yci.com
Tue Nov 12 08:25:45 PST 2002


It is kind of weird to have optional matches like (IDENT^)? promoted to the
root.  What is your rationale for this?  Your tree rule would look like

selectColumn: #(IDENT groupExpression)
			| groupExpression
	;

Monty

-----Original Message-----
From: Ney, Richard [mailto:richard.ney at aspect.com]
Sent: Monday, November 11, 2002 11:26 PM
To: 'antlr-interest at yahoogroups.com'
Subject: [antlr-interest] Tree-Parser Grammer Question


I have battled this issue for two days now so I'm at a loss to how to solve
this problem. I created a initial parser for a basic SQL Select. One of my
key rules in the initial parser looks like this:
groupExpression 
        : ("avg"^|"max"^|"min"^|"sum"^) OPEN_PAREN! (additiveExpression |
(("all" | "distinct") field_name)) CLOSE_PAREN! (IDENT^)
        | ("count"^ OPEN_PAREN! (("all" | "distinct")? field_name | STAR)
CLOSE_PAREN! (IDENT^)?) 
        | additiveExpression (IDENT^)? 
        ; 
The result of this rule is that it builds the tree with the final name of
the column always being to top-most root. I.E.
Select test, count(*), count(*) test from foo; 
Results in a tree that looks like 
select 
        test 
        count 
                * 
        test 
                count 
                        * 
from 
        foo 
Now in my tree parser I have a two rules that look like this: 
selectColumn 
        : fieldName (groupExpression)? 
        ; 
        
groupExpression 
        : #("avg" mathExpression) 
        { 
        } 
        | #("sum" mathExpression) 
        { 
        } 
        | #("count" ("all" | "distinct")? (fieldName| STAR)) 
        { 
        } 
        | #("max" mathExpression) 
        { 
        } 
        | #("min" mathExpression) 
        { 
        } 
        ; 
These rules handle the 1st and 3rd cases in the select statement but not the
2nd where the count(*) doesn't have an alias. Does anyone have an idea how
to write something like
selectColumn 
        : (fieldName)? (groupExpression)? 
        ; 
that is a little less ambiguous? 
-Richard 
----------------------------------------------------------------------------
------------------------ 
Richard Ney     Aspect Communications 
Principal Software Engineer 
http://www.aspect.com                           Main:  408.325.2200 
mailto:richard.ney at aspect.com                   SJ Office: 408.325.2464 
        Home Office: 916.797.9602 
----------------------------------------------------------------------------
------------------------ 
The Three Laws of Infernal Dynamics:
1. An object in motion will always be headed in the wrong direction.
2. An object at rest will always be in the wrong place.
3. The energy required to change either of these states will always be more
than you wish to expend, but never so much as to make the task appear
prospectively impossible.


Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 

 

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



More information about the antlr-interest mailing list