The parsing part I was fine with, strip whitespace, split on equals, tokenize the expression.
Clarify the DSL grammar and evaluation semantics, then propose a two-phase approach: parse each line into a dependency graph, and evaluate via topological sort with cycle detection. Discuss error handling for undefined variables and cycles, and how to return partial results.
Pro tip: Mention that you would separate parsing from evaluation to make the system testable and extensible, and that you would use memoization to avoid re-evaluating expressions.
Ask about the DSL syntax (e.g., variable names, operators, parentheses), whether expressions can be multi-line, and how to handle errors (skip vs. report). Confirm the expected output format.
Tokenize each line, ignoring whitespace, and parse into an AST or a simple structure capturing the variable name and its expression. Identify all variable references within the expression.
Create a directed graph where edges represent dependencies between variables. Use DFS or Kahn's algorithm to detect cycles; any variable in a cycle cannot be evaluated.
Process variables in an order where dependencies are resolved first. For each variable, evaluate its expression using already computed values; if a dependency is undefined or in a cycle, mark the variable as failed.
Collect successfully evaluated variables into a map. For undefined variables or cycles, either omit them or include error information, depending on requirements. Discuss trade-offs.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.