David Abrahams <[EMAIL PROTECTED]> wrote: > "Joel de Guzman" <[EMAIL PROTECTED]> writes:
>> Now, unlike YACC, Spirit has iteration (kleene, plus, optional) >> Here's a more or less the complete suite of patterns and the >> corresponding semantic-action signatures: >> >> r ::= a b -----> F(tuple<A, B>) >> r ::= a | b -----> F(variant<A, B>) >> r ::= a* -----> F(vector<A>) >> r ::= a+ -----> F(vector<A>) >> r ::= a? -----> F(optional<A>) > > > This is somewhat OT, but I want to suggest you consider something > else. I did this in a parser generator system I wrote, and it worked > out really well. > > If the rule is > > x -> a b | c d c > > Then the way you refer to the semantic value associated with the a > symbol is by writing, simply, 'a'. The way you refer to the semantic > value of the first c symbol is by writing c[0], and you refer to the > 2nd one as c[1]. I'm sure you get the idea. > > Then the user almost never needs to worry about positional > associations between grammar symbols and their semantic values. It's > actually fairly rare that the same symbol appears twice on the rhs of > a rule (especially when rules are reduced to eliminate "|") and > keeping track of whether it's the first or nth instance of 'X' is much > easier than keeping track of precisely where the Xs fall in the > sequence of symbols. > > My system was written in Python, but you might be able to adapt the > general idea to C++. Hmmm, nice! How does it handle iteration like x -> a* and the optional x -> a? -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost