Hi,
I've just looked at awk's docos for the first time and it seems
suitable for implememting an augumented-finite-state-machine.
Imagine those syntax-diagrams for pascal from the 70s - like
railway-maps, where the tracks loop around/back from
different stations/nodes.
Now stretch it out down the left side of the page, so that
the nodes are all below each other on separate lines, where the
action corresponding to the node/token is listed on the line.
The main track is going down, and any loop-back tracks are
going up behind/to-the-left-of the main-track.
At each/most node there's an action to be performed.
Some nodes are not terminals/leaves and just lead to
another nested syntax-diagram via push & return via pop.
I've built several p-code compilers like this.
From what I see from awks docos, it's very suitable for
doing the [token,action] task, as the source-code is
scanned into tokens and passed to awk.
As I remember, at the branch-points a one token look ahead
only was needed for the pascal-like syntax.
Can awk handle this ?
How would it handle the branching, eg. the sub-diagram for
statement would be like:
Case TOKEN
'IF': next state := IF-node;
'WHILE: next state := WHILE-node;
....
Of course FSMs are also very usefull for eg. ppp implementation,
because the spec. is even given as a FSM .........
==crg.


|