This SDF3 syntax:

context-free start-symbols
    Start

context-free syntax
    Start           = Exp
    Exp.Var         = <<ID>>
    Exp.Int         = <<INT>>
    Exp             = OpExp
    OpExp.Add       = <<Exp> + <Exp>> {left}
    OpExp.Sub       = <<Exp> - <Exp>> {left}

context-free priorities
    { left:
        OpExp.Add 
        OpExp.Sub
    }

context-free priorities
    { left:
        Exp = Exp "+" Exp
        Exp = Exp "-" Exp
    }

parses this example:

x + 10

ambiguously. I get this error:

Fragment is ambiguous: either or Add

and this AST where one possible tree contains a tuple?

amb([
       (Var("x"), Int("10")),
    Add(Var("x"), Int("10"))
])

The ambiguity seems to come from the priority rules that are obviously wrong as there are no corresponding syntax rules:

context-free priorities
    { left:
        Exp = Exp "+" Exp
        Exp = Exp "-" Exp
    }

In reality the ‘wrong’ priority rules where buried deep inside my project, and I couldn’t figure out where the tuple in the ambiguous AST came from. I believe this is an SDF2 issue.

Am I correct to assume that any rule specified in the context-free priorities section should also be a rule that’s defined in a context-free syntax section? In that case, specifying priority rules that are not syntax rules is an error, and this strange behavior should not occur.

Submitted by D. Pelsmaeker on 7 August 2014 at 17:28

Log in to post comments