advanced

Design a Compiler Lexer and Parser

Design the front-end of a compiler. Include a lexer that tokenizes source code, a parser that builds an abstract syntax tree, AST node hierarchy, symbol table management, and expression evaluation.

Suggested time: 45 minutes

Loading the workspace...

About this problem

A compiler front-end (lexer + parser) is an excellent OOD problem because it combines the Composite pattern (AST trees), Visitor pattern (decoupled operations), and precise state management (tokenization). Let's define exactly what the system must do.

What your design needs to cover

  • Tokenization

  • Parsing into AST

  • Expression Support

  • Statement Support

  • Symbol Table

Key challenges the editorial covers

Learn from other designs

Related problems

Guides