[antlr-interest] Failing on case test: how?

Hendrik Maryns qwizv9b02 at sneakemail.com
Wed Nov 19 08:05:24 PST 2008


Sam Harwell sharwell-at-pixelminegames.com |news.gmane.org| schreef:
> Can you make a rule like:
> 
> variable returns [Variable result]
>   : IDENTIFIER { $result = getVariable($IDENTIFIER.text); }
>   ;
> 
> Where the check is done in the indicated function? If there are cases where only one or the other is allowed, you can also do that semantic analysis at another point. The advantage here is you can have a more "lenient" parser that's able to provide better error messages once you start working on that.

No I can’t, since the constructors of the other formula subtypes expect
a specific type of variable, either first- or second order, so the rules
have to return a variable of the appropriate type.

> The other option with *gated* semantic predicates is (I don't do Java so the code is a best guess on what it might be in Java):
> 
> firstOrderVariable returns [FirstOrderVariable result]
> 	: {Character.isLowerCase( input.LA(1).getText().charAt(0) )} =>
>         IDENTIFIER { $result = getFirstOrderVariable($IDENTIFIER.text); }
> 	;
> 
> secondOrderVariable returns [SecondOrderVariable result]
> 	: {Character.isUpperCase( input.LA(1).getText().charAt(0) )} =>
>         IDENTIFIER { $result = getSecondOrderVariable($IDENTIFIER.text); }
> 	;

I think that is the way to go, thanks.

H.
-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081119/31d4a355/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081119/31d4a355/attachment-0001.bin 


More information about the antlr-interest mailing list