diff --git a/command.js b/command.js index 69d8492..be8bf2e 100644 --- a/command.js +++ b/command.js @@ -47,13 +47,13 @@ class CommandArg { this.validator = (str) => { return /^[-+]?[0-9]*\.?[0-9]*$/.test(str); } - + break; case ARGUMENT_TYPES.EXPRESSION: this.validator = (str) => { let res = /^[-+]?([0-9]+\.?[0-9]?|[0-9]*\.?[0-9]+)(\s[+-/*]{1}\s[-+]?([0-9]+\.?[0-9]?|[0-9]*\.?[0-9]+))*$/.test(str); return res; } - + break; } } else this.validator = validator; @@ -117,16 +117,15 @@ class CommandExecutor { break; case ARGUMENT_TYPES.FLOAT: this.values.push(parseFloat(value)); + break; case ARGUMENT_TYPES.COMMANDS: this.values.push( new Parser(value, this.callback).parse() ); break; - case ARGUMENT_TYPES.EXPRESSION: - //console.log(this.parseExpression(value)) - this.values.push(this.parseExpression(value).eval()) - + this.values.push(this.parseExpression(value).eval()); + break; case ARGUMENT_TYPES.PARAMETERS: // Example this.values.push(value.split(" ")); break; @@ -147,7 +146,6 @@ class CommandExecutor { e = new Expression(next,new Expression('$',token), right); } else return new Expression('$', token); - //console.log(right); if (right.lvl() > e.lvl()) { let new_left = new Expression(next, new Expression('$',token), right.left); e = new Expression(right.type, new_left, right.right); diff --git a/commandList.js b/commandList.js index b15358b..73eb84a 100644 --- a/commandList.js +++ b/commandList.js @@ -9,33 +9,25 @@ const commandLookUp = new CommandLookUp(); * and then the function to execute. */ commandLookUp.add( - new Command("fd", [new CommandArg("value", ARGUMENT_TYPES.EXPRESSION)], value => { - turtle.forward(value); }) ); commandLookUp.add( - new Command("bd", [new CommandArg("value", ARGUMENT_TYPES.EXPRESSION)], value => { - turtle.forward(-value); }) ); commandLookUp.add( - new Command("rt", [new CommandArg("value", ARGUMENT_TYPES.EXPRESSION)], value => { - turtle.right(value); }) ); commandLookUp.add( - new Command("lt", [new CommandArg("value", ARGUMENT_TYPES.EXPRESSION)], value => { - turtle.right(-value); }) ); @@ -55,9 +47,7 @@ commandLookUp.add( commandLookUp.add( new Command( "pensize", - [new CommandArg("size", ARGUMENT_TYPES.EXPRESSION)], - size => { turtle.strokeWeight = size; } @@ -68,10 +58,8 @@ commandLookUp.add( new Command( "setxy", [ - new CommandArg("x", ARGUMENT_TYPES.EXPRESSION), new CommandArg("y", ARGUMENT_TYPES.EXPRESSION) - ], (x, y) => { turtle.x = x; @@ -81,17 +69,13 @@ commandLookUp.add( ); commandLookUp.add( - new Command("setx", [new CommandArg("x", ARGUMENT_TYPES.EXPRESSION)], x => { - turtle.x = x; }) ); commandLookUp.add( - new Command("sety", [new CommandArg("y", ARGUMENT_TYPES.EXPRESSION)], y => { - turtle.y = y; }) ); diff --git a/expression.js b/expression.js index ff79632..e4d2e12 100644 --- a/expression.js +++ b/expression.js @@ -7,8 +7,8 @@ class Expression { eval() { if(this.type == '$') { - return parseFloat(this.left); - } else if(this.type == '/') { + return parseFloat(this.left); + } else if(this.type == '/') { return this.left.eval() / this.right.eval(); } else if(this.type == '*') { return this.left.eval() * this.right.eval(); diff --git a/index.html b/index.html index 7483bc6..caf21c9 100644 --- a/index.html +++ b/index.html @@ -34,22 +34,18 @@ - +
- + - + Icons made by Turtle from www.flaticon.com is licensed by CC 3.0 BY - - - +