Consider an interface like this for setting up a TDOP with Pratt:
var parser = OperatorPrecidence(c => c
.Level(l => l
.Left(Number())
)
.Level(l => l
.Left(Match('-'), (ctx, state, token) => { ... })
)
.Level(l => l
.Right(Match('+'), (ctx, state, token) => { ... })
.Right(Match('-'), (ctx, state, token) => { ... })
)
.Level(l => l
.Right(Match('*'), (ctx, state, token) => { ... })
.Right(Match('/'), (ctx, state, token) => { ... })
)
.Level(l => l
.RightAssociative(r => r
.Right(Match('.'), (ctx, state, token) => { ... })
)
)
);
With a setup like this, we don't have to manually change precedence levels every time we want to insert something into the table, we just add a new .Level() call and everything just works. Need to do some work on the Left/Right associativity though.
Consider an interface like this for setting up a TDOP with Pratt:
With a setup like this, we don't have to manually change precedence levels every time we want to insert something into the table, we just add a new
.Level()call and everything just works. Need to do some work on the Left/Right associativity though.