开发者

Table-driven lexical analyzer/scanner implementation

开发者 https://www.devze.com 2023-02-16 23:26 出处:网络
Actually I have two questions. If I start writing my own lexical analyzer, parser what architecture it will be? Wha开发者_高级运维t principles should I consider (i.e. Open-Close, loose coupling)?

Actually I have two questions. If I start writing my own lexical analyzer, parser what architecture it will be? Wha开发者_高级运维t 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消