@top Program { line* }
line {
DerivativeLine | AssignmentLine | Newline
}
DerivativeLine {
DPrefix NumeratorVar Slash DPrefix DenominatorVar Equals Expression
}
AssignmentLine {
AssignmentVar Equals Expression
}
DPrefix { lower_d ~ambiguous }
NumeratorVar { Name }
DenominatorVar { Name }
AssignmentVar { Name ~ambiguous }
Equals { "=" }
Slash { "/" }
Newline { newline1 | newline2 }
Name {
(lower_d | lower_not_d | upper | "_")
(lower_d | lower_not_d | upper | "_" | digit)* ~ambiguous
}
// consumes characters, but not newlines, meaning DerivativeLine and AssignmentLine always stop at newline
@external tokens expressionTokenizer from "./tokens.js" {
Expression
}
@tokens {
lower_d { "d" }
lower_not_d { $[a-c] | $[e-z] }
upper { $[A-Z] }
digit { $[0-9] }
space { " " }
newline1 { "\n" }
newline2 { "\r\n" }
}
@skip { space }
shift/reduce conflict between
(lower_d | lower_not_d | upper | "_" | digit)+ -> · lower_d
and
DPrefix -> lower_d
With input:
lower_d · lower_d …
The reduction of DPrefix is allowed before lower_d because of this rule:
DerivativeLine -> DPrefix · NumeratorVar Slash DPrefix DenominatorVar Equals Expression
Shared origin: line+ -> · line
via line -> · AssignmentLine
via AssignmentLine -> · AssignmentVar Equals Expression
via AssignmentVar -> · Name
via Name -> lower_d · (lower_d | lower_not_d | upper | "_" | digit)+
(lower_d | lower_not_d | upper | "_" | digit)+ -> · lower_d
via line -> · DerivativeLine
via DerivativeLine -> · DPrefix NumeratorVar Slash DPrefix DenominatorVar Equals Expression
DPrefix -> lower_d ·
Hi, my language is basically (line \n)* and there are 2 possible lines:
dx/dt = … (example of DerivativeLine)
name = … (example of AssignmentLine)
But the DPrefix could also be the first character of an AssignmentVar (e.g. ddd = …). The way to choose is whether a Slash appears before encountering Equals (if it does: DerivativeLine, if it does not: AssignmentLine). But I cannot seem to fix it using GLR and I don’t understand why. And some of the features like precedence, dynamic precedence, specialize/extend, I don’t really understand either, if they are even the solution here. I have tried placing ‘~ambiguous’ in many different ways, but the error remains.