Avoiding full context parsing strategy

31 views
Skip to first unread message

Jonathan Martin

unread,
Oct 29, 2015, 8:54:07 AM10/29/15
to antlr-discussion
Hi,

I'm trying to adjust an Antlr4 grammar I've written so that the generated parser can run in SSL mode with the majority of inputs for maximum performance but I'm having difficulty preventing the full context strategy from being invoked for simple IF statements.  Here is a simplified example with test input.

grammar ContextSensitivity;

statement :
    IF INTEGER_LITERAL statement ( ELSE statement )?
  | RETURN
;

IF     : 'IF';
ELSE   : 'ELSE';
RETURN : 'RETURN';

INTEGER_LITERAL : [0-9]+ ;

WHITE_SPACE :
    [ \t\r\n]+ -> skip ;


Test input:

IF 1
  RETURN
ELSE
  RETURN


The diagnostics output shows that the full context strategy has been invoked even for this simple input.

$ grun ContextSensitivity statement -diagnostics -SSL < test.sql
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
line 3:0 reportAttemptingFullContext d=0 (statement), input='ELSE'
line 4:2 reportContextSensitivity d=0 (statement), input='ELSERETURN'
$


Firstly, am I interpreting this correctly?  Assuming I am, is this to be expected or is there a way to prevent this?

Thanks,

Jonathan
Reply all
Reply to author
Forward
0 new messages