Snowflake Interview Question: Implement a Mini Programming Language Interpreter

16 Views
No Comments

SnowCal is a simple programming language used to perform calculations. A SnowCal program keeps a single integer X in memory, initially set to zero, and repeatedly performs addition and multiplication operations on it. Formally, the language has 5 operations:

  • ADD Y → add Y to X
  • MUL Y → multiply X by Y
  • FUN F → begin the definition of a function with unique name F
  • END → end of current function
  • INV F → invoke function F

Write an interpreter that takes in the commands as an array of strings and returns the final value of X.


Example Programs

Input:

MUL 2
ADD 3

Output:

3

Input:

FUN INCREMENT
  ADD 1
END

INV INCREMENT
MUL 2
ADD 3

This problem asks you to implement an interpreter for a simplified programming language called SnowCal, which maintains a single integer X in memory (initially 0). The language supports five commands:

  • ADD Y → add Y to X
  • MUL Y → multiply X by Y
  • FUN F → begin defining a user-defined function named F
  • END → end of the current function
  • INV F → invoke function F

You must parse the program line-by-line, store any function definitions, and correctly execute operations (including nested or repeated function calls). The output is the final value of X after processing all commands.

Core challenges include:

  • Managing function definitions and scopes
  • Handling function invocation correctly
  • Ensuring commands execute sequentially
  • Avoiding recursion issues if functions call each other

This tests a candidate’s ability to design an interpreter, manage state, and implement clean parsing and execution logic.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including SnowFlake, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0