Relative Content

Tag Archive for lexer

Why implement a lexer as a 2d array and a giant switch?

I’m slowly working to finish my degree, and this semester is Compilers 101. We’re using the Dragon Book. Shortly into the course and we’re talking about lexical analysis and how it can be implemented via deterministic finite automata (hereafter, DFA). Set up your various lexer states, define transitions between them, etc.

Passing context around AST nodes

I have various objects inside my AST, such as IfBlock, FunctionBlock, LogicExpression, etc. All of those objects share a context, which is basically a hashmap with some variables. It’s a very simple language, created for learning purposes. I use this hashmap to make it possible that a FunctionBlock is able to modify a variable later used in an LogicExpression.