Open EmmanuelMess opened 4 years ago
That's pretty cool. I had tried something similar a while back, but I never actually filled out the tables according to Jasper's syntax. Is that something you could do?
We don't have a full BNF for Jasper's syntax, but I could try to write it up, if that'd help.
I can try to make production rules that fit the language.
How should redefinitions of the same variable be handled? like: a:= 10; a:=1;
I can try to make production rules that fit the language.
Would having a BNF help?
How should redefinitions of the same variable be handled? like:
a:= 10; a:=1;
It shouldn't be allowed.
That is not what actually happens in the compiler, which could be considered a bug. (EDIT: addressed in #188)
Would having a BNF help?
Reading about BNF, it seems it constructs a context free language, the issue right now for me would be dealing with (variable) names and how to not repeat them.
the issue right now for me would be dealing with (variable) names and how to not repeat them.
The way we handle variables in the compiler is with a stack of hash tables.
Whenever a new scope is introduced (either by a for-statement, a block-statement, or a function-expression), we push a new table onto the stack, and pop it when the scope ends.
When producing a new name, one could generate random (valid) strings until one that is not "in the current scope" is generated.
I propose a function that generates syntactically correct strings, to test the interpreter:
Output: