Georgios Petasis wrote:
> ----- Original Message ----- From: "Joel" <joel@...>
> To: <spirit-general@...>
> Sent: Monday, April 18, 2005 3:03 AM
> Subject: [Spirit-general] Re: How to reduce the time needed to compile
> this grammar?
>> Georgios Petasis wrote:
>>> Dear list members,
>>> Finally, ANTLR does not seem to fulfil the task :-)
>>> I got an initial impression at first that it does, but my solution
>>> for making it act as a "filter" conflicts with its lookahead
>>> features, and finds only a subset of the text ranges that
>>> matches the grammar.
>>> And as I wasn't able to find information on how to
>>> make ANTLR act as a "filter", I gave up on it.
>>> So, I am back into using spirit, which can perform
>>> the task I want, as the lexer & parser are not two
>>> different entities, as in ANTLR. Also, I managed
>>> to get g++ to compile my (large) grammars, by
>>> splitting large rules. For example, instead of
>>> S = B1 | B2 | B3 | ... | B5000;
>>> I used:
>>> S = S_1 | S_2 | S_3 | ...;
>>> S_1 = B1 | ... | B10;
>>> S_2 = B11 | ... | B20;
>>> I am not sure why this helps, but it does.
>>> I have attached a small file that has a small grammar
>>> that uses this technique. It would be nice if anybody
>>> could explain why using intermediate symbols in the grammar
>>> helps, as I couldn't find anything about this in the FAQ.
>> Welcome back :)
>> Because a very big single expression *is* the one thet's
>> choking your compiler. Breaking it up gives you small
>> easily digestable chunks for the compiler to eat.
>> Still, I suggest you use the symbols parser. You can also
>> it break down this way. I'd even suggest using a for loop
>> to stuff the strings which come from a vector<string>.
>> That would make it a lot faster and manageable.
> I am using the symbols table, for all rule bodies that have only a single
> terminal. I think I can not use it anywhere else :-)
> For example:
> S -> "A"
> S -> "Z"
> S-> "A" "B"
> S-> "C" "B"
> From these rules, I will create:
> symbols<> S_symbol_table;
> S = longest_d[ ("A" >> "B")|("C" >> "B") |(S_symbol_table) ]);
> Is there anything better I can do?
Will this code snippet from the test directory help?
sym = "pineapple", "orange", "banana", "applepie", "apple";
check(sym, "pineapple", true, "", 9);
check(sym, "orange", true, "", 6);
check(sym, "banana", true, "", 6);
check(sym, "apple", true, "", 5);
check(sym, "pizza", false, "pizza", -1);
check(sym, "steak", false, "steak", -1);
check(sym, "applepie", true, "", 8);
Notice "apple" and "applepie". See libs/spirit/test/symbols_tests.cpp
Joel de Guzman