Skip to content

Are %shift modifiers still supported to resolve ambiguities? #26

@mewmew

Description

@mewmew

From my understanding of http://textmapper.org/documentation.html#grammar-ambiguities, %shift modifiers may be used to resolve shift/reduce ambiguities in grammars.

From the example, I tried to derive a minimal working grammar. However, when I tried to generate the parser using Textmapper, I got the following error:

$ textmapper shiftreduce.tm 
shiftreduce.tm,34: input: 'if' '(' Expr ')' Stmt
shift/reduce conflict (next: 'else')
    IfStmt : 'if' '(' Expr ')' Stmt

conflicts: 1 shift/reduce and 0 reduce/reduce
lalr: 0.019s, text: 0.105s, parser: 18 states, 0KB

From https://github.com/mewspring/foo/blob/427ecc6ddb2a95906cea7570c5b28c33abc26544/shiftreduce/shiftreduce.tm#L33:

IfStmt
	: 'if' '(' Expr ')' Stmt %shift 'else'
	| 'if' '(' Expr ')' Stmt 'else' Stmt
;

Is that the correct syntax for using %shift modifiers, and if so, why is there a shift/reduce error being reported?

If I remove 'if' '(' Expr ')' Stmt %shift 'else' from the grammar, Textmapper is able to successfully produce both lexers and parsers.

Edit: this is on version v0.9.22 of Textmapper.

u@x1 ~> textmapper --version
textmapper v0.9.22/java build 2018

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions