Design (LLD) Compiler - Machine Coding
15 Oct 20231 min read
This is the minimum required to show a functioning compiler.
Lexical Analysis (Scanner):
Regex-based tokenization of keywords (
var,print), identifiers, numbers, and operators.Handling of whitespace and basic delimiters (
;,(,)).
Syntax Analysis (Recursive Descent Parser):
Expression Handling: Implementation of operator precedence (e.g., Multiplication before Addition).
Statement Parsing: Support for variable declarations and
printstatements.
Abstract Syntax Tree (AST):
- A clean node hierarchy (e.g.,
BinaryOpNode,LiteralNode,VariableNode).
- A clean node hierarchy (e.g.,
Basic Interpreter:
- A visitor that traverses the AST and executes the logic immediately using a simple Global Symbol Table (Map of
StringtoValue).
- A visitor that traverses the AST and executes the logic immediately using a simple Global Symbol Table (Map of