You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Carlos DurĂ¡n <ca...@gmail.com> on 2008/11/09 12:45:03 UTC

Tokenizer Lookahead

Hello,
I have checked that there is a conflict(with jexl library) if you define a
method called "foreach",for example.If method's name is the same than the
beginning of a statement defined("foraech" is already defined but you can
define other like "forall","exists"..) the parser doesnt recognize that
method,the statement defined is expected.

This is the grammar.

void Statement() #void :
{}
{
  ";"
|
  Block()
|
  LOOKAHEAD( Reference() ";" ) ReferenceExpression()
|
  LOOKAHEAD( PrimaryExpression() "=" ) StatementExpression()
|
  LOOKAHEAD( Expression() ";" ) ExpressionExpression()
|
  Expression()
|
  IfStatement()
|
 * ForeachStatement()*
|
  WhileStatement()

}



void ForeachStatement() :
{}
{
  "foreach" "(" Reference() "in"  Reference() ")" Statement()
}


---------------------------------------------------------------------------------------------
If I do something like this:

String jexlExp = "foreach(x)";  //there is no problem if the name is not the
same than something defined in the grammar(for example "foreac(x)")
Script script = ScriptFactory.createScript(jexlExp);


the result is:

Exception in thread "main" org.apache.commons.jexl.parser.ParseException:
Encountered ")" at line 1, column 10.
Was expecting one of:
    "in" ...
    "(" ...
    "[" ...
    "." ...

    at
org.apache.commons.jexl.parser.Parser.generateParseException(Parser.java:3786)
    at
org.apache.commons.jexl.parser.Parser.jj_consume_token(Parser.java:3663)
    at
org.apache.commons.jexl.parser.Parser.ForeachStatement(Parser.java:1729)
    at org.apache.commons.jexl.parser.Parser.Statement(Parser.java:1546)
    at org.apache.commons.jexl.parser.Parser.JexlScript(Parser.java:60)
    at org.apache.commons.jexl.parser.Parser.parse(Parser.java:18)
    at
org.apache.commons.jexl.ScriptFactory.createNewScript(ScriptFactory.java:162)
    at
org.apache.commons.jexl.ScriptFactory.createScript(ScriptFactory.java:99)
    at parser.pruebillas.main(pruebillas.java:134)



I think this is connected to Tokenizer Lookahead, but I dont know well what
is the best way to solve the problem,I need help.

Thanks.