Skip to content

Unexpected GLR parse result #159

@gafusss

Description

@gafusss

Consider the following example:

from parglare import Grammar, GLRParser

grammar = r"""
DOC: S? QZ;

terminals

QZ: /Q?Z/;
S: /(Q|Z)/;
"""

g = Grammar.from_string(grammar)
parser = GLRParser(g, debug=True, error_recovery=False)

result = parser.parse("QZ")

print("Result = ", result.to_str())

With parglare==0.21.0, the output is as follows:

1:  DOC[0->2]
    S_opt[0->0]
    QZ[1->2, "Z"]
2:  DOC[0->2]
    S_opt[0->1]
      S[0->1, "Q"]
    QZ[1->2, "Z"]

Notice that in the first tree, the "Q" from the input is missing. However, as far as I understand, that should not be possible.
What am I doing wrong, is there a gap in my understating of GLR parsers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions