Trying to add subtract multiply and divide variables together but Im getting an error
When I try to define a variable like t = 5 and do println(t*t) I get an error. Can someone please help me fix this? The problem is in parser.py
In line 151 try switching the two
p.NAME1respectively. Also if you want to lower the complexity of your parser, I would recommend adding an interpreting stage and having the parser return an AST
@JacobMcPherson1 Though I don’t have enough time to make an interpreting stage, I can explain what an AST is an get you started in tinge write direction.
For starters, currently when you look at the design of your language, you can see that the syntax is turned into a stream toke using the lexer which will stay the same. Right now, that stream of tokens is being parsed and executed at the same time which can lead to confusion for the parser. To alleviate this what you can do is have the parser return a set of instructions in a tree like form. This is where the AST comes in as it stands for abstract syntax tree and is essentially a set of instructions of the last stage. Now back to the parser, since python doesn’t actually have a tree data structure, we are better off using nested tuples with instructions something like this:
(“println”, (“add”, p.NAME0, p.NAME1))
That was a very generalized example but my point here being that you will have to interpret the AST recursively. Here is a good example on an interpret/execute stage: https://www.google.com/amp/s/www.geeksforgeeks.org/how-to-create-a-programming-language-using-python/amp/
Maybe it is because tt is an integer and you can only print strings?
Try converting tt into a string