PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Applied

Design a mini compiler/interpreter

Last updated: Mar 29, 2026

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.

  • easy
  • Applied
  • Software Engineering Fundamentals
  • Software Engineer

Design a mini compiler/interpreter

Company: Applied

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 ```

Quick Answer: 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.

Related Interview Questions

  • Design Ordered CUDA Reduction - Applied (medium)
Applied logo
Applied
Feb 12, 2026, 12:00 AM
Software Engineer
Onsite
Software Engineering Fundamentals
2
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

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Applied•More Software Engineer•Applied Software Engineer•Applied Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.