
christopher diggins wrote:
struct StartRule { template<typename Elem_T> static bool Accept(ParserInputStream<Elem_T>& in) { switch (in.GetChar()) { case 'a' : return match<RuleA>(in); case 'b' : return match<RuleB>(in); case 'c' : return match<RuleC>(in); case 'd' : return match<RuleD>(in); default : return false; } } }
This approach requires the programmer to figure out the FIRST(N) table by hand. I have found that there are typically only a couple of performance bottlenecks where lookahead is actually needed, and that generating these tables by hand to be easy. Perhaps other's experience is different.
I would be curious how to express the above grammars in Spirit, with and without the hand-rolled lookahead rule.
See: http://www.boost.org/libs/spirit/doc/switch_parser.html. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net