Browse Source

base of new compiler with some tests, added eof to tokenizer and tests

Kajetan Johannes Hammerle 5 years ago
parent
commit
909b453830
100 changed files with 1013 additions and 358 deletions
  1. 37 0
      src/me/hammerle/snuviscript/compiler/Array.java
  2. 10 0
      src/me/hammerle/snuviscript/compiler/Break.java
  3. 10 0
      src/me/hammerle/snuviscript/compiler/Catch.java
  4. 382 292
      src/me/hammerle/snuviscript/compiler/Compiler.java
  5. 27 0
      src/me/hammerle/snuviscript/compiler/Constant.java
  6. 10 0
      src/me/hammerle/snuviscript/compiler/Continue.java
  7. 10 0
      src/me/hammerle/snuviscript/compiler/Else.java
  8. 10 0
      src/me/hammerle/snuviscript/compiler/ElseIf.java
  9. 10 0
      src/me/hammerle/snuviscript/compiler/For.java
  10. 43 0
      src/me/hammerle/snuviscript/compiler/Function.java
  11. 31 0
      src/me/hammerle/snuviscript/compiler/Goto.java
  12. 10 0
      src/me/hammerle/snuviscript/compiler/If.java
  13. 49 0
      src/me/hammerle/snuviscript/compiler/Instruction.java
  14. 51 0
      src/me/hammerle/snuviscript/compiler/ReturnWrapper.java
  15. 6 0
      src/me/hammerle/snuviscript/compiler/Script2.java
  16. 27 0
      src/me/hammerle/snuviscript/compiler/SignInverter.java
  17. 10 0
      src/me/hammerle/snuviscript/compiler/Try.java
  18. 26 0
      src/me/hammerle/snuviscript/compiler/UserFunction.java
  19. 10 0
      src/me/hammerle/snuviscript/compiler/While.java
  20. 35 1
      src/me/hammerle/snuviscript/test/Test.java
  21. 1 0
      src/me/hammerle/snuviscript/test/TestLogger.java
  22. 32 15
      src/me/hammerle/snuviscript/token/TokenType.java
  23. 1 0
      src/me/hammerle/snuviscript/token/Tokenizer.java
  24. 0 0
      test/calc/base.cout
  25. 1 0
      test/calc/base.tout
  26. 0 0
      test/calc/mixed.cout
  27. 1 0
      test/calc/mixed.tout
  28. 6 0
      test/comments/comment0.cout
  29. 1 0
      test/comments/comment0.tout
  30. 4 0
      test/comments/comment1.cout
  31. 1 0
      test/comments/comment1.tout
  32. 6 0
      test/comments/comment2.cout
  33. 1 0
      test/comments/comment2.tout
  34. 6 0
      test/comments/comment3.cout
  35. 1 0
      test/comments/comment3.tout
  36. 0 0
      test/conditions/conditions0.cout
  37. 1 0
      test/conditions/conditions0.tout
  38. 0 0
      test/conditions/conditions1.cout
  39. 1 0
      test/conditions/conditions1.tout
  40. 0 0
      test/conditions/conditions2.cout
  41. 1 0
      test/conditions/conditions2.tout
  42. 0 0
      test/conditions/conditions3.cout
  43. 1 0
      test/conditions/conditions3.tout
  44. 0 0
      test/conditions/conditions4.cout
  45. 1 0
      test/conditions/conditions4.tout
  46. 0 0
      test/conditions/conditions5.cout
  47. 1 0
      test/conditions/conditions5.tout
  48. 0 0
      test/conditions/conditions6.cout
  49. 1 0
      test/conditions/conditions6.tout
  50. 0 0
      test/conditions/conditions7.cout
  51. 1 0
      test/conditions/conditions7.tout
  52. 0 0
      test/conditions/conditions8.cout
  53. 1 0
      test/conditions/conditions8.tout
  54. 1 1
      test/for_break_continue/for_break_continue0
  55. 0 0
      test/for_break_continue/for_break_continue0.cout
  56. 8 2
      test/for_break_continue/for_break_continue0.tout
  57. 1 1
      test/for_break_continue/for_break_continue1
  58. 0 0
      test/for_break_continue/for_break_continue1.cout
  59. 8 3
      test/for_break_continue/for_break_continue1.tout
  60. 1 1
      test/for_break_continue/for_break_continue2
  61. 0 0
      test/for_break_continue/for_break_continue2.cout
  62. 8 3
      test/for_break_continue/for_break_continue2.tout
  63. 1 1
      test/for_break_continue/for_break_continue3
  64. 0 0
      test/for_break_continue/for_break_continue3.cout
  65. 8 3
      test/for_break_continue/for_break_continue3.tout
  66. 1 1
      test/for_break_continue/for_break_continue4
  67. 0 0
      test/for_break_continue/for_break_continue4.cout
  68. 8 3
      test/for_break_continue/for_break_continue4.tout
  69. 1 1
      test/for_break_continue/for_break_continue5
  70. 0 0
      test/for_break_continue/for_break_continue5.cout
  71. 8 3
      test/for_break_continue/for_break_continue5.tout
  72. 2 2
      test/for_break_continue/for_break_continue6
  73. 0 0
      test/for_break_continue/for_break_continue6.cout
  74. 15 4
      test/for_break_continue/for_break_continue6.tout
  75. 2 2
      test/for_break_continue/for_break_continue7
  76. 0 0
      test/for_break_continue/for_break_continue7.cout
  77. 15 4
      test/for_break_continue/for_break_continue7.tout
  78. 2 2
      test/for_break_continue/for_break_continue8
  79. 0 0
      test/for_break_continue/for_break_continue8.cout
  80. 15 4
      test/for_break_continue/for_break_continue8.tout
  81. 3 3
      test/for_break_continue/for_break_continue9
  82. 0 0
      test/for_break_continue/for_break_continue9.cout
  83. 22 6
      test/for_break_continue/for_break_continue9.tout
  84. 0 0
      test/functions/functions0.cout
  85. 1 0
      test/functions/functions0.tout
  86. 0 0
      test/functions/functions1.cout
  87. 1 0
      test/functions/functions1.tout
  88. 0 0
      test/functions/functions10.cout
  89. 1 0
      test/functions/functions10.tout
  90. 0 0
      test/functions/functions11.cout
  91. 1 0
      test/functions/functions11.tout
  92. 0 0
      test/functions/functions12.cout
  93. 1 0
      test/functions/functions12.tout
  94. 0 0
      test/functions/functions13.cout
  95. 1 0
      test/functions/functions13.tout
  96. 0 0
      test/functions/functions14.cout
  97. 1 0
      test/functions/functions14.tout
  98. 0 0
      test/functions/functions2.cout
  99. 1 0
      test/functions/functions2.tout
  100. 0 0
      test/functions/functions3.cout

+ 37 - 0
src/me/hammerle/snuviscript/compiler/Array.java

@@ -0,0 +1,37 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+import me.hammerle.snuviscript.variable.Variable;
+
+public class Array extends Instruction
+{
+    private final int arguments;
+    private final ReturnWrapper wrapper = new ReturnWrapper();
+    private final Variable v;
+    
+    public Array(int line, int arguments, Variable v)
+    {
+        super(line);
+        this.arguments = arguments;
+        this.v = v;
+    }
+    
+    @Override
+    public InputProvider execute(Script sc, InputProvider[] in) throws Exception
+    {
+        Object o = v.get(sc);
+        for(InputProvider ip : in)
+        {
+            o = java.lang.reflect.Array.get(o, ip.getInt(sc));
+        }
+        wrapper.setValue(o);
+        return wrapper;
+    }
+
+    @Override
+    public int getArguments()
+    {
+        return arguments;
+    }
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/Break.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Break extends Goto
+{
+    public Break(int line)
+    {
+        super(line, 0);
+    }
+    
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/Catch.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Catch extends Goto
+{
+    public Catch(int line)
+    {
+        super(line, 0);
+    }
+    
+}

+ 382 - 292
src/me/hammerle/snuviscript/compiler/Compiler.java

@@ -1,389 +1,479 @@
 package me.hammerle.snuviscript.compiler;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import me.hammerle.snuviscript.code.FunctionLoader;
+import me.hammerle.snuviscript.code.ISnuviLogger;
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.constants.ConstantBoolean;
+import me.hammerle.snuviscript.constants.ConstantDouble;
+import me.hammerle.snuviscript.constants.ConstantNull;
+import me.hammerle.snuviscript.constants.ConstantString;
 import me.hammerle.snuviscript.exceptions.PreScriptException;
 import me.hammerle.snuviscript.token.Token;
 import me.hammerle.snuviscript.token.TokenType;
+import static me.hammerle.snuviscript.token.TokenType.*;
+import me.hammerle.snuviscript.variable.Variable;
 
 public class Compiler
 {
+    private final ISnuviLogger logger;
     private int index = 0;
     private Token[] tokens = null;
+    private final ArrayList<Instruction> instr = new ArrayList<>();
+    private final HashMap<String, Integer> labels = new HashMap<>();
+    private final HashMap<String, Variable> vars = new HashMap<>();
+
+    public Compiler(ISnuviLogger logger)
+    {
+        this.logger = logger;
+    }
     
-    public Compiler()
+    private void addConstant(int line, InputProvider ip)
     {
+        instr.add(new Constant(line, ip));
     }
     
-    public void checkSyntax(Token[] tokens)
+    private void addFunction(int line, int args, String name)
     {
-        this.tokens = tokens;
-        index = 0;
-        checkLine();
+        instr.add(new Function(line, args, FunctionLoader.getFunction(name)));
     }
     
-    private Token consumeToken()
+    private boolean match(TokenType... types)
     {
-        if(index >= tokens.length)
+        for(TokenType type : types)
         {
-            return null;
+            if(check(type))
+            {
+                advance();
+                return true;
+            }
         }
-        return tokens[index++];
+        return false;
     }
-    
-    private Token peekOrNullToken()
+
+    private boolean check(TokenType type)
     {
-        if(index >= tokens.length)
+        if(isAtEnd())
         {
-            return null;
+            return false;
         }
+        return peek().getType() == type;
+    }
+
+    private Token advance()
+    {
+        if(!isAtEnd())
+        {
+            index++;
+        }
+        return previous();
+    }
+
+    private boolean isAtEnd()
+    {
+        return peek().getType() == EOF;
+    }
+
+    private Token peek()
+    {
         return tokens[index];
     }
+
+    private Token previous()
+    {
+        return tokens[index - 1];
+    }
     
-    private Token peekToken()
+    private Token consume(TokenType type) 
     {
-        if(index >= tokens.length)
+        if(check(type))
         {
-            throw new PreScriptException("missing token at end of file", -1);
+            return advance();
         }
-        return tokens[index];
+        throw new PreScriptException(String.format("exptected %s got %s", type, peek().getType()), peek().getLine());
+    }  
+
+    public Script2 compile(Token[] tokens)
+    {
+        this.tokens = tokens;
+        index = 0;
+        instr.clear();
+        labels.clear();
+        vars.clear();
+
+        while(!isAtEnd())
+        {
+            line();
+        }
+        
+        for(Instruction i : instr)
+        {
+            logger.print(i.toString(), null, null, null, null, -1);
+        }
+        
+        return null;
     }
     
-    private void consumeTokenAndCheck(TokenType... type)
+    private void line()
     {
-        Token t = consumeToken();
-        if(t == null)
+        int oldIndex = index;
+        Token t = advance();
+        switch(t.getType())
         {
-            throw new PreScriptException("missing token at end of file " + type, -1);
+            case IF: handleIf(); break;
+            case LABEL: labels.put(previous().getData().toString(), instr.size()); break;
+            case SEMICOLON: break;
+            case FOR: handleFor(); break;
+            case BREAK: 
+                instr.add(new Break(previous().getLine())); 
+                consume(SEMICOLON);
+                break;
+            case CONTINUE:
+                instr.add(new Continue(previous().getLine()));
+                consume(SEMICOLON);
+                break;
+            case FUNCTION: handleUserFunction(); break;
+            case RETURN: handleReturn(); break;
+            case WHILE: handleWhile(); break;
+            case TRY: handleTry(); break;
+            default:
+                index = oldIndex;
+                expression();
+                consume(SEMICOLON);
         }
-        for(TokenType ty : type)
+    }
+    
+    private void handleIf()
+    {
+        Token t = previous();
+        consume(OPEN_BRACKET);
+        expression();
+        instr.add(new If(t.getLine()));
+        consume(CLOSE_BRACKET);
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
         {
-            if(ty == t.getType())
-            {
-                return;
-            }
+            line();
         }
-        throw new PreScriptException("unexpected token " + t, t.getLine());
+        handleElseIf();
     }
     
-    private void checkFunctionArguments()
+    private void handleElseIf()
     {
-        TokenType type = peekToken().getType();
-        if(type == TokenType.CLOSE_BRACKET)
+        while(match(ELSEIF))
         {
-            consumeToken();
-            return;
+            Token t = previous();
+            consume(OPEN_BRACKET);
+            expression();
+            instr.add(new Else(t.getLine()));
+            consume(CLOSE_BRACKET);
+            consume(OPEN_CURVED_BRACKET);
+            while(!match(CLOSE_CURVED_BRACKET))
+            {
+                line();
+            }
         }
+        handleElse();
+    }
 
-        consumeTokenAndCheck(TokenType.LITERAL);
-
-        while(true)
+    private void handleElse()
+    {
+        if(match(ELSE))
         {
-            type = peekToken().getType();
-            if(type == TokenType.CLOSE_BRACKET)
+            instr.add(new Else(previous().getLine()));
+            consume(OPEN_CURVED_BRACKET);
+            while(!match(CLOSE_CURVED_BRACKET))
             {
-                consumeToken();
-                return;
+                line();
             }
-            consumeTokenAndCheck(TokenType.COMMA);
-            consumeTokenAndCheck(TokenType.LITERAL);
         }
     }
     
-    private void checkLine()
+    private void handleFor()
     {
-        while(true)
+        Token t = previous();
+        consume(OPEN_BRACKET);    
+        if(!match(SEMICOLON))
         {
-            Token t = peekOrNullToken();
-            if(t == null || t.getType() == TokenType.CLOSE_CURVED_BRACKET)
-            {
-                break;
-            }
-            consumeToken();
-            switch(t.getType())
+            expression();
+            consume(SEMICOLON);
+        }
+        if(!match(SEMICOLON))
+        {
+            expression();
+            consume(SEMICOLON);
+        }
+        if(!match(CLOSE_BRACKET))
+        {
+            expression();
+            consume(CLOSE_BRACKET);
+        }
+        instr.add(new For(t.getLine()));
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
+        {
+            line();
+        }
+    }
+    
+    private void handleUserFunction()
+    {
+        consume(LITERAL);
+        Token t = previous();
+        consume(OPEN_BRACKET);
+        ArrayList<String> list = new ArrayList<>();
+        if(!match(CLOSE_BRACKET))
+        {
+            while(true)
             {
-                case LITERAL:
-                    switch(t.getData().toString())
-                    {
-                        case "function":
-                            consumeTokenAndCheck(TokenType.LITERAL);
-                            consumeTokenAndCheck(TokenType.OPEN_BRACKET);
-                            checkFunctionArguments();
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case "for":
-                            consumeTokenAndCheck(TokenType.OPEN_BRACKET);
-                            checkArguments(TokenType.CLOSE_BRACKET);
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case "else":
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case "elseif":
-                        case "while":
-                        case "if":
-                            consumeTokenAndCheck(TokenType.OPEN_BRACKET);
-                            checkExpression();
-                            consumeTokenAndCheck(TokenType.CLOSE_BRACKET);
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case "try":
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            Token token = consumeToken();
-                            if(token.getType() != TokenType.LITERAL || !token.getData().equals("catch"))
-                            {
-                                throw new PreScriptException("try without catch", token.getLine());
-                            }
-                            consumeTokenAndCheck(TokenType.OPEN_CURVED_BRACKET);
-                            checkLine();
-                            consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case "continue":
-                        case "break":
-                            consumeTokenAndCheck(TokenType.SEMICOLON);
-                            break;
-                        case "return":
-                            if(peekToken().getType() == TokenType.SEMICOLON)
-                            {
-                                consumeToken();
-                            }
-                            else
-                            {
-                                checkExpression();
-                                consumeTokenAndCheck(TokenType.SEMICOLON);
-                            }
-                            break;
-                        default:
-                            checkAfterLiteral(true);
-                            consumeTokenAndCheck(TokenType.SEMICOLON);
-                    }
-                    break;
-                case OPEN_CURVED_BRACKET:
-                    checkLine();
-                    consumeTokenAndCheck(TokenType.CLOSE_CURVED_BRACKET);
-                    break;
-                /*case DOLLAR:
-                    checkVariable();
-                    checkVariableOperation(true);
-                    consumeTokenAndCheck(TokenType.SEMICOLON);
-                    break;*/
-                case LABEL:
-                    consumeTokenAndCheck(TokenType.LITERAL, TokenType.NUMBER);
-                    break;
-                case SEMICOLON:
-                    break;
-                case INC:
-                case DEC:
-                    Token token = peekToken();
-                    //if(token.getType() == TokenType.DOLLAR)
-                    {
-                        consumeToken();
-                    }
-                    checkVariable();
-                    consumeTokenAndCheck(TokenType.SEMICOLON);
+                consume(LITERAL);
+                list.add(previous().getData().toString());
+                if(match(CLOSE_BRACKET))
+                {
                     break;
-                default:
-                    throw new PreScriptException("unexpected token " + t, t.getLine());
+                }
+                consume(COMMA);
             }
+        }  
+        instr.add(new UserFunction(t.getLine(), t.getData().toString(), list.toArray(new String[list.size()])));
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
+        {
+            line();
         }
-    }  
+    }
     
-    private void checkVariable()
+    private void handleReturn()
     {
-        consumeTokenAndCheck(TokenType.LITERAL);
-        
-        Token t = peekToken();
-        if(t.getType() == TokenType.OPEN_SQUARE_BRACKET)
+        if(!match(SEMICOLON))
         {
-            consumeToken();
-            checkArguments(TokenType.CLOSE_SQUARE_BRACKET);
+            expression();
+            consume(SEMICOLON);
         }
     }
     
-    private void checkAfterLiteral(boolean line)
+    private void handleWhile()
     {
-        Token t = peekToken();
-        switch(t.getType())
+        Token t = previous();
+        consume(OPEN_BRACKET);
+        expression();
+        instr.add(new While(t.getLine()));
+        consume(CLOSE_BRACKET);
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
         {
-            case OPEN_BRACKET:
-                consumeToken();
-                checkArguments(TokenType.CLOSE_BRACKET);
-                if(!line)
-                {
-                    checkCalc();
-                }
-                return;
-            case OPEN_SQUARE_BRACKET:
-                consumeToken();
-                checkArguments(TokenType.CLOSE_SQUARE_BRACKET);
-                checkVariableOperation(line);
-                return; 
-            case INC:
-            case DEC:
-                consumeToken();
-                checkCalc();
-                return; 
-            case SET: 
-            case ADD_SET:
-            case SUB_SET: 
-            case MUL_SET:
-            case DIV_SET:
-            case MOD_SET:
-            case LEFT_SHIFT_SET:
-            case RIGHT_SHIFT_SET: 
-            case BIT_AND_SET:
-            case BIT_XOR_SET: 
-            case BIT_OR_SET:
-                consumeToken();
-                checkExpression();
-                return;
-            default:
-                if(line)
-                {
-                    throw new PreScriptException("unexpected token " + t, t.getLine());
-                }
+            line();
         }
-        
-        checkCalc();
     }
     
-    private void checkVariableOperation(boolean line)
+    private void handleTry()
     {
-        Token t = peekToken();
+        instr.add(new Try(previous().getLine()));
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
+        {
+            line();
+        }
+        consume(CATCH);
+        instr.add(new Catch(previous().getLine()));
+        consume(OPEN_CURVED_BRACKET);
+        while(!match(CLOSE_CURVED_BRACKET))
+        {
+            line();
+        }
+    }
+
+    private void expression()
+    {
+        assignment();
+    }
+    
+    private void assignment()
+    {
+        logicalOr();
+        if(match(SET, ADD_SET, SUB_SET, MUL_SET, DIV_SET, MOD_SET, LEFT_SHIFT_SET, 
+                RIGHT_SHIFT_SET, BIT_AND_SET, BIT_XOR_SET, BIT_OR_SET))
+        {
+            Token t = previous();
+            assignment();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }   
+    
+    private void logicalOr()
+    {
+        logicalAnd();
+        while(match(OR))
+        {
+            Token t = previous();
+            logicalAnd();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }  
+    
+    private void logicalAnd()
+    {
+        equality();
+        while(match(AND))
+        {
+            Token t = previous();
+            equality();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }  
+
+    private void equality()
+    {
+        comparison();
+        while(match(EQUAL, NOT_EQUAL))
+        {
+            Token t = previous();
+            comparison();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }
+
+    private void comparison()
+    {
+        addition();
+        while(match(GREATER, GREATER_EQUAL, LESS, LESS_EQUAL))
+        {
+            Token t = previous();
+            addition();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }
+
+    private void addition()
+    {
+        multiplication();
+        while(match(SUB, ADD))
+        {
+            Token t = previous();
+            multiplication();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }
+
+    private void multiplication()
+    {
+        unary();
+        while(match(DIV, MUL))
+        {
+            Token t = previous();
+            unary();
+            addFunction(t.getLine(), 2, t.getType().getName());
+        }
+    }
+
+    private void unary()
+    {
+        if(match(INVERT, BIT_INVERT, SUB, INC, DEC))
+        {
+            Token t = previous();
+            unary();
+            addFunction(t.getLine(), 1, t.getType().getName());
+            return;
+        }
+        postUnary();
+    }
+    
+    private void postUnary()
+    {
+        primary();
+        while(match(INC, DEC))
+        {
+            Token t = previous();
+            addFunction(t.getLine(), 1, "p" + t.getType().getName());
+        }
+    }
+
+    private void primary()
+    {
+        Token t = advance();
         switch(t.getType())
         {
-            case INC:
-            case DEC:
-            case SET: 
-            case ADD_SET:
-            case SUB_SET: 
-            case MUL_SET:
-            case DIV_SET:
-            case MOD_SET:
-            case LEFT_SHIFT_SET:
-            case RIGHT_SHIFT_SET: 
-            case BIT_AND_SET:
-            case BIT_XOR_SET: 
-            case BIT_OR_SET:
-                consumeToken();
-                checkExpression();
-                break;
-            default:
-                if(line)
+            case FALSE: addConstant(t.getLine(), ConstantBoolean.FALSE); return;
+            case TRUE: addConstant(t.getLine(), ConstantBoolean.FALSE); return;
+            case NULL: addConstant(t.getLine(), ConstantNull.NULL); return;
+            case STRING: addConstant(t.getLine(), new ConstantString(t.getData().toString())); return;
+            case LABEL: addConstant(t.getLine(), new ConstantString(t.getData().toString().substring(1))); return;
+            case NUMBER: addConstant(t.getLine(), new ConstantDouble((Double) t.getData())); return;
+            case OPEN_BRACKET:
+                expression();
+                consume(CLOSE_BRACKET);
+                return;
+            case LITERAL:
+                if(match(OPEN_SQUARE_BRACKET))
+                {
+                    handleArray(t);
+                }
+                else if(match(OPEN_BRACKET))
                 {
-                    throw new PreScriptException("unexpected token " + t, t.getLine());
+                    handleFunction(t);
                 }
                 else
                 {
-                    checkCalc();
+                    addConstant(t.getLine(), getVariable(t.getData().toString()));
                 }
+                return;
         }
+        throw new PreScriptException(String.format("unexpected token %s", t.getType()), t.getLine());
     }
     
-    private void checkCalc()
+    public void handleFunction(Token t)
     {
-        Token t = peekToken();
-        switch(t.getType())
+        int args = 0;
+        if(peek().getType() != CLOSE_BRACKET)
         {
-            case MUL:
-            case DIV:
-            case MOD:
-            case ADD:
-            case SUB:
-            case LEFT_SHIFT:
-            case RIGHT_SHIFT:
-            case LESS:
-            case LESS_EQUAL:
-            case GREATER:
-            case GREATER_EQUAL:
-            case EQUAL:
-            case NOT_EQUAL:
-            case BIT_AND:
-            case BIT_XOR:
-            case BIT_OR:
-            case AND:
-            case OR:
-                consumeToken();
-                checkExpression();
-                break;
+            while(true)
+            {
+                args++;
+                expression();
+                if(match(CLOSE_BRACKET))
+                {
+                    break;
+                }
+                consume(COMMA);
+            }
         }
+        else
+        {
+            consume(CLOSE_BRACKET);
+        }
+        addFunction(t.getLine(), args, t.getData().toString());
     }
     
-    private void checkArguments(TokenType end)
+    public void handleArray(Token t)
     {
-        Token t = peekToken();
-        if(t.getType() == end)
+        if(peek().getType() == CLOSE_SQUARE_BRACKET)
         {
-            consumeToken();
-            return;
+            throw new PreScriptException("empty array access", peek().getLine());
         }
-        
-        checkExpression();
-        
+        int args = 0;
         while(true)
         {
-            t = peekToken();
-            if(t.getType() == end)
+            args++;
+            expression();
+            if(match(CLOSE_SQUARE_BRACKET))
             {
-                consumeToken();
-                return;
+                break;
             }
-            consumeTokenAndCheck(TokenType.COMMA);
-            checkExpression();
+            consume(COMMA);
         }
+        instr.add(new Array(t.getLine(), args, getVariable(t.getData().toString())));
     }
     
-    private void checkExpression()
+    private Variable getVariable(String name)
     {
-        Token t = consumeToken();
-        switch(t.getType())
+        Variable v = vars.get(name);
+        if(v != null)
         {
-            case SUB:
-                checkExpression();
-                break;
-            case NUMBER:
-            case STRING:
-                checkCalc();
-                break;
-            case LITERAL:
-                checkAfterLiteral(false);
-                break;
-            case OPEN_BRACKET:
-                checkExpression();
-                consumeTokenAndCheck(TokenType.CLOSE_BRACKET);
-                checkCalc();
-                break;
-            /*case DOLLAR:
-                checkVariable();
-                checkVariableOperation(false);
-                break;*/
-            case LABEL:
-                consumeTokenAndCheck(TokenType.LITERAL);
-                break;
-            case INC:
-            case DEC:
-                Token token = peekToken();
-                //if(token.getType() == TokenType.DOLLAR)
-                {
-                    consumeToken();
-                }
-                checkVariable();
-                checkCalc();
-                break;
-            case INVERT:
-            case BIT_INVERT:
-                checkExpression();
-                break;          
-            default:
-                throw new PreScriptException("unexpected token " + t, t.getLine());
+            return v;
         }
+        v = new Variable(name);
+        vars.put(name, v);
+        return v;
     }
 }

+ 27 - 0
src/me/hammerle/snuviscript/compiler/Constant.java

@@ -0,0 +1,27 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+
+public class Constant extends Instruction
+{
+    private final InputProvider constant;
+    
+    public Constant(int line, InputProvider constant)
+    {
+        super(line);
+        this.constant = constant;
+    }
+
+    @Override
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
+    {
+        return constant;
+    }
+
+    @Override
+    public String toString()
+    {
+        return String.format("push %s", constant.toString());
+    }
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/Continue.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Continue extends Goto
+{
+    public Continue(int line)
+    {
+        super(line, 0);
+    }
+    
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/Else.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Else extends Goto
+{
+    public Else(int line)
+    {
+        super(line, 0);
+    }
+    
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/ElseIf.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class ElseIf extends Goto
+{
+    public ElseIf(int line)
+    {
+        super(line, 1);
+    }
+    
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/For.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class For extends Goto
+{
+    public For(int line)
+    {
+        super(line, 2);
+    }
+    
+}

+ 43 - 0
src/me/hammerle/snuviscript/compiler/Function.java

@@ -0,0 +1,43 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.BasicFunction;
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+
+public class Function extends Instruction
+{
+    private final BasicFunction function;
+    private final int arguments;
+    private final ReturnWrapper wrapper = new ReturnWrapper();
+    
+    public Function(int line, int arguments, BasicFunction function)
+    {
+        super(line);
+        this.function = function;
+        this.arguments = arguments;
+    }
+
+    @Override
+    public InputProvider execute(Script sc, InputProvider[] in) throws Exception
+    {
+        Object o = function.execute(sc, in);
+        if(o == Void.TYPE)
+        {
+            return null;
+        }
+        wrapper.setValue(o);
+        return wrapper;
+    }
+
+    @Override
+    public int getArguments()
+    {
+        return arguments;
+    }
+
+    @Override
+    public String toString()
+    {
+        return String.format("use %s(%d)", function.getName(), arguments);
+    }
+}

+ 31 - 0
src/me/hammerle/snuviscript/compiler/Goto.java

@@ -0,0 +1,31 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Goto extends Instruction
+{
+    private int jump;
+    private final int arguments;
+    
+    public Goto(int line, int arguments)
+    {
+        super(line);
+        this.arguments = arguments;
+    }
+
+    @Override
+    public int getArguments()
+    {
+        return arguments;
+    }
+    
+    @Override
+    public void setJump(int value)
+    {
+        jump = value;
+    }
+
+    @Override
+    public int getJump()
+    {
+        return jump;
+    }
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/If.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class If extends Goto
+{
+    public If(int line)
+    {
+        super(line, 1);
+    }
+    
+}

+ 49 - 0
src/me/hammerle/snuviscript/compiler/Instruction.java

@@ -0,0 +1,49 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+
+public abstract class Instruction
+{
+    private final static String[] VARS = new String[0];
+    private final int line;
+    
+    public Instruction(int line)
+    {
+        this.line = line;
+    }
+
+    public int getLine()
+    {
+        return line;
+    }
+    
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
+    {
+        return null;
+    }
+    
+    public int getArguments()
+    {
+        return 0;
+    }
+    
+    public void setJump(int value)
+    {
+    }
+    
+    public int getJump()
+    {
+        return 0;
+    }
+    
+    public String[] getVars()
+    {
+        return VARS;
+    }
+    
+    public String getName()
+    {
+        return "";
+    }
+}

+ 51 - 0
src/me/hammerle/snuviscript/compiler/ReturnWrapper.java

@@ -0,0 +1,51 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+import me.hammerle.snuviscript.variable.Variable;
+
+public class ReturnWrapper extends InputProvider
+{
+    private Object o;
+    
+    public void setValue(Object o)
+    {
+        this.o = o;
+    }
+
+    @Override
+    public Object get(Script sc) throws Exception
+    {
+        return o;
+    }
+    
+    @Override
+    public Object getArray(Script sc) throws Exception
+    {
+        return o;
+    }
+    
+    @Override
+    public double getDouble(Script sc) throws Exception
+    {
+        return (double) o;
+    }
+    
+    @Override
+    public String getString(Script sc) throws Exception
+    {
+        return String.valueOf(o);
+    }
+    
+    @Override
+    public boolean getBoolean(Script sc) throws Exception
+    {
+        return (Boolean) o;
+    }
+    
+    @Override
+    public Variable getVariable(Script sc) throws Exception
+    {
+        return (Variable) o;
+    }
+}

+ 6 - 0
src/me/hammerle/snuviscript/compiler/Script2.java

@@ -0,0 +1,6 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Script2
+{
+    
+}

+ 27 - 0
src/me/hammerle/snuviscript/compiler/SignInverter.java

@@ -0,0 +1,27 @@
+package me.hammerle.snuviscript.compiler;
+
+import me.hammerle.snuviscript.code.InputProvider;
+import me.hammerle.snuviscript.code.Script;
+
+public class SignInverter extends Instruction
+{
+    private final ReturnWrapper wrapper = new ReturnWrapper();
+    
+    public SignInverter(int line)
+    {
+        super(line);
+    }
+
+    @Override
+    public int getArguments()
+    {
+        return 1;
+    }
+
+    @Override
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
+    {
+        wrapper.setValue(-o[0].getDouble(sc));
+        return wrapper;
+    }
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/Try.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class Try extends Goto
+{
+    public Try(int line)
+    {
+        super(line, 0);
+    }
+    
+}

+ 26 - 0
src/me/hammerle/snuviscript/compiler/UserFunction.java

@@ -0,0 +1,26 @@
+package me.hammerle.snuviscript.compiler;
+
+public class UserFunction extends Goto
+{
+    private final String[] vars;
+    private final String name;
+    
+    public UserFunction(int line, String name, String[] vars)
+    {
+        super(line, 0);
+        this.vars = vars;
+        this.name = name;
+    }
+
+    @Override
+    public String[] getVars()
+    {
+        return vars;
+    }
+
+    @Override
+    public String getName()
+    {
+        return name;
+    }
+}

+ 10 - 0
src/me/hammerle/snuviscript/compiler/While.java

@@ -0,0 +1,10 @@
+package me.hammerle.snuviscript.compiler;
+
+public class While extends Goto
+{
+    public While(int line)
+    {
+        super(line, 1);
+    }
+    
+}

+ 35 - 1
src/me/hammerle/snuviscript/test/Test.java

@@ -7,6 +7,7 @@ import java.util.function.BiConsumer;
 import me.hammerle.snuviscript.code.SnuviParser;
 import me.hammerle.snuviscript.token.Tokenizer;
 import me.hammerle.snuviscript.token.Token;
+import me.hammerle.snuviscript.compiler.Compiler;
 
 public class Test
 {
@@ -19,7 +20,8 @@ public class Test
     public static void test()
     {
         testTokenizer();
-        testOutput();
+        testCompiler();
+        //testOutput();
     }
     
     private static void testOutput()
@@ -72,6 +74,38 @@ public class Test
         System.out.println(String.format("%d / %d tokenizer tests succeeded", done, tests));
     }
     
+    private static void testCompiler()
+    {
+        done = 0;
+        tests = 0; 
+        final Compiler c = new Compiler(LOGGER);
+        forEachFile(new File("./test"), ".cout", (inFile, checkFile) -> 
+        {
+            tests++;
+            try
+            {
+                try(FileInputStream in = new FileInputStream(inFile))
+                {
+                    Tokenizer tokenizer = new Tokenizer();
+                    LOGGER.reset();
+                    c.compile(tokenizer.tokenize(in));
+                    if(LOGGER.check(checkFile))
+                    {
+                        done++;
+                    }
+                }
+            }
+            catch(Exception ex)
+            {
+                System.out.println("_________________________________________");
+                System.out.println(inFile + " failed:");
+                System.out.println(ex.getMessage());
+                ex.printStackTrace();
+            }
+        });
+        System.out.println(String.format("%d / %d compiler tests succeeded", done, tests));
+    }
+    
     private static void forEachFile(File f, String ending, BiConsumer<File, File> bc)
     {
         if(f.isFile())

+ 1 - 0
src/me/hammerle/snuviscript/test/TestLogger.java

@@ -22,6 +22,7 @@ public class TestLogger implements ISnuviLogger
         {
             System.out.println(ex);
             System.out.println(ex.getMessage());
+            System.out.println("error line " + line);
         }
     }
     

+ 32 - 15
src/me/hammerle/snuviscript/token/TokenType.java

@@ -2,27 +2,44 @@ package me.hammerle.snuviscript.token;
 
 public enum TokenType
 {
-    NUMBER, STRING, LITERAL, LABEL, TRUE, FALSE, NULL,
+    NUMBER("number"), STRING("string"), LITERAL("literal"), LABEL("label"), 
+    TRUE("true"), FALSE("false"), NULL("null"),
     
-    OPEN_BRACKET, CLOSE_BRACKET, 
-    OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, 
-    OPEN_CURVED_BRACKET, CLOSE_CURVED_BRACKET, 
+    OPEN_BRACKET("("), CLOSE_BRACKET(")"), 
+    OPEN_SQUARE_BRACKET("["), CLOSE_SQUARE_BRACKET("]"), 
+    OPEN_CURVED_BRACKET("{"), CLOSE_CURVED_BRACKET("}"), 
     
-    SEMICOLON, COMMA, 
+    SEMICOLON(";"), COMMA(","), 
     
-    INC, DEC, 
+    INC("++"), DEC("--"), 
     
-    INVERT, BIT_INVERT, 
+    INVERT("!"), BIT_INVERT("~"), 
     
-    MUL, DIV, MOD, ADD, SUB, 
-    ADD_SET, SUB_SET, MUL_SET, DIV_SET, MOD_SET, 
+    MUL("*"), DIV("/"), MOD("%"), ADD("+"), SUB("-"), 
+    ADD_SET("+="), SUB_SET("-="), MUL_SET("*="), DIV_SET("/="), MOD_SET("%="), 
     
-    LEFT_SHIFT, RIGHT_SHIFT, 
-    LEFT_SHIFT_SET, RIGHT_SHIFT_SET, BIT_AND_SET, BIT_XOR_SET, BIT_OR_SET,
+    LEFT_SHIFT("<<"), RIGHT_SHIFT(">>"), 
+    LEFT_SHIFT_SET("<<="), RIGHT_SHIFT_SET(">>="), BIT_AND_SET("&="), BIT_XOR_SET("^="), BIT_OR_SET("|="),
     
-    LESS, LESS_EQUAL, GREATER, GREATER_EQUAL, EQUAL, NOT_EQUAL, 
-    BIT_AND, BIT_XOR, BIT_OR, 
-    AND, OR, SET,
+    LESS("<"), LESS_EQUAL("<="), GREATER(">"), GREATER_EQUAL(">="), EQUAL("=="), NOT_EQUAL("!="), 
+    BIT_AND("&"), BIT_XOR("^"), BIT_OR("|"), 
+    AND("&&"), OR("||"), SET("="),
     
-    IF, ELSE, ELSEIF, WHILE, TRY, CATCH, FOR, FUNCTION, BREAK, CONTINUE, RETURN
+    IF("if"), ELSE("else"), ELSEIF("else if"), WHILE("while"), TRY("try"), 
+    CATCH("catch"), FOR("for"), FUNCTION("function"), BREAK("break"), 
+    CONTINUE("continue"), RETURN("return"),
+    
+    EOF("end of file");
+    
+    private final String name;
+    
+    private TokenType(String name)
+    {
+        this.name = name;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
 }

+ 1 - 0
src/me/hammerle/snuviscript/token/Tokenizer.java

@@ -78,6 +78,7 @@ public class Tokenizer
         {
             handleChar(c);
         }
+        add(EOF);
         return tokens.toArray(new Token[tokens.size()]);
     }
     

+ 0 - 0
test/calc/base.cout


+ 1 - 0
test/calc/base.tout

@@ -92,3 +92,4 @@
 (15, NUMBER, 2.0)
 (15, CLOSE_BRACKET)
 (15, SEMICOLON)
+(16, EOF)

+ 0 - 0
test/calc/mixed.cout


+ 1 - 0
test/calc/mixed.tout

@@ -94,3 +94,4 @@
 (8, NUMBER, 4.0)
 (8, CLOSE_BRACKET)
 (8, SEMICOLON)
+(9, EOF)

+ 6 - 0
test/comments/comment0.cout

@@ -0,0 +1,6 @@
+push "a"
+use print(1)
+push "c"
+use print(1)
+push "d"
+use print(1)

+ 1 - 0
test/comments/comment0.tout

@@ -13,3 +13,4 @@
 (4, STRING, "d")
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 4 - 0
test/comments/comment1.cout

@@ -0,0 +1,4 @@
+push "a"
+use print(1)
+push "d"
+use print(1)

+ 1 - 0
test/comments/comment1.tout

@@ -8,3 +8,4 @@
 (4, STRING, "d")
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 6 - 0
test/comments/comment2.cout

@@ -0,0 +1,6 @@
+push "a"
+use print(1)
+push "c"
+use print(1)
+push "e"
+use print(1)

+ 1 - 0
test/comments/comment2.tout

@@ -13,3 +13,4 @@
 (4, STRING, "e")
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 6 - 0
test/comments/comment3.cout

@@ -0,0 +1,6 @@
+push "a"
+use print(1)
+push "d"
+use print(1)
+push "e"
+use print(1)

+ 1 - 0
test/comments/comment3.tout

@@ -13,3 +13,4 @@
 (4, STRING, "e")
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 0 - 0
test/conditions/conditions0.cout


+ 1 - 0
test/conditions/conditions0.tout

@@ -8,3 +8,4 @@
 (2, FALSE)
 (2, CLOSE_BRACKET)
 (2, SEMICOLON)
+(3, EOF)

+ 0 - 0
test/conditions/conditions1.cout


+ 1 - 0
test/conditions/conditions1.tout

@@ -26,3 +26,4 @@
 (4, FALSE)
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 0 - 0
test/conditions/conditions2.cout


+ 1 - 0
test/conditions/conditions2.tout

@@ -26,3 +26,4 @@
 (4, FALSE)
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 0 - 0
test/conditions/conditions3.cout


+ 1 - 0
test/conditions/conditions3.tout

@@ -31,3 +31,4 @@
 (3, FALSE)
 (3, CLOSE_BRACKET)
 (3, SEMICOLON)
+(4, EOF)

+ 0 - 0
test/conditions/conditions4.cout


+ 1 - 0
test/conditions/conditions4.tout

@@ -32,3 +32,4 @@
 (7, LITERAL, "a")
 (7, CLOSE_BRACKET)
 (7, SEMICOLON)
+(8, EOF)

+ 0 - 0
test/conditions/conditions5.cout


+ 1 - 0
test/conditions/conditions5.tout

@@ -32,3 +32,4 @@
 (7, LITERAL, "a")
 (7, CLOSE_BRACKET)
 (7, SEMICOLON)
+(8, EOF)

+ 0 - 0
test/conditions/conditions6.cout


+ 1 - 0
test/conditions/conditions6.tout

@@ -103,3 +103,4 @@
 (17, NUMBER, 5.0)
 (17, CLOSE_BRACKET)
 (17, SEMICOLON)
+(18, EOF)

+ 0 - 0
test/conditions/conditions7.cout


+ 1 - 0
test/conditions/conditions7.tout

@@ -20,3 +20,4 @@
 (2, NUMBER, 4.0)
 (2, CLOSE_BRACKET)
 (2, SEMICOLON)
+(3, EOF)

+ 0 - 0
test/conditions/conditions8.cout


+ 1 - 0
test/conditions/conditions8.tout

@@ -56,3 +56,4 @@
 (4, NUMBER, 2.0)
 (4, CLOSE_BRACKET)
 (4, SEMICOLON)
+(5, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue0

@@ -1,4 +1,4 @@
-for(i, 6, 9)
+for(i = 6; i <= 9; i++)
 {
     print(i);
 }

+ 0 - 0
test/for_break_continue/for_break_continue0.cout


+ 8 - 2
test/for_break_continue/for_break_continue0.tout

@@ -1,10 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 6.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 9.0)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, INC)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
 (3, LITERAL, "print")
@@ -13,3 +18,4 @@
 (3, CLOSE_BRACKET)
 (3, SEMICOLON)
 (4, CLOSE_CURVED_BRACKET)
+(5, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue1

@@ -1,4 +1,4 @@
-for(i, 6, 9, 2)
+for(i = 6; i <= 9; i += 2)
 {
     print(i);
 }

+ 0 - 0
test/for_break_continue/for_break_continue1.cout


+ 8 - 3
test/for_break_continue/for_break_continue1.tout

@@ -1,11 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 6.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 9.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, ADD_SET)
 (1, NUMBER, 2.0)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
@@ -15,3 +19,4 @@
 (3, CLOSE_BRACKET)
 (3, SEMICOLON)
 (4, CLOSE_CURVED_BRACKET)
+(5, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue2

@@ -1,4 +1,4 @@
-for(i, 5, 15, 3)
+for(i = 5; i <= 15; i += 3)
 {
     print(i);
 }

+ 0 - 0
test/for_break_continue/for_break_continue2.cout


+ 8 - 3
test/for_break_continue/for_break_continue2.tout

@@ -1,11 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 15.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, ADD_SET)
 (1, NUMBER, 3.0)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
@@ -15,3 +19,4 @@
 (3, CLOSE_BRACKET)
 (3, SEMICOLON)
 (4, CLOSE_CURVED_BRACKET)
+(5, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue3

@@ -1,4 +1,4 @@
-for(i, 5, 15, 3)
+for(i = 5; i <= 15; i += 3)
 {
     print(i);
     break;

+ 0 - 0
test/for_break_continue/for_break_continue3.cout


+ 8 - 3
test/for_break_continue/for_break_continue3.tout

@@ -1,11 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 15.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, ADD_SET)
 (1, NUMBER, 3.0)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
@@ -17,3 +21,4 @@
 (4, BREAK)
 (4, SEMICOLON)
 (5, CLOSE_CURVED_BRACKET)
+(6, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue4

@@ -1,4 +1,4 @@
-for(i, 5, 15, 3)
+for(i = 5; i <= 15; i += 3)
 {
     print(i);
     if(i == 9)

+ 0 - 0
test/for_break_continue/for_break_continue4.cout


+ 8 - 3
test/for_break_continue/for_break_continue4.tout

@@ -1,11 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 15.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, ADD_SET)
 (1, NUMBER, 3.0)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
@@ -25,3 +29,4 @@
 (6, SEMICOLON)
 (7, CLOSE_CURVED_BRACKET)
 (8, CLOSE_CURVED_BRACKET)
+(9, EOF)

+ 1 - 1
test/for_break_continue/for_break_continue5

@@ -1,4 +1,4 @@
-for(i, 5, 15, 3)
+for(i = 5; i <= 15; i += 3)
 {
     print(i);
     if(i == 11)

+ 0 - 0
test/for_break_continue/for_break_continue5.cout


+ 8 - 3
test/for_break_continue/for_break_continue5.tout

@@ -1,11 +1,15 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 15.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, ADD_SET)
 (1, NUMBER, 3.0)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
@@ -25,3 +29,4 @@
 (6, SEMICOLON)
 (7, CLOSE_CURVED_BRACKET)
 (8, CLOSE_CURVED_BRACKET)
+(9, EOF)

+ 2 - 2
test/for_break_continue/for_break_continue6

@@ -1,6 +1,6 @@
-for(i, 5, 7)
+for(i = 5; i <= 7; i++)
 {
-    for(j, 0, 5)
+    for(j = 0; j <= 5; j++)
     {
         print(j);
     }

+ 0 - 0
test/for_break_continue/for_break_continue6.cout


+ 15 - 4
test/for_break_continue/for_break_continue6.tout

@@ -1,19 +1,29 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 7.0)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, INC)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
 (3, FOR)
 (3, OPEN_BRACKET)
 (3, LITERAL, "j")
-(3, COMMA)
+(3, SET)
 (3, NUMBER, 0.0)
-(3, COMMA)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, LESS_EQUAL)
 (3, NUMBER, 5.0)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, INC)
 (3, CLOSE_BRACKET)
 (4, OPEN_CURVED_BRACKET)
 (5, LITERAL, "print")
@@ -28,3 +38,4 @@
 (7, CLOSE_BRACKET)
 (7, SEMICOLON)
 (8, CLOSE_CURVED_BRACKET)
+(9, EOF)

+ 2 - 2
test/for_break_continue/for_break_continue7

@@ -1,6 +1,6 @@
-for(i, 5, 7)
+for(i = 5; i <= 7; i++)
 {
-    for(j, 0, 5)
+    for(j = 0; j <= 5; j++)
     {
         break;
         print(j);

+ 0 - 0
test/for_break_continue/for_break_continue7.cout


+ 15 - 4
test/for_break_continue/for_break_continue7.tout

@@ -1,19 +1,29 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 7.0)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, INC)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
 (3, FOR)
 (3, OPEN_BRACKET)
 (3, LITERAL, "j")
-(3, COMMA)
+(3, SET)
 (3, NUMBER, 0.0)
-(3, COMMA)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, LESS_EQUAL)
 (3, NUMBER, 5.0)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, INC)
 (3, CLOSE_BRACKET)
 (4, OPEN_CURVED_BRACKET)
 (5, BREAK)
@@ -30,3 +40,4 @@
 (8, CLOSE_BRACKET)
 (8, SEMICOLON)
 (9, CLOSE_CURVED_BRACKET)
+(10, EOF)

+ 2 - 2
test/for_break_continue/for_break_continue8

@@ -1,6 +1,6 @@
-for(i, 5, 7)
+for(i = 5; i <= 7; i++)
 {
-    for(j, 0, 5)
+    for(j = 0; j <= 5; j++)
     {
         if(i == 6)
         {

+ 0 - 0
test/for_break_continue/for_break_continue8.cout


+ 15 - 4
test/for_break_continue/for_break_continue8.tout

@@ -1,19 +1,29 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "i")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 5.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, LESS_EQUAL)
 (1, NUMBER, 7.0)
+(1, SEMICOLON)
+(1, LITERAL, "i")
+(1, INC)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
 (3, FOR)
 (3, OPEN_BRACKET)
 (3, LITERAL, "j")
-(3, COMMA)
+(3, SET)
 (3, NUMBER, 0.0)
-(3, COMMA)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, LESS_EQUAL)
 (3, NUMBER, 5.0)
+(3, SEMICOLON)
+(3, LITERAL, "j")
+(3, INC)
 (3, CLOSE_BRACKET)
 (4, OPEN_CURVED_BRACKET)
 (5, IF)
@@ -38,3 +48,4 @@
 (11, CLOSE_BRACKET)
 (11, SEMICOLON)
 (12, CLOSE_CURVED_BRACKET)
+(13, EOF)

+ 3 - 3
test/for_break_continue/for_break_continue9

@@ -1,8 +1,8 @@
-for(x, 0, 2)
+for(x = 0; x <= 2; x++) 
 {
-    for(y, 0, 2)
+    for(y = 0; y <= 2; y++)
     {
-        for(z, 0, 2)
+        for(z = 0; z <= 2; z++)
         {
             print(x, " ", y, " ", z);
         }

+ 0 - 0
test/for_break_continue/for_break_continue9.cout


+ 22 - 6
test/for_break_continue/for_break_continue9.tout

@@ -1,28 +1,43 @@
 (1, FOR)
 (1, OPEN_BRACKET)
 (1, LITERAL, "x")
-(1, COMMA)
+(1, SET)
 (1, NUMBER, 0.0)
-(1, COMMA)
+(1, SEMICOLON)
+(1, LITERAL, "x")
+(1, LESS_EQUAL)
 (1, NUMBER, 2.0)
+(1, SEMICOLON)
+(1, LITERAL, "x")
+(1, INC)
 (1, CLOSE_BRACKET)
 (2, OPEN_CURVED_BRACKET)
 (3, FOR)
 (3, OPEN_BRACKET)
 (3, LITERAL, "y")
-(3, COMMA)
+(3, SET)
 (3, NUMBER, 0.0)
-(3, COMMA)
+(3, SEMICOLON)
+(3, LITERAL, "y")
+(3, LESS_EQUAL)
 (3, NUMBER, 2.0)
+(3, SEMICOLON)
+(3, LITERAL, "y")
+(3, INC)
 (3, CLOSE_BRACKET)
 (4, OPEN_CURVED_BRACKET)
 (5, FOR)
 (5, OPEN_BRACKET)
 (5, LITERAL, "z")
-(5, COMMA)
+(5, SET)
 (5, NUMBER, 0.0)
-(5, COMMA)
+(5, SEMICOLON)
+(5, LITERAL, "z")
+(5, LESS_EQUAL)
 (5, NUMBER, 2.0)
+(5, SEMICOLON)
+(5, LITERAL, "z")
+(5, INC)
 (5, CLOSE_BRACKET)
 (6, OPEN_CURVED_BRACKET)
 (7, LITERAL, "print")
@@ -41,3 +56,4 @@
 (8, CLOSE_CURVED_BRACKET)
 (9, CLOSE_CURVED_BRACKET)
 (10, CLOSE_CURVED_BRACKET)
+(11, EOF)

+ 0 - 0
test/functions/functions0.cout


+ 1 - 0
test/functions/functions0.tout

@@ -19,3 +19,4 @@
 (8, STRING, "c")
 (8, CLOSE_BRACKET)
 (8, SEMICOLON)
+(9, EOF)

+ 0 - 0
test/functions/functions1.cout


+ 1 - 0
test/functions/functions1.tout

@@ -20,3 +20,4 @@
 (8, STRING, "c")
 (8, CLOSE_BRACKET)
 (8, SEMICOLON)
+(9, EOF)

+ 0 - 0
test/functions/functions10.cout


+ 1 - 0
test/functions/functions10.tout

@@ -32,3 +32,4 @@
 (11, STRING, "d")
 (11, CLOSE_BRACKET)
 (11, SEMICOLON)
+(12, EOF)

+ 0 - 0
test/functions/functions11.cout


+ 1 - 0
test/functions/functions11.tout

@@ -34,3 +34,4 @@
 (11, STRING, "e")
 (11, CLOSE_BRACKET)
 (11, SEMICOLON)
+(12, EOF)

+ 0 - 0
test/functions/functions12.cout


+ 1 - 0
test/functions/functions12.tout

@@ -42,3 +42,4 @@
 (17, STRING, "e")
 (17, CLOSE_BRACKET)
 (17, SEMICOLON)
+(18, EOF)

+ 0 - 0
test/functions/functions13.cout


+ 1 - 0
test/functions/functions13.tout

@@ -55,3 +55,4 @@
 (20, STRING, "e")
 (20, CLOSE_BRACKET)
 (20, SEMICOLON)
+(21, EOF)

+ 0 - 0
test/functions/functions14.cout


+ 1 - 0
test/functions/functions14.tout

@@ -27,3 +27,4 @@
 (11, CLOSE_BRACKET)
 (11, SEMICOLON)
 (13, LABEL, "@end")
+(14, EOF)

+ 0 - 0
test/functions/functions2.cout


+ 1 - 0
test/functions/functions2.tout

@@ -25,3 +25,4 @@
 (9, STRING, "c")
 (9, CLOSE_BRACKET)
 (9, SEMICOLON)
+(10, EOF)

+ 0 - 0
test/functions/functions3.cout


Some files were not shown because too many files changed in this diff