- 19
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
Your task is to create an interpreter for a language that hasThis language doesn't care about syntax, so for an example: "x = 2 n function x add 1" is legal, you could define a function and a variable in the same line, and this applies for everything else.
When defining functions/if statements/loops, you need to know that all the code that goes after it in the same line is its body. There's nothing that indicates their body end other than the end of the line.
When referencing variables, a dollar sign should be at the start, so:
Comments are represented by a
Cases of errors: Invalid variables and invalid functions.
Ex: Referencing variable x which does not exist, or calling function x which also does not exist.
In case of an error: print
Variables are ordered by the order at which they were first created, so the following example would output 5 1:
x = 5
y = 3
z = 1
delete y
Instructions
Format: Instruction || Description || Usage
print || Stop execution and print the variables || print
= || Assigning variables, variables will always be integers ||
add || Add
sub || Subtract
mult || Multiply
delete || Delete
loop || Executes
function || Create function
Logical instructions
Everything here is only used in if blocks.
if || If the condition given is true, execute the
== || Equality operator, If
!= || Not equal operator, if
or || Logical or operator, If at least one of the conditions are true it returns true ||
and || Logical and operator, If both of the conditions are true it returns true ||
Logical instructions accept literal integers or variable values, so variables are referenced when given.
A function call is a function call if it ends with (), functions and variables can have the same name. All names consist of letters only.
Input
Line 1: An integer n for the number of lines
Next n lines: A string consisting of one or more instructions
Next n lines: A string consisting of one or more instructions
Output
Line 1: All variable values separated by a space
Constraints
2 <= n <= 8
Example
Input
2 x = 50 print
Output
50
A higher resolution is required to access the IDE