A small, but not quite correct, changes in CheckTop() and Compile() functions in presented above compiler allows recognition of the operator precedence in expressions:
In contrast to the previous parser which fixed the error in the presence of the choice between shift and reduce, this parser performs reduce only if shift will lead to an empty state (i.e. state with no points).
To take into account the opertors precedence next changes in file c.def may be done:
Also rules for a function call may be simplified:
The modified parser also allow to remove the syntax sugar. For example semicolons, is, then and do keywords may be removed from grammar (and from programs).
If you change the rule for Expr as follow
the expressions will be computed from right to left, i.e. as they are computed in original Tiny Context language.
And adding to CheckTop() function correct choice between shift and reduce. Unfortunately after that program exceeds one thousand lines of code limit:
In some cases these changes allow to choice one of several reduces. For example, it will be possible to replace previously introduced terminal symbols type, var, array and fn with corresponding non-terminal symbols and rules for them:
In the new actions 270, 280, 290 and 300 need to search for a name in the dictionary and verify that the symbol name are really Type, Var, Array or Fn. For example, when trying to access a simple variable as an array element error must be fixed.
After that scaner and parser are made fully independent (scaner no longer need access to the dictionary).
On modern computers, it is not very noticeable (but in DOSBox emulator are noticeable), but the compiler is running slow. At each shift step it build new state (set of points) and at each reduce step it destroy some states. To improve performance set of states and transitions table must be build once. After that work speed may be comparable to manually written recursive descent parser.