Creating ambiguous parses in external scanner

15 views
Skip to first unread message

Thomas Weigert

unread,
Jul 20, 2015, 11:26:57 AM7/20/15
to marpa-...@googlegroups.com
I am trying to figure out how I can create, from within an external scanner, an ambiguous parse. What I want to achieve is this: I get fed an event from marpa, and now in the code handling this event I will need to recognize the matched symbol as two different lexemes, each causing a different parse to result.

From the documentation it seems that I could call lexeme_alternative() twice, once for each lexeme I want to create. But, alas....

Could you please point me to an example where somebody has successfully done something like this?

In summary, I hope to, in a pause look at the expected symbols. If I find that certain symbols are expected, create a parse for each of them, resulting in a parse forest. (In fact, I know already that one of the alternatives will die later, but at this point, I do not yet know which.)

Thanks, Th.

Jeffrey Kegler

unread,
Jul 20, 2015, 12:02:07 PM7/20/15
to Marpa Parser Mailing LIst
Calling lexeme_alternative() twice should work, and I believe it's a technique used in an app or two.  RNS pointed to the location of some examples in this thread: https://groups.google.com/forum/#!topic/marpa-parser/X2DLX8q6Byw



--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Kegler

unread,
Jul 20, 2015, 12:12:17 PM7/20/15
to Marpa Parser Mailing LIst
There's a use by RNS here: https://github.com/rns/MarpaX-Languages-Lua-AST/blob/e5cce31936d32dc4944b1b9274564a24621015bb/lib/MarpaX/Languages/Lua/AST.pm#L542 -- I haven't studied this app, but it looks fairly standard.


The RNS use may be the easier one to study.  It's a more standard use than Jean-Damien, and it's for a parser for Lua, which has a much simpler grammar.



On Mon, Jul 20, 2015 at 8:26 AM, Thomas Weigert <weigert...@gmail.com> wrote:

--

Ruslan Shvedov

unread,
Jul 20, 2015, 2:04:27 PM7/20/15
to marpa-...@googlegroups.com
There are also a couple of examples in Marpa::R2 test suite with internal scanning (lexeme_alternative() is used in external scanning, as in the examples provided by Jeffrey) -- ambiguous lexemes as defined as multiple RHS alternatives on a lexical rule with the same LHS, e.g.:

NNS ~ 'shoots' | 'leaves'
VBZ ~ 'eats' | 'shoots' | 'leaves'

IN ~ 'like'
VBP ~ 'like'
NN ~ 'time':i
VBP ~ 'time':i

You can then use Marpa::R2::ASF interface to build/prune a parse forest or tree (sl_panda1.t) or just enumerate the parse trees (sl_timeflies.t).


--
Reply all
Reply to author
Forward
0 new messages