[antlr-interest] New article on StringTemplates and Treewalkers
Sohail Somani
sohail at taggedtype.net
Tue Jan 10 22:45:03 PST 2006
> --------------------------------------------------------------------------------------
> // certain places in Java require a boolean type, where C allows "int" type:
> // * for condition: for (int i=0; b; i++)
> // * while: while (b)
> // * do-while: do { } while (b);
> // * if: if (b)
>
> public class ForceToBooleanRule extends Rule {
> private String newexpr;
> private Token startToken = null;
> private Token endToken = null;
>
> // if we see one of the patterns listed above, set startToken and
> endToken and return true.
> public boolean match(Source source) {
> String current = source.currentToken.getText();
> if (current.equals("for")) {
Is there some reason you just didn't do
if (source.currentToken.getType()==Parser.FOR)...? :)
> // here is where the expression is parsed and changed to be
> boolean type:
> newexpr = ExpressionUtils.forceToBoolean(expr, source);
> return !expr.equals(newexpr);
> }
forceToBoolean must be... err... interesting :)
More information about the antlr-interest
mailing list