[antlr-interest] Using code inserts in syntactic predicates
Mike Gadsdon
m.gadsdon at rheagroup.com
Wed Mar 16 01:05:36 PST 2005
John,
the parser is doing what I want now with a combination of syntactic and
semantic predicates as below.
Thanks for the hint!
Mike.
// we need to use syntactic predicates to eliminate ambiguity
standardObjectPropertyName
: (sopnConfirmationStatus) => sopnConfirmationStatus
| (sopnValidityStatus) => sopnValidityStatus
| (sopnValue) => sopnValue
| (sopnMonitoringStatus) => sopnMonitoringStatus
| (sopnStatusConsistencyCheckStatus) => sopnStatusConsistencyCheckStatus
| (sopnLimitCheckStatus) => sopnLimitCheckStatus
| (sopnDeltaCheckStatus) => sopnDeltaCheckStatus
| sopnExpectedCheckStatus
;
// following rules define the standard object properties, checking the token
text is
// correct in each case
sopnConfirmationStatus
: {LT(2).getText().equalsIgnoreCase("status")}?
a:CONFIRMATION IDENTIFIER_WORD
{a_AST.setType(Parse.IDENTIFIER_WORD);}
;
sopnValidityStatus
: {LT(1).getText().equalsIgnoreCase("validity") &&
LT(2).getText().equalsIgnoreCase("status")}?
IDENTIFIER_WORD IDENTIFIER_WORD
;
sopnValue
: a:VALUE
{a_AST.setType(Parse.IDENTIFIER_WORD);}
;
sopnMonitoringStatus
: {LT(1).getText().equalsIgnoreCase("monitoring") &&
LT(2).getText().equalsIgnoreCase("status")}?
IDENTIFIER_WORD IDENTIFIER_WORD
;
==============================================================
Mike Gadsdon mailto:m.gadsdon at rheagroup.com
Rhea System S.A Tel +44 (0)20 8891 0702
Fax +44 (0)20 8891 6702
==============================================================
-----Original Message-----
From: John D. Mitchell [mailto:johnm-antlr at non.net]
Sent: 15 March 2005 17:48
To: Mike Gadsdon
Cc: antlr-interest at antlr.org
Subject: [antlr-interest] Using code inserts in syntactic predicates
>>>>> "Mike" == Mike Gadsdon <m.gadsdon at rheagroup.com> writes:
[...]
> I'm trying to use syntactic predicates in conjuction with testing token
> text to resolve parsing ambiguity. Problem is that the code inserts I use
> end up surrounded by a condition on inputState.guessing==0, which means
> that my token text code only runs when the rule is NOT being run as a
> syntactic predicate, but I need it to run always.
Hmm... Why aren't you using semantic predicates then?
Take care,
John
More information about the antlr-interest
mailing list