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
signature.asc
Description: PGP signature
signature.asc
Description: OpenPGP digital signature
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
