Example run of lex calculator
Recognising the input line:
12 3 +14 2-*;newline
(I am using a ^ to indicate where we are on the line,
and newline to mean the single character often represented by \n)
^12 3 +14 2-*;newline
stack= (empty)
12^ 3 +14 2-*;newline
rule= [0-9]+
stack= 12
12 ^3 +14 2-*;newline
rule= [ \t\n]
stack= 12
although the space is discarded, it is essential to separate the two numbers,
otherwise they would be read as one long number 123
12 3^ +14 2-*;newline
rule= [0-9]+
stack= 12 3
12 3 ^+14 2-*;newline
rule= [ \t\n]
stack= 12 3
this space is not essential to separate 3 and +
as they are not recognised by the same pattern in the example calculator
12 3 +^14 2-*;newline
rule= "+"
stack= 15
12 3 +14^ 2-*;newline
rule= [0-9]+
stack= 15 14
12 3 +14 ^2-*;newline
rule= [ \t\n]
stack= 15 14
12 3 +14 2^-*;newline
rule= [0-9]+
stack= 15 14 2
12 3 +14 2-^*;newline
rule= -
stack= 15 12
12 3 +14 2-*^;newline
rule= "*"
stack= 180
12 3 +14 2-*;^newline
rule= ;
stack= (empty)
print "180\n"
12 3 +14 2-*;newline^
rule= [ \t\n]
stack= (empty)