How to store tokens during lexical analysis

I am trying to create a compiler and lexical analysis. Let's say I take the simple "Hello World!" program as a string file and extract tokens from it. What is the best way to store these tokens? In one data structure or in two or more data structures depending on the type of token?

+4
source share
2 answers

You need to build a parse tree, not just a list of tokens. I suggest that you continue reading on this subject before you start coding,

+4
source

Actually, you do not want to store all tokens, period.

, , . , , . node AST. , , , , , , .

, , , - AST ? , , / AST. , .

AST . . , node . YMMV.

+4

Source: https://habr.com/ru/post/1524251/


All Articles