Table-driven lexical analyzer/scanner implementation

1.2k views Asked by At

Actually I have two questions. If I start writing my own lexical analyzer, parser what architecture it will be? What principles should I consider (i.e. Open-Close, loose coupling)?

Next question is about table-driven lexical analyzer implementation. Recently I have written lexical analyzer but it's not a programming pearl. Obviously I've used too straight approach). So does anyone know about how to implement table driven lexical analyzer?

1

There are 1 answers

0
Hexception On

So if you want to build a lexer your goal is a function that returns the next token by "eating" an input-stream.

The best choice is to implement a deterministic-finite-automation. That means you first have to create the table for the DFA. And the function runs through the DFA table and ends at a specific end state and each end state is assigned to a token. So just return that token and you have a table-driven lexer.