cslarsen / python-simple-vm

A simple virtual machine w/constant folding implemented in Python

Home Page:https://csl.name/post/vm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexError: Unknown token NEWLINE: ''

VosMottor opened this issue · comments

I guess it is caused by using mac (I'm using MacOSX High Sierra).

Hit CTRL+D or type "exit" to quit.
> 1 1 + println
IndexError: Unknown token NEWLINE: ''

Same error on 3.7.3/RPI, but does not show up when i run the program on 2.x version of python.
This is what i did to fix it:

In the Paser function i added 'tokenize.NEWLINE' criteria of the break rule

elif toknum in [tokenize.ENDMARKER, tokenize.NEWLINE]:
break

De divide opcode is also not correct working, this my fix for that.
added int() to the division

def div(self):
last = self.pop()
self.push(int(self.pop() / last))