Design a mini compiler/interpreter

Quick Overview

This question evaluates understanding of language design and implementation skills, including lexical analysis, parsing into an AST, expression evaluation with operator precedence and unary operators, variable assignment semantics, and runtime error reporting.

Design a mini compiler/interpreter

Company: Applied Intuition

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Onsite

## Problem Design and implement a **mini compiler / interpreter** for a small expression language. You are given a program as a string (possibly multiple lines). The language supports: - Integer literals, e.g. `42` - Variables and assignment, e.g. `x = 3 + 4` - Arithmetic: `+ - * /` with standard precedence and parentheses - Unary minus, e.g. `-x` - A `print(expr)` statement that outputs an integer ### Task Build a pipeline that: 1. Tokenizes the input (lexer) 2. Parses tokens into an AST (parser) 3. Evaluates the AST (interpreter) and produces the printed outputs in order ### Clarifications - Integer division truncates toward zero. - All variables are global. - Invalid syntax should raise a clear error. ### Example Program: ``` x = 10 print(x + 2 * 3) print(-(x - 7)) ``` Output: ``` 16 -3 ```

Overview: This question evaluates understanding of language design and implementation skills, including lexical analysis, parsing into an AST, expression evaluation with operator precedence and unary operators, variable assignment semantics, and runtime error reporting.

|Home/Software Engineering Fundamentals/Applied Intuition
Applied Intuition logo
Applied Intuition
Feb 12, 2026
easySoftware EngineerOnsiteSoftware Engineering Fundamentals
8
0

Problem

Design and implement a mini compiler / interpreter for a small expression language.

You are given a program as a string (possibly multiple lines). The language supports:

  • Integer literals, e.g. 42
  • Variables and assignment, e.g. x = 3 + 4
  • Arithmetic: + - * / with standard precedence and parentheses
  • Unary minus, e.g. -x
  • A print(expr) statement that outputs an integer

Task

Build a pipeline that:

  1. Tokenizes the input (lexer)
  2. Parses tokens into an AST (parser)
  3. Evaluates the AST (interpreter) and produces the printed outputs in order

Clarifications

  • Integer division truncates toward zero.
  • All variables are global.
  • Invalid syntax should raise a clear error.

Example

Program:

x = 10
print(x + 2 * 3)
print(-(x - 7))

Output:

16
-3
Loading comments...