[ 
https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832675#action_12832675
 ] 

Jeff Ichnowski commented on JEXL-97:
------------------------------------

Thanks for the quick attention!  Confirmed on my end too.  My apologies for not 
being clear that it was limited to 1.x as far as we've tried.  Our problem is 
in 1.1 and we've got too much tied into it currently to do a major upgrade 
quickly.  Is there a possibility of a 1.1 patch?

The LOOKAHEAD and recognized syntax in JEXL 2.0 is much simpler.  Perhaps a 1.1 
patch release (if planned) could use the 2.0 structure instead of the patch I 
proposed above.  Unfortunately it would break anything that depended on 
expressions like  "(a) = 1" being recognized (which currently is by 1.1).

{code:title=JEXL 2.0 Expression}
void Expression() #void : {}
{
    LOOKAHEAD( Reference() "=" ) Assignment()
|
    ConditionalExpression()
}
{code}

{code:title=JEXL 1.1 Expression with Problem}
void Expression() : {}
{
    LOOKAHEAD( PrimaryExpression() "=" ) Assignment()
|
    ConditionalOrExpression()
}
{code}

{code:title=JEXL 1.0 Alternate Fix}
void Expression() : {}
{
    LOOKAHEAD( Reference() "=" ) Assignment()
|
    ConditionalOrExpression()
}
{code}


> JEXL parses long expressions with lots of parenthesis slowly
> ------------------------------------------------------------
>
>                 Key: JEXL-97
>                 URL: https://issues.apache.org/jira/browse/JEXL-97
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         Attachments: proposed.patch
>
>
> JEXL's parser uses an unbounded JavaCC LOOKAHEAD to distinguish assignment 
> expressions from other expressions.  The result is certain expressions take 
> exponential time to parse.  The example snippet below demonstrates the 
> problem.  On my machine parsing the expression below takes ~120 seconds.  
> Changing the parser to remove the LOOKAHEAD can get this to parse in 
> milliseconds.  The lookahead appears to be in all versions of the parser 
> source.
> import org.apache.commons.jexl.Expression;
> import org.apache.commons.jexl.ExpressionFactory;
> public class SlowParse {
>     public static void main(String[] args) throws Exception {
>         String input = 
>             
> "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";
>         // Make sure everything is loaded...
>         Expression expr = ExpressionFactory.createExpression(input);
>         long start = System.nanoTime();
>         expr = ExpressionFactory.createExpression(input);
>         long end = System.nanoTime();
>         System.out.printf("Parse took %.1f seconds\n", (end-start)/1e+9);
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to