craftinginterpreters icon indicating copy to clipboard operation
craftinginterpreters copied to clipboard

Making var optional for declaring new variables

Open mcfriend99 opened this issue 5 years ago • 3 comments

Hi all,

I totally love this tutorial.

But I have been struggling with something lately and I guess it may be nice if we discuss it (if anyone has been able to implement this, I will appreciate a walkthrough).

I want to make the var keyword optional for declaring new variables like Python. It will be an interesting topic. I have tried multiple approaches, but all has one major pitfall... variables are always global.

Is anyone interested in this topic?? Please let's gather here and discuss it.

mcfriend99 avatar Sep 11 '20 19:09 mcfriend99

One of the design notes discusses this exact topic: http://craftinginterpreters.com/statements-and-state.html#design-note :)

munificent avatar Sep 14 '20 22:09 munificent

this is possible but you'd basically have to remove the variable declaration syntax and just leave it as an assignment statement or expression and wait until after parsing to make sure the first time the variable being used means it's a declaration.

kevyonan avatar Sep 15 '20 00:09 kevyonan

At the end, has anyone find a solution to this problem?

RevengerWizard avatar Jan 09 '22 11:01 RevengerWizard