[antlr-interest] WG: RE: RE: rules with parameters are not equivalent to ruleswithout parameters
Kristian Marinkovic
kristian.marinkovic at porsche.co.at
Tue Oct 10 07:07:46 PDT 2006
Hi Remco and John,
thank you very much!!!
a=a_sub did the trick! :)
g,
kris
"Remco van
Engelen"
<Remco.van.Engele An
n at asml.com> "Kristian Marinkovic"
<kristian.marinkovic at porsche.co.at
10.10.2006 14:07 >
Kopie
Thema
RE: RE: [antlr-interest] rules
with parameters are not equivalent
to ruleswithout parameters
Hi Kristian,
Sorry, my bad ;-) It should be:
( a=a_sub | b=b_sub) COL c SEMIC {//do sth};
With the notation a:a_sub you assign to a the AST that is returned by the
rule a_sub, not the return value. If a_sub were a lexer rule, a:a_sub would
return the token of a_sub into a, and you could use the getText() method to
access the token text (this is also a typical idiom to use; but it only
work for lexer rules, not parser rules).
Regards
Remco,
From: Kristian Marinkovic [mailto:kristian.marinkovic at porsche.co.at]
Sent: Tue 10/10/2006 2:05 PM
To: Remco van Engelen
Subject: RE: RE: [antlr-interest] rules with parameters are not equivalent
to ruleswithout parameters
Hi Remco,
the problem is indeed, that ANTLR can't 'see' the rule.
I already tried to change the rules as you suggested
but a and b are not assigned with the desired value.
ANTLR just reports: warning:Rule 'a_sub' returns a value
generated code:
String a = null;
String b = null;
...
switch ( LA(1)) {
case LITERAL_AAA:
{
a_sub();
break;
}
"Remco van
Engelen"
<Remco.van.Engele An
n at asml.com> "Kristian Marinkovic"
<kristian.marinkovic at porsche.co.at
10.10.2006 13:53 >
Kopie
Thema
RE: [antlr-interest] rules with
parameters are not equivalent to
ruleswithout parameters
It seems to me you are calling the subrules directly from within action
code blocks, where ANTLR cannot 'see' them (ANTLR does not look into your
action code). You should be fine if you rewrite it as follows:
body
{
String a = null;
String b = null;
}
:
( a:a_sub | b: b_sub) COL c SEMIC {//do sth};
Regards,
Remco,
From: antlr-interest-bounces at antlr.org on behalf of Kristian Marinkovic
Sent: Tue 10/10/2006 1:43 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] rules with parameters are not equivalent to
ruleswithout parameters
Hello,
i'm trying to understand why antlr is generating different code for rules
with parameters and rules without parameters.
I assumed that the 2 examples below are equivalent?!
example without parameter:
a : "AAA";
b : "BBB";
c : "CCC";
startRule : (body)*;
body : (a | b) COL c SEMIC {//do sth};
example with parameter:
startRule : (body)*;
body
{
String a = null;
String b = null;
}
:
( {a = a_sub();} | {b = b_sub();} ) COL c SEMIC {//do sth};;
a_sub returns [String a] : a { a = "AAA"; //alt. get it from token};
b_sub returns [String b] : b { b =" BBB"; //alt. get it from token};
Is there another way i can solve this? Because the parser with the
parameter is not deterministic! I'm using Antlr 2.7.5
g,
kris
-- The information contained in this communication and any attachments is
confidential and may be privileged, and is for the sole use of the intended
recipient(s). Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please notify the sender
immediately by replying to this message and destroy all copies of this
message and any attachments. ASML is neither liable for the proper and
complete transmission of the information contained in this communication,
nor for any delay in its receipt.
-- The information contained in this communication and any attachments is
confidential and may be privileged, and is for the sole use of the intended
recipient(s). Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please notify the sender
immediately by replying to this message and destroy all copies of this
message and any attachments. ASML is neither liable for the proper and
complete transmission of the information contained in this communication,
nor for any delay in its receipt.
More information about the antlr-interest
mailing list