Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From the top of parser_builder.d, which can be found at https://github.com/chadjoan/xdc/blob/master/src/xdc/parser_builder/parser_builder.d
- Unitary Expression: an expression that, given an input string, has only one
- possible match (only one match.end is possible).
- PEG rules are unitary expressions.
- Terminals are unitary expressions as well.
- Ex: aa/a on the input "aaa" has only one match: [aa]a
- Nonunitary Expression: an expression that, given an input string, has many
- possible matches.
- Regular expression operators are nonunitary expressions.
- Ex: aa|a on the input "aaa" may match [a]aa or [aa]a depending on whether the
- code driving the expression requests 1 or 2 characters.
- Both unitary and nonunitary expressions may reside within regular expressions.
- Only unitary expressions are allowed in PEGs.
- Nonunitary expressions can be converted into unitary expressions by using some
- manner of rule to disambiguate which match to take. Intuitively, we define
- "longest" and "shortest" rules to accomplish this.
- We can thus create unitary expressions with nonunitary subexpressions, and
- gain some of the convenience of regular expressions within more powerful
- constructs like PEGs.
- Nonunitary expressions are not reentrant without an explosion of algorithmic
- complexity. This prevents PEGs from having things like unordered choice:
- A <- b*aB
- B <- (A|b*)
- In this case, the rule called within the unordered choice (the | operator)
- will invoke B again and reenter the choice without first resolving the succuss
- of the first unordered choice entry. This ambiguity can result in repeated
- backtracking.
- (TODO: is this example good? maybe use a better one that will obviously create
- a lot of backtracking.)
- The concatenation of a nonunitary expression and a unitary expression is nonunitary.
- PEG elements may not follow nonunitary expressions in concatenation without
- suffering a large penalty in algorithmic complexity. This arrangement
- requires nonlocal backtracing out of failed matches of the PEG until a place
- on the input is found where the nonunitary expression before it matches and
- the PEG also matches the text ahead of it. To maintain linear complexity,
- such nonlinear expressions preceding PEGs must be disambiguated with some
- rule like longest-match or shortest-match.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement