Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Parsing expression grammar
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Ambiguity detection and influence of rule order on language that is matched === LL(k) and LR(k) parser generators will fail to complete when the input grammar is ambiguous. This is a feature in the common case that the grammar is intended to be unambiguous but is defective. A PEG parser generator will resolve unintended ambiguities earliest-match-first, which may be arbitrary and lead to surprising parses. The ordering of productions in a PEG grammar affects not only the resolution of ambiguity, but also the ''language matched''. For example, consider the first PEG example in Ford's paper<ref name="For04" /> (example rewritten in pegjs.org/online notation, and labelled {{tmath|G_1}} and {{tmath|G_2}}): * {{tmath|G_1}}: {{code|code= A = "a" "b" / "a"}} * {{tmath|G_2}}: {{code|code= A = "a" / "a" "b"}} Ford notes that ''The second alternative in the latter PEG rule will never succeed because the first choice is always taken if the input string ... begins with 'a'.''.<ref name="For04" /> Specifically, {{tmath|L(G_1)}} (i.e., the language matched by {{tmath|G_1}}) includes the input "ab", but {{tmath|L(G_2)}} does not. Thus, adding a new option to a PEG grammar can ''remove'' strings from the language matched, e.g. {{tmath|G_2}} is the addition of a rule to the single-production grammar {{code|code= A = "a" "b"}}, which contains a string not matched by {{tmath|G_2}}. Furthermore, constructing a grammar to match {{tmath|L(G_1) \cup L(G_2)}} from PEG grammars {{tmath|G_1}} and {{tmath|G_2}} is not always a trivial task. This is in stark contrast to CFG's, in which the addition of a new production cannot remove strings (though, it can introduce problems in the form of ambiguity), and a (potentially ambiguous) grammar for {{tmath|L(G_1) \cup L(G_2)}} can be constructed <syntaxhighlight lang="apl"> S β start(G1) | start(G2) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)