Issue #2 expression fix, updated readme.

This commit is contained in:
Marvin Blum
2015-10-25 18:37:51 +01:00
parent bf283cb87a
commit 665c9e27a1
5 changed files with 10 additions and 4 deletions

View File

@@ -61,6 +61,12 @@ var number = 123;
var floatingPointNumber = 1.23; var floatingPointNumber = 1.23;
var string = "string"; var string = "string";
var array = [1, 2, 3]; var array = [1, 2, 3];
// accessing array elements:
var one = array[0];
// accessing using a statement:
var zwo = array[33/3-2];
``` ```
### Control structures ### Control structures

View File

@@ -1,6 +1,6 @@
var array = [1, 2, 3]; var array = [1, 2, 3];
var x = array[0]; var x = array[0];
if array[1] == 2 { if array[(1-1)+10/10] == 2 {
foo(); foo();
} }

View File

@@ -1,5 +1,5 @@
array = [1,2,3]; array = [1,2,3];
x = (array select 0); x = (array select 0);
if ((array select 1)==2) then { if ((array select (1-1)+10/10)==2) then {
[] call foo; [] call foo;
}; };

View File

@@ -424,7 +424,7 @@ func parseIdentifier() string {
output += "("+get().token output += "("+get().token
next() next()
expect("[") expect("[")
output += " select "+parseExpression(false)+")" output += " select ("+parseExpression(false)+"))"
expect("]") expect("]")
} else if accept("!") || accept("-") { } else if accept("!") || accept("-") {
output = get().token output = get().token

View File

@@ -131,7 +131,7 @@ func TestParserWaitUntil(t *testing.T) {
func TestParserArray(t *testing.T) { func TestParserArray(t *testing.T) {
got := getCompiled(t, "test/parser_array.asl") got := getCompiled(t, "test/parser_array.asl")
want := "x = [1,2,3];\ny = (x select 1);\n" want := "x = [1,2,3];\ny = (x select (1));\n"
equal(t, got, want) equal(t, got, want)
} }