
www.Usenet.com
Group Index
Comp Thread Archive from Usenet.com
Newbie question...
- __From__: Amund Trovåg
- __Subject__: Newbie question...
- __Date__: Mon, 17 Nov 2003 05:22:44 -0600
Hi all. I am trying to create a parser that parses something like this:
project ssn, name (relationName);
This is a relational algebra expression.
I have actually made it this far, but I have one slight problem. I want
the attributes (ssn, name, etc) to become tokens, but without the
comma... That is, I want the parser to understand that when there is a
comma, there should be another attribute, but not add the comma to the
token.
The tokens are defined:
*snip more tokens above*
| <COMMA: ",">
|<ID : ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","0"-"9"] )*<COMMA> >
// with comma
|<LASTID: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","0"-"9"] )* >
//without comma(expecting ;)
And the production for the expression:
//----------------------------------
void project() #PROJECT:
{Token t = new Token();}
{// project + attribute name commalist(zero or more(*)) end with
(relationname) and EOF=;
(t=<PROJECT>) [attributeList()] Relation() {jjtThis.setToken(t.kind,
t.image);}
}
//-----------------------------------
void attributeList() #ATTRIBUTELIST:
{Token t = new Token();}
{
(t=<ID>)*{jjtThis.addToken(t.kind, t.image);}
(t=<LASTID>){jjtThis.addToken(t.kind, t.image);} // optional i.e. can
project the relation without specific attributes
}
*snipped Relation() as it is irrelevant here*
So...how can I make it so it is parsed the way it is now, but that the
<COMMA> is not a part of the <ID>s?
Very grateful for advice, have tried alot of different things now.
Regards,
Amund
- Newbie question...,
Amund Trovåg