[antlr-interest] Rapidly expanding grammar when using gated predicate

Jonathan Roberts plasticfridge at googlemail.com
Fri Feb 10 03:28:21 PST 2012


Hello all,

Hope you can help.  I am trying to parse a file format called L5K (Allen
Bradley Logix Controller language) and have hit a snag. Below is a small
sample of some encoded data.





                ENCODED_DATA ( Name := "EncData",

                              Description := "Some Encoded data",

                              Revision := "1.0",

                              RevisionExtension := "Initial Release",

                              RevisionNote := "08-06-16: Version 1.0 -
Initial release")



                                xbr+GxxsZhjttrjMWfkzJFlYwrgbwregbwrwer
<<Lots more encoded data follows>>



                END_ENCODED_DATA



Parsing the start tag, end tag and parameter list is not an issue. The
problem is the line that starts ‘xbr+Gxxs’.



This is just a long sting of encoded data that terminates with a new line.
A small sample of the grammar that I am using to match is as follows…





ENCODED_DATA

                :               'ENCODED_DATA' {parseState.isEncodedData =
true;}

                ;



END_ENCODED_DATA

                :               'END_ENCODED_DATA'
{parseState.isEncodedData = false;}

                ;



ENC_DATA_LINE

                :               {parseState.isEncodedData}?=> (~'\n')+

                ;



This seams to work pretty well when tested in isolation but when combined
with the rest of the L5K grammar generates me a huge java file that simple
will not compile (too large).



I have tried splitting the grammar into multiple files in the hope that I
can make smaller java files that will compile with little success.



I have also tried with a C# target and while that will compile it results
in several other problems with the generated code (exceptions not being
caught, AST issues etc).


I am using version 3.4 as previous versions take issue with the gated
predicate.



Anyone have any thoughts on how to solve this problem?


Kind regards


Jonathan Roberts


More information about the antlr-interest mailing list