A formal language for linear equations

As another example, consider a language for systems of linear equations, with the grammar

equations : equation | equations "," equation
equation : side "=" side
side : term | side operator term
term : integer | variable | integer variable
operator : "+" | "-"
variable : "w" | "x" | "y" | "z"
integer : "0" | positive_integer | "-" positive_integer
positive_integer : positive_digit | positive_integer digit
digit : "0" | positive_digit
positive_digit : "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

As usual, I’ll assume that the lexical analyser strips out whitespace.

The definition of integers is borrowed from an earlier example. I’ve only allowed four variables. For real applications we would probably want more. An example of a string in this language would be \({ 3 z - 1 = x , 2 y = 1 }\). Its parse tree is as in the figure.

Full parse tree for 3 z - 1 = x , 2 y = 1