diff --git a/README.md b/README.md index 22ed441..8020315 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ describes the language's features, syntax, and usage. - **Control Flow**: Conditional branching (`if`, `elif`, `else`) and loops (`while`). - **Arithmetic Operations**: Basic operations like addition, subtraction, multiplication, and division. - **Logic Operations**: Basic logic operations (`and`, `or`, `xor`,`not`, `negate`) -- **Variables**: Assign and use named variables (`let`). - **Input/Output**: Print strings or variable values. - **Modularity**: Define subroutines for reusable code. - **Comments**: Supports comments anywhere in the code using `#` @@ -41,16 +40,7 @@ end ### Instructions -Instructions include variable assignment, stack operations, arithmetic operations, and control flow constructs. - -#### Variable Assignment - -Assign a value to a variable: - -```imperivm -push 42 -let x -``` +Instructions include variable stack operations, arithmetic operations, and control flow constructs. #### Memory Operations diff --git a/src/executor.py b/src/executor.py index db6634f..953197f 100644 --- a/src/executor.py +++ b/src/executor.py @@ -109,11 +109,6 @@ def instruction_pop(self, args, bindings): value = self.stack.pop() bindings.assign(target, value) - def instruction_let(self, args, bindings): - [(_, target)] = args - value = self.stack.pop() - bindings.assign(target, value) - def instruction_invocation(self, args): _, subroutine = args[0] self.invoke_subroutine(subroutine, Bindings()) @@ -177,8 +172,6 @@ def execute_instruction(self, instruction, bindings: Bindings): self.instruction_push(args, bindings) elif operation == "pop": self.instruction_pop(args, bindings) - elif operation == "let": - self.instruction_let(args, bindings) elif operation == "invocation": self.instruction_invocation(args) elif operation == "stop": diff --git a/src/grammar.py b/src/grammar.py index 0f21e38..bcf48e0 100644 --- a/src/grammar.py +++ b/src/grammar.py @@ -5,10 +5,9 @@ program = ws_0n subroutine (sp_0n br ws_0n subroutine)* ws_0n subroutine = identifier ws_1n block block = begin ws_1n (instruction (sp_0n br ws_0n instruction)*)? ws_1n end - instruction = assignment / conditional / loop / stack / op / io / stop + instruction = conditional / loop / stack / op / io / stop / identifier / halt / store / load - assignment = let sp_1n identifier conditional = if sp_1n value ws_1n block (ws_1n elif sp_1n value ws_1n block)* (ws_1n else ws_1n block)? loop = while sp_1n value ws_1n block stack = (push sp_1n value) / (pop sp_1n identifier) @@ -35,7 +34,7 @@ sp_1n = ~r"[ \t]+" reserved = begin / end / stop / if / elif / else / while / push - / pop / let / add / subtract / multiply / divide / and + / pop / add / subtract / multiply / divide / and / or / xor / not / print / exit / store / load begin = ~r"begin"i / ~r"do"i exit = ~r"exit"i @@ -47,7 +46,6 @@ while = ~r"while"i push = ~r"push"i pop = ~r"pop"i - let = ~r"let"i add = ~r"add"i subtract = ~r"subtract"i multiply = ~r"multiply"i diff --git a/src/visitor.py b/src/visitor.py index f298cce..ad0e7ad 100644 --- a/src/visitor.py +++ b/src/visitor.py @@ -28,15 +28,11 @@ def visit_block(self, _, visited_children): result.insert(0, first) return tuple(result) - def visit_instruction(self, node, visited_children): + def visit_instruction(self, _, visited_children): if visited_children[0][0] == "id": return [("invocation", visited_children[0])] return visited_children - def visit_assignment(self, _, visited_children): - instruction, _, target = visited_children - return instruction.text, target - def visit_conditional(self, _, visited_children): operation, _, condition, _, block, elif_operations, else_operations = visited_children diff --git a/tests/add.imp b/tests/add.imp index ab42c78..3851832 100644 --- a/tests/add.imp +++ b/tests/add.imp @@ -1,7 +1,7 @@ main begin push -5 - let x + pop x push 5 add x exit x diff --git a/tests/and.imp b/tests/and.imp index f33ece8..e9e8899 100644 --- a/tests/and.imp +++ b/tests/and.imp @@ -1,6 +1,6 @@ main begin push 1 - let x + pop x push 2 and x diff --git a/tests/divide.imp b/tests/divide.imp index 02fbe36..45cf292 100644 --- a/tests/divide.imp +++ b/tests/divide.imp @@ -1,7 +1,7 @@ main begin push 0 - let x + pop x push 14884 divide x exit x diff --git a/tests/if.imp b/tests/if.imp index 267b5e9..aa66188 100644 --- a/tests/if.imp +++ b/tests/if.imp @@ -1,7 +1,7 @@ main begin push 1 - let x + pop x if x begin exit 0 diff --git a/tests/if_elif.imp b/tests/if_elif.imp index 643490c..11684d8 100644 --- a/tests/if_elif.imp +++ b/tests/if_elif.imp @@ -1,9 +1,9 @@ main begin push 0 - let x + pop x push 1 - let y + pop y if x begin exit 1 diff --git a/tests/if_elif_else.imp b/tests/if_elif_else.imp index ed81a36..4fb3f24 100644 --- a/tests/if_elif_else.imp +++ b/tests/if_elif_else.imp @@ -1,7 +1,7 @@ main begin push 0 - let x + pop x if x begin exit 1 diff --git a/tests/if_else.imp b/tests/if_else.imp index 549f84d..2a6a961 100644 --- a/tests/if_else.imp +++ b/tests/if_else.imp @@ -1,7 +1,7 @@ main begin push 0 - let x + pop x if x begin exit 1 diff --git a/tests/multiply.imp b/tests/multiply.imp index 86bb711..088bcb5 100644 --- a/tests/multiply.imp +++ b/tests/multiply.imp @@ -1,7 +1,7 @@ main begin push 84781 - let x + pop x push 0 multiply x exit x diff --git a/tests/negate.imp b/tests/negate.imp index 4ee4b9f..a6a2f6a 100644 --- a/tests/negate.imp +++ b/tests/negate.imp @@ -1,6 +1,6 @@ main begin push 1 - let x + pop x negate x push 2 diff --git a/tests/not.imp b/tests/not.imp index 1faa926..882edaa 100644 --- a/tests/not.imp +++ b/tests/not.imp @@ -1,6 +1,6 @@ main begin push 1 - let x + pop x not x if x do diff --git a/tests/or.imp b/tests/or.imp index e34578a..9db6309 100644 --- a/tests/or.imp +++ b/tests/or.imp @@ -1,6 +1,6 @@ main begin push 1 - let x + pop x push 2 or x diff --git a/tests/subtract.imp b/tests/subtract.imp index d5fb219..e91ac23 100644 --- a/tests/subtract.imp +++ b/tests/subtract.imp @@ -1,7 +1,7 @@ main begin push 5 - let x + pop x push 5 subtract x exit x diff --git a/tests/xor.imp b/tests/xor.imp index f198b54..6efc0b6 100644 --- a/tests/xor.imp +++ b/tests/xor.imp @@ -1,6 +1,6 @@ main begin push 1 - let x + pop x push 3 xor x