Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
Artist
Instead of the old Stack Parser or Recursive Descent Parser, we are now using a State Machine Parser. This is totally table-driven, allowing small and faster code, and tidier logic, instead of chains of "if" or "case" statements and random logic. It also allows the Lexer as well as the Parser to be integrated, and syntax errors to be recognised more easily. It is similar in concept to the microcoding of the instruction set rather than using a large random array of gates. Example code :
Parser <:: { (input=%, tree=(), state=0, action={()}, node, token); // Local variables
{* #input : // Loop while input isn't empty
{input => token; // Pop a token from the front of input
action <:: table[token][state]; // See what to do in this state with this token
state <:: next[token][state]; // And where to go next
action(); // Call the action for our state
}
*} // And loop round again
tree}; // Return the parse tree as our result