1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
lexeme
  • 2,915
  • 10
  • 60
  • 125

1 Answers1

0

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.

Hexception
  • 722
  • 10
  • 25