PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Coding & Algorithms/Mithril

Parse code into operation triads IR

Last updated: Mar 29, 2026

Quick Overview

This question evaluates parsing and IR-generation skills, including tokenization, AST or three-address (operation triads) construction, deterministic control-flow serialization, and management of temporaries and labels.

  • medium
  • Mithril
  • Coding & Algorithms
  • Software Engineer

Parse code into operation triads IR

Company: Mithril

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem: Operation-Triads Parsing (Mini Language) You are given a small, line-based programming language consisting of **assignment statements** and **non-nested if–else blocks**. Your task is to parse the input program and **deserialize it into a deterministic intermediate representation (IR)**. You may output either: - a flat list of **operation triads** (three-address/triad form), or - an equivalent structured representation (e.g., AST/JSON). ### Language #### 1) Statements 1. **Assignment** (one per line) - Examples: - `a = 1` - `x = b + c` 2. **If–Else** (block form) ``` if (condition) { assignment } else { assignment } ``` #### 2) Expressions - Operands: variable identifiers (`a`, `b`, `x`) or integers (`1`, `2`, `10`) - Binary operators: `+`, `-`, `*`, `/` - Conditions use comparison operators (at least `==`), e.g. `a + b == 3` - The condition is a binary comparison between two expressions. #### 3) Control-flow constraints - `if–else` blocks **cannot be nested**. - Every `if` **must** have an `else`. - Each `{ ... }` block contains **exactly one assignment statement**. ### Input - A list/array of strings, each string is one line of code, in order. Example input: ``` [a = 1, if (a + b == 3) { x = 10 } else { x = 20 } ] ``` ### Output Produce an IR that preserves execution order and control flow. If using **operation triads**, each instruction is a tuple: - `(op, arg1, arg2)` You may introduce temporary values `t1`, `t2`, … and labels `L1`, `L2`, … as needed. Example (one acceptable triad-style output for the sample): ``` (=, 1, a) (+, a, b) -> t1 (==, t1, 3) -> t2 (if_false, t2, L1) (=, 10, x) (goto, L2, _) (label, L1, _) (=, 20, x) (label, L2, _) ``` ### Requirements - Tokenize and parse the input lines. - Enforce the stated constraints (non-nested `if`, must have `else`, exactly one assignment per block). - Output must be deterministic and serializable. - Clearly define how temporaries and labels are generated.

Quick Answer: This question evaluates parsing and IR-generation skills, including tokenization, AST or three-address (operation triads) construction, deterministic control-flow serialization, and management of temporaries and labels.

Mithril logo
Mithril
Feb 12, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

Problem: Operation-Triads Parsing (Mini Language)

You are given a small, line-based programming language consisting of assignment statements and non-nested if–else blocks. Your task is to parse the input program and deserialize it into a deterministic intermediate representation (IR).

You may output either:

  • a flat list of operation triads (three-address/triad form), or
  • an equivalent structured representation (e.g., AST/JSON).

Language

1) Statements

  1. Assignment (one per line)
    • Examples:
      • a = 1
      • x = b + c
  2. If–Else (block form)
    if (condition) {
      assignment
    } else {
      assignment
    }
    

2) Expressions

  • Operands: variable identifiers ( a , b , x ) or integers ( 1 , 2 , 10 )
  • Binary operators: + , - , * , /
  • Conditions use comparison operators (at least == ), e.g. a + b == 3
  • The condition is a binary comparison between two expressions.

3) Control-flow constraints

  • if–else blocks cannot be nested .
  • Every if must have an else .
  • Each { ... } block contains exactly one assignment statement .

Input

  • A list/array of strings, each string is one line of code, in order.

Example input:

[a = 1,
 if (a + b == 3) {
 x = 10
 } else {
 x = 20
 }
]

Output

Produce an IR that preserves execution order and control flow.

If using operation triads, each instruction is a tuple:

  • (op, arg1, arg2)

You may introduce temporary values t1, t2, … and labels L1, L2, … as needed.

Example (one acceptable triad-style output for the sample):

(=, 1, a)
(+, a, b)        -> t1
(==, t1, 3)      -> t2
(if_false, t2, L1)
(=, 10, x)
(goto, L2, _)
(label, L1, _)
(=, 20, x)
(label, L2, _)

Requirements

  • Tokenize and parse the input lines.
  • Enforce the stated constraints (non-nested if , must have else , exactly one assignment per block).
  • Output must be deterministic and serializable.
  • Clearly define how temporaries and labels are generated.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Mithril•More Software Engineer•Mithril Software Engineer•Mithril Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.