Reputation: 199
I'm extremely confused about this error. All I'm trying to do is use the match function but I keep getting a syntax error even though I believe there's nothing wrong with this.
Here's my code:
def compile(code):
code_ptr = 0;
mem_ptr = 0;
memory = [0] * 1000
loop = []
while code_ptr > len(code):
command = code[code_ptr]
match command:
case '>':
mem_ptr += 1
case '<':
mem_ptr -= 1
case: '+':
memory[mem_ptr] + 1
case '-':
memory[mem_ptr] - 1
code_ptr += 1
print(memory)
Here's the error:
match command:
^
SyntaxError: invalid syntax
I'm running Python 3.8.5
Upvotes: 2
Views: 1976
Reputation: 70267
As mentioned in the comments, the match
syntax is only available as of Python 3.10. There are no from __future__
tricks or backports to make it work; it's a significant syntax change. So unfortunately the only way to get this syntax is to upgrade your Python version.
Upvotes: 7