Switching between grammars in one parse

18 views
Skip to first unread message

Paul Bennett

unread,
Feb 22, 2017, 12:10:37 AM2/22/17
to marpa-...@googlegroups.com
I'm writing a tinylang. One of the things the lang needs is a token "XPath", which parses as per the w3c XPath spec, which is highly different to the rest of the language spec. I plan to approach it by writing two grammars. It seems the words for me to grep the pod for are "pause" and "expect" if I'm reading it right.

Are there any teachable examples out there that I can learn from?

Thanks in advance...


--
P/PW/PWBENNETT 

Jeffrey Kegler

unread,
Feb 22, 2017, 12:14:17 AM2/22/17
to Marpa Parser Mailing LIst
Try combining the 2 grammars.  Marpa only recognizes *acceptable* lexemes, so if it is unambiguous which you're looking for, it will only recognizer the "right" set of lexemes.  It's not like standard lexers, where the lexer is looking for everything all the time, and clueless about context.

Can anybody think of examples for Paul?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron Savage

unread,
Feb 22, 2017, 12:32:20 AM2/22/17
to marpa parser
I agree with Jeffrey. I have written a Perl module - GraphViz2::Marpa - which switches, but I did write it in 2 stages. Next time, I'd roll them into a single bnf. Search the mail module for bnf and bnf4html.

Ron Savage

unread,
Feb 22, 2017, 12:33:09 AM2/22/17
to marpa parser
Sigh. That should read 'main' module not 'mail' module.

Paul Bennett

unread,
Feb 22, 2017, 1:27:46 AM2/22/17
to marpa-...@googlegroups.com
Any good examples of mixing grammars? In my "main" grammar I have :discard ~ whitespace (etc), but in the XPath spec whitespace seems to be significant. I'm obviously behind the times ...

I guess I could use "..." around my XPath expressions and treat them as blind strings handled by the semantics.
Reply all
Reply to author
Forward
0 new messages