[antlr-interest] How do I fix "code too large" errors?
Andrew Lentvorski
bsder at allcaps.org
Thu Jul 26 19:33:05 PDT 2007
Andrew Lentvorski wrote:
> Yes, I know that this is a Java error, but one does not need a huge
> grammar to hit this.
Here's the grammar that causes the problem. I put comments at the
FREETEXT lines which create the overflow in the lexer.
Any advice would be appreciated.
Thanks,
-a
grammar vcdfile2;
@lexer::members {
boolean flgSimCommand = false;
boolean flgFreeText = false;
boolean flgNWSFreeText = false;
}
vcd : (declaration_command WS*)+ (simulation_command WS*)+ EOF;
simulation_command: dumpvars_scmd | dumpoff_scmd | dumpon_scmd | SIMTIME | value_change;
value_change: (VECTORT WS+ NWSFREETEXT) | (SCALART NWSFREETEXT);
dumpvars_scmd: DUMPVARSK value_change+ ENDK;
dumpoff_scmd: DUMPOFFK value_change+ ENDK;
dumpon_scmd: DUMPONK value_change+ ENDK;
DUMPVARSK: '$dumpvars';
DUMPOFFK: '$dumpoff';
DUMPONK: '$dumpon';
SIMTIME: {flgSimCommand}?=> '#' ('0'..'9')+;
VECTORT: {flgSimCommand}?=> 'b' ('0' | '1' | 'x' | 'X' | 'z' | 'Z')+ {flgNWSFreeText = true;};
SCALART: {flgSimCommand}?=> ('0' | '1' | 'x' | 'X' | 'z' | 'Z') {flgNWSFreeText = true;};
declaration_command: comment_dcmd | date_dcmd | enddef_dcmd | scope_dcmd | upscope_dcmd | var_dcmd | version_dcmd | timescale_dcmd ;
comment_dcmd: COMMENTK FREETEXT ENDK;
date_dcmd: DATEK FREETEXT ENDK;
enddef_dcmd: ENDDEFK WS* ENDK;
scope_dcmd: SCOPEK FREETEXT ENDK;
timescale_dcmd: TIMESCALEK FREETEXT ENDK;
upscope_dcmd: UPSCOPEK WS* ENDK;
var_dcmd: VARK FREETEXT ENDK;
version_dcmd: VERSIONK FREETEXT ENDK;
COMMENTK: '$comment' {flgFreeText = true;};
DATEK : '$date' {flgFreeText = true;};
ENDDEFK : '$enddefinitions' {flgSimCommand = true;};
SCOPEK : '$scope' {flgFreeText = true;};
TIMESCALEK: '$timescale' {flgFreeText = true;};
UPSCOPEK: '$upscope';
VARK : '$var' {flgFreeText = true;};
VERSIONK: '$version' {flgFreeText = true;};
ENDK : '$end';
/* The uncommented FREETEXT line below causes the lexer to blow through its limits */
FREETEXT: {flgFreeText}?=> ( { ! (input.LA(1) == '$' && input.LA(2) == 'e' && input.LA(3) == 'n' && input.LA(4) == 'd') }?=> .)+;
/* This commented FREETEXT line below, however, does not hit the limits */
//FREETEXT: {flgFreeText}?=> (~'$')+ {flgFreeText = false;};
NWSFREETEXT: {flgNWSFreeText}?=> (~WS)+ {flgNWSFreeText=false;};
WS : (' '|'\n'|'\r'|'\t') ;
ANY : .;
More information about the antlr-interest
mailing list