::SHE+ILA::'s New Parser and Lexer [$6F]

Diagram of a Finite State Machine with States and Transitions
37
1
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • Prompt
    Read prompt
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    3h ago
  • Try

More about ::SHE+ILA::'s New Parser and Lexer [$6F]

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

Comments


Loading Dream Comments...

Discover more dreams from this artist