Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Newbie question...





Amund Trovåg wrote:



Mike Atkinson wrote:

Amund Trovåg wrote:



Yes, thank you so much for that! This works, and I understand why it should be like this. :)
The last problem I have now is the part of the expression that is "relationName". In the language, the relationNames/relation expressions, are always enclosed in parentheses like you show above. The parentheses however, are not part of the actual string of the token, they are rather there to show that it is a relation, and not attribute e.g.


This problem seems similar to the one you just solved, but it doesn't seem to be(at least not in my newb experience) :).
I have defined the tokens
| <LEFTPAR: "(">
| <RIGHTPAR: ")">
and <RELATION> is the same as the token <ID>, only a different tokenname.


So I have:
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);}
}
and the relation production:
void Relation() #RELATION:
{Token t = new Token();}
{
t=<RELATION>{jjtThis.setToken(t.kind, t.image);}
}
In Relation() I want to do something like this:
<LEFTPAR>t=<RELATION>{jjtThis.setToken(t.kind, t.image);}<RIGHTPAR>
but this doesn't seem to work.


When I write in the parser: project ssn, name(relationName); The parser returns, "expecting <RELATION>". I get it to work if I define the <RELATION> token to be enclosed by <LEFTPAR> and <RIGHTPAR>. Still, this is not what I want. This token too, should have the string as the relationName in itself, _without_ the parentheses.

This may seem easy for some of you, but I would be happy if you could point me in the right direction for this as well so I can get on with my program.

Thanks in advance,

regards,
Amund


After parsing name it then tries to match Relation(), the first token of Relation is <RELATION> while the next token of the input is "(".

I didn't understand exactly what you mean here... Isn't the first token of Relation() actually <LEFTPAR>, then <RELATION>, and then <RIGHTPAR>?



The answer is similar to the previous one. You need to change Relation() to look for "(" <RELATION> ")".

Yes, this is what I have been trying to do, with things like:


void Relation() #RELATION:
{Token t = new Token();}
{
<LEFTPAR>t=<RELATION>{jjtThis.setToken(t.kind, t.image);}<RIGHTPAR>
}
It seems so easy to do, and I feel this _should_ be correct, but it isn't :S


Think I may have found it! :)
The above expression is correct, however, only if I change the token <RELATION> with <ID> which has the same structure. Is it true that <RELATION> in the expression above calls itself recursively? (Because of #RELATION?) If so, I am a bit wiser today :)


Amund




<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.