feat: allow variable declarations without explicit initializers

In the compiler, when parsing a variable declaration, the `=` token is now optional. If present, the initializer expression is compiled as before. If absent, the variable is implicitly initialized to `null` via a call to `null(compiler, false)`. This change removes the previous `TODO` comment and the unconditional `consume` of `TOKEN_EQ`.

Two new test files verify the behavior for both global and local variables without initializers, asserting that reading such a variable yields `null`.
This commit is contained in:
Bob Nystrom
2013-12-23 02:47:58 +00:00
parent 8c13258ef6
commit 75d9a39040
3 changed files with 15 additions and 4 deletions
@@ -0,0 +1,2 @@
var a
IO.write(a) // expect: null
@@ -0,0 +1,4 @@
{
var a
IO.write(a) // expect: null
}