Parsing

Using a recursive descent algorithm, HyperScript 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 HyperScript parses and executes statements and expressions. The table below has three columns: the Input column shows the token read by the HyperScript parser at each step, the Expression column shows where HyperScript adds the token prior to execution, the Stack column shows where HyperScript places the token operands, and the Action column shows when HyperScript 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")