-
Notifications
You must be signed in to change notification settings - Fork 2
parsing
Using a recursive descent algorithm, HS parses and executes each sub-expression as soon as the operands are known using a postfix (RPN) expression on an internal stack. The following example illustrates how HS parses and executes statements and expressions. The table below has three columns: the Input column shows the token read by the HS parser at each step, the Expression column shows where HS adds the token prior to execution, the Stack column shows where HS places the token operands, and the Action column shows when HS evaluates a complete sub-expression, popping operands from the stack and pushing a result back onto the stack.
Parsing the following expression:
If ( 10 == ( 7 + 16/2 - 5 ) ) put ( "Hello" ) ;
_
results in the following parse operations:
Input Expression Stack Action
If if
( if (
10 if ( 10
== if ( == 10
( if ( == (
7 if ( == ( 7
if ( == ( + 10 7
16 if ( == ( + 16
/ if ( == ( + / 10 7 16
2 if ( == ( + / 2
if ( == ( + - 10 7 16 2 16 / 2
5 if ( == ( + - 5 10 7 8
) if ( == ( + 10 7 8 5 8 - 5
if ( == 10 7 3 7 + 3
) if ( 10 10 (10 == 10)?
Put put
( put (
"Hello" put ( "Hello"
) "Hello"
; put("Hello")