|
Boost : |
From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-03-26 09:32:55
Dave Gomboc wrote:
> When I define rules x, y, and z such that
>
> x = ch_p('a');
> y = ch_p('a');
> z = !x >> y;
>
> it appears to operate the same as if z were defined to be
>
> z = (ch_p('a') | epsilon_p) >> 'a';
>
> which accepts "aa", but rejects "a".
>
>
> On the other hand, if I define z as
>
> z = (epsilon_p | ch_p('a')) >> 'a'
>
> then "a" is accepted, but "aa" is rejected.
>
>
> (These are, of course, not the actual rules I am interested in, but a
> vast simplification of them, focusing on the point of interest.)
>
> My original expectation had been that first the choice on the left
> side of the or operation would be attempted, but when ultimately
> failing to match
> the entire string later on, to then backtrack and attempt matching
> via the choice on the right side of the or. How can I achieve this
> behaviour?
I am not quiet sure what you mean. AFAICT, given "aa" or "a",
both (ch_p('a') | epsilon_p) and (epsilon_p | ch_p('a')) does not
fail. What do you mean by "failing to match" above?
> In the real problem the semantic actions associated with x and y are
> different, but the inputs they match individually have significant
> overlap, and where they do overlap, I need y to be matched rather
> than x.
Perhaps I can answer this after your first question is clarified.
> On a related note, when I defined BOOST_SPIRIT_DEBUG before
> #including the core, and specified BOOST_SPIRIT_DEBUG_RULE(test); in
> my grammar I
> received the following error message using g++-3.2.2 on linux-i686:
>
> test_grammar.hpp:45: ISO C++ forbits declaration of
> `get_node_registry'
> with no type
> test_grammar.hpp:45: invalid use of `::'
> test_grammar.hpp:45: syntax error before `.' token
>
> Any idea what I might be doing wrong?
Not sure. Can I peek into your test_grammar.hpp?
> Also, please let me know if I should be asking this on a
> spriit-specific
> list rather than boost's.
Spirit-devel mailing list
Spirit-devel_at_[hidden]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
I already cross-posted this there.
Regards,
-- Joel de Guzman joel at boost-consulting.com http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk