瀏覽代碼

clean up, exception bifunction, new commands

Kajetan Johannes Hammerle 5 年之前
父節點
當前提交
d16b18b6d3

+ 1 - 34
src/me/hammerle/snuviscript/SnuviScript.java

@@ -1,7 +1,6 @@
 package me.hammerle.snuviscript;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -9,9 +8,6 @@ import me.hammerle.snuviscript.code.ISnuviLogger;
 import me.hammerle.snuviscript.code.ISnuviScheduler;
 import me.hammerle.snuviscript.code.Script;
 import me.hammerle.snuviscript.code.SnuviParser;
-import me.hammerle.snuviscript.code.SnuviUtils;
-import me.hammerle.snuviscript.exceptions.PreScriptException;
-import me.hammerle.snuviscript.token.Tokenizer;
 
 public class SnuviScript
 {
@@ -66,35 +62,6 @@ public class SnuviScript
         };
         
         SnuviParser parser = new SnuviParser(logger, scheduler);
-        parser.startScript(true, ".sbasic", "./test");  
-        
-        /*try
-        {
-            List<String> list = SnuviUtils.readCode(".sbasic", "./test");           
-            Tokenizer t = new Tokenizer(String.join("\n", list));
-            t.tokenize();
-        }
-        catch(PreScriptException ex)
-        {
-            System.out.println(ex);
-            System.out.println(ex.getStartLine() + "   " + ex.getEndLine());
-            ex.printStackTrace();
-        }*/
-        
-        //parser.callEvent("testevent", null, null);      
+        parser.startScript(true, ".sbasic", "./test");    
     }  
-    
-    /*public static Location getSpawn()
-    {
-        // Player changeDimension, WorldServer, MinecraftServer
-        return KajetansMod.conf.getLocation("spawn");
-    }
-
-    public static void setSpawn(World w, Vec3d v, float yaw, float pitch)
-    {          
-        SimpleConfig conf = KajetansMod.conf;
-        conf.setLocation("spawn", new Location(w, v, yaw, pitch));
-        conf.save();
-        w.setSpawnPoint(new BlockPos(v.x, v.y, v.z));
-    }*/
 }

+ 7 - 7
src/me/hammerle/snuviscript/array/DynamicArray.java

@@ -23,7 +23,7 @@ public class DynamicArray extends InputProvider
         return Array.getLength(var.getArray(sc));
     }
     
-    public void init(Script sc)
+    public void init(Script sc) throws Exception
     {
         int[] dims = new int[input.length];
         for(int i = 0; i < dims.length; i++)
@@ -34,7 +34,7 @@ public class DynamicArray extends InputProvider
     }
     
     @Override
-    public Object getArray(Script sc)
+    public Object getArray(Script sc) throws Exception
     {
         Object ob = var.getArray(sc);
         for(InputProvider in : input) 
@@ -44,7 +44,7 @@ public class DynamicArray extends InputProvider
         return ob;
     }
     
-    public Object getLastArray(Script sc)
+    public Object getLastArray(Script sc) throws Exception
     {
         Object ob = var.getArray(sc);
         int end = input.length - 1;
@@ -56,25 +56,25 @@ public class DynamicArray extends InputProvider
     }
     
     @Override
-    public void set(Script sc, Object o) 
+    public void set(Script sc, Object o) throws Exception
     {
         Array.set(getLastArray(sc), input[input.length - 1].getInt(sc), o);
     }
 
     @Override
-    public Object get(Script sc) 
+    public Object get(Script sc) throws Exception
     {
         return Array.get(getLastArray(sc), input[input.length - 1].getInt(sc));
     }
     
     @Override
-    public double getDouble(Script sc) 
+    public double getDouble(Script sc) throws Exception
     {
         return (double) get(sc);
     }
     
     @Override
-    public String getString(Script sc) 
+    public String getString(Script sc) throws Exception
     {
         Object last = getLastArray(sc);
         int index = input[input.length - 1].getInt(sc);

+ 3 - 5
src/me/hammerle/snuviscript/code/BasicFunction.java

@@ -1,13 +1,11 @@
 package me.hammerle.snuviscript.code;
 
-import java.util.function.BiFunction;
-
 public final class BasicFunction 
 {
     private final String name;
-    private final BiFunction<Script, InputProvider[], Object> f;
+    private final ExceptionBiFunction<Script, InputProvider[], Object> f;
     
-    public BasicFunction(String name, BiFunction<Script, InputProvider[], Object> f)
+    public BasicFunction(String name, ExceptionBiFunction<Script, InputProvider[], Object> f)
     {
         this.name = name;
         this.f = f;
@@ -18,7 +16,7 @@ public final class BasicFunction
         return name;
     }
     
-    public Object execute(Script sc, InputProvider[] input)
+    public Object execute(Script sc, InputProvider[] input) throws Exception
     {
         sc.currentCommand = name;
         Object o = f.apply(sc, input);

+ 7 - 0
src/me/hammerle/snuviscript/code/ExceptionBiFunction.java

@@ -0,0 +1,7 @@
+package me.hammerle.snuviscript.code;
+
+@FunctionalInterface
+public interface ExceptionBiFunction<T, U, R>
+{
+    public R apply(T t, U u) throws Exception;
+}

+ 6 - 6
src/me/hammerle/snuviscript/code/Function.java

@@ -39,13 +39,13 @@ public class Function extends InputProvider
     }
 
     @Override
-    public Object get(Script sc) 
+    public Object get(Script sc) throws Exception
     {
         return function.execute(sc, input);
     }
     
     @Override
-    public Object getArray(Script sc)
+    public Object getArray(Script sc) throws Exception
     {
         Object o = function.execute(sc, input);
         if(o instanceof ArrayVariable || o instanceof LocalArrayVariable)
@@ -56,25 +56,25 @@ public class Function extends InputProvider
     }
     
     @Override
-    public double getDouble(Script sc) 
+    public double getDouble(Script sc) throws Exception
     {
         return (double) function.execute(sc, input);
     }
     
     @Override
-    public String getString(Script sc)
+    public String getString(Script sc) throws Exception
     {
         return String.valueOf(function.execute(sc, input));
     }
     
     @Override
-    public boolean getBoolean(Script sc)
+    public boolean getBoolean(Script sc) throws Exception
     {
         return (Boolean) function.execute(sc, input);
     }
     
     @Override
-    public Variable getVariable(Script sc)
+    public Variable getVariable(Script sc) throws Exception
     {
         return (Variable) function.execute(sc, input);
     }

+ 11 - 39
src/me/hammerle/snuviscript/code/FunctionLoader.java

@@ -1,7 +1,6 @@
 package me.hammerle.snuviscript.code;
 
 import java.io.File;
-import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.lang.reflect.Array;
 import java.nio.file.Files;
@@ -19,12 +18,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Objects;
 import java.util.Set;
-import java.util.function.BiFunction;
 import java.util.stream.Collectors;
 import me.hammerle.snuviscript.array.DynamicArray;
 import me.hammerle.snuviscript.config.SnuviConfig;
-import me.hammerle.snuviscript.exceptions.AssertionException;
-import me.hammerle.snuviscript.exceptions.FileIOException;
 import me.hammerle.snuviscript.variable.ArrayVariable;
 import me.hammerle.snuviscript.variable.Variable;
 
@@ -32,12 +28,12 @@ public class FunctionLoader
 {
     private static final HashMap<String, BasicFunction> FUNCTIONS = new HashMap<>();
     
-    protected static void registerFunction(String name, String fname, BiFunction<Script, InputProvider[], Object> f)
+    protected static void registerFunction(String name, String fname, ExceptionBiFunction<Script, InputProvider[], Object> f)
     {
         FUNCTIONS.put(name, new BasicFunction(fname, f));
     }
     
-    protected static void registerFunction(String name, BiFunction<Script, InputProvider[], Object> f)
+    protected static void registerFunction(String name, ExceptionBiFunction<Script, InputProvider[], Object> f)
     {
         registerFunction(name, name, f);
     }
@@ -461,44 +457,20 @@ public class FunctionLoader
         registerFunction("file.delete", (sc, in) ->  ((File) in[0].get(sc)).delete());
         registerFunction("file.getname", (sc, in) -> ((File) in[0].get(sc)).getName());
         registerFunction("file.getlist", (sc, in) -> Arrays.asList(((File) in[0].get(sc)).listFiles()));
-        registerFunction("file.read", (sc, in) ->         
-        {
-            try
-            {
-                return Files.readAllLines(((File) in[0].get(sc)).toPath());
-            }
-            catch(IOException ex)
-            {
-                throw new FileIOException(ex.getMessage());
-            }
-        });
+        registerFunction("file.read", (sc, in) -> Files.readAllLines(((File) in[0].get(sc)).toPath()));
         registerFunction("file.write", (sc, in) ->         
         {
-            try
+            File f = (File) in[0].get(sc);
+            if(f.getParentFile() != null)
             {
-                File f = (File) in[0].get(sc);
-                if(f.getParentFile() != null)
-                {
-                    f.getParentFile().mkdirs();
-                }
-                if(!f.exists())
-                {
-                    try
-                    {
-                        f.createNewFile();
-                    }
-                    catch(IOException ex)
-                    {
-                        throw new FileIOException(ex.getMessage());
-                    }
-                }
-                Files.write(Paths.get(f.toURI()), ((List<Object>) in[1].get(sc))
-                        .stream().map(o -> String.valueOf(o)).collect(Collectors.toList()), StandardCharsets.UTF_8);
+                f.getParentFile().mkdirs();
             }
-            catch(UnsupportedOperationException | SecurityException | IOException ex)
+            if(!f.exists())
             {
-                throw new FileIOException(ex.getMessage());
+                f.createNewFile();
             }
+            Files.write(Paths.get(f.toURI()), ((List<Object>) in[1].get(sc))
+                    .stream().map(o -> String.valueOf(o)).collect(Collectors.toList()), StandardCharsets.UTF_8);
             return Void.TYPE;
         });
         
@@ -926,7 +898,7 @@ public class FunctionLoader
         {
             if(!in[0].getBoolean(sc))
             {
-                throw new AssertionException("assertion failed");
+                throw new IllegalArgumentException("assertion failed");
             }
             return Void.TYPE;
         });

+ 12 - 12
src/me/hammerle/snuviscript/code/InputProvider.java

@@ -4,62 +4,62 @@ import me.hammerle.snuviscript.variable.Variable;
 
 public abstract class InputProvider 
 {
-    public Object get(Script sc)
+    public Object get(Script sc) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public byte getByte(Script sc)
+    public byte getByte(Script sc) throws Exception
     {
         return (byte) getDouble(sc);
     }
     
-    public short getShort(Script sc)
+    public short getShort(Script sc) throws Exception
     {
         return (short) getDouble(sc);
     }
     
-    public int getInt(Script sc)
+    public int getInt(Script sc) throws Exception
     {
         return (int) getDouble(sc);
     }
     
-    public long getLong(Script sc)
+    public long getLong(Script sc) throws Exception
     {
         return (long) getDouble(sc);
     }
     
-    public float getFloat(Script sc)
+    public float getFloat(Script sc) throws Exception
     {
         return (float) getDouble(sc);
     }
     
-    public double getDouble(Script sc)
+    public double getDouble(Script sc) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public String getString(Script sc)
+    public String getString(Script sc) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public boolean getBoolean(Script sc)
+    public boolean getBoolean(Script sc) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public Variable getVariable(Script sc)
+    public Variable getVariable(Script sc) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public void set(Script sc, Object o)
+    public void set(Script sc, Object o) throws Exception
     {
         throw new ClassCastException();
     }
     
-    public Object getArray(Script sc)
+    public Object getArray(Script sc) throws Exception
     {
         return null;
     }

+ 1 - 1
src/me/hammerle/snuviscript/code/Instruction.java

@@ -54,7 +54,7 @@ public class Instruction
         return sb.toString();
     }
     
-    public void execute(Script sc)
+    public void execute(Script sc) throws Exception
     {
         input.get(sc);
     }

+ 11 - 7
src/me/hammerle/snuviscript/code/Script.java

@@ -1,7 +1,5 @@
 package me.hammerle.snuviscript.code;
 
-import java.io.Closeable;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -115,8 +113,9 @@ public final class Script
             try
             {
                 //System.out.println("EXECUTE: " + code[currentLine]);
+                //System.out.println("LINE 1: " + currentLine);
                 code[currentLine].execute(this);
-                //System.out.println("EXECUTE: " + currentLine);
+                //System.out.println("LINE 2: " + currentLine);
                 currentLine++;
             }
             catch(Exception ex)
@@ -132,7 +131,8 @@ public final class Script
                     setVar("error", ex.getClass().getSimpleName());
                     continue;
                 }
-                logger.print(ex.getLocalizedMessage(), ex, currentCommand, name, this, code[currentLine].getRealLine() + 1);
+                int line = (currentLine < length) ? code[currentLine].getRealLine() + 1 : -1;
+                logger.print(ex.getLocalizedMessage(), ex, currentCommand, name, this, line);
                 //ex.printStackTrace();
                 return returnValue;
             }
@@ -294,15 +294,14 @@ public final class Script
         }
         closeables.forEach(c -> 
         {
+            logger.print("prepared statement not closed", null, null, name, this, -1);
             try
             {
                 c.close();
             }
             catch(Exception ex)
             {
-                System.out.println("Cannot close closeable in script '" + name + "'");
-                System.out.println(ex);
-                System.out.println(ex.getMessage());
+                logger.print("cannot close closeable in script", ex, null, name, this, -1);
             }
         });
     }
@@ -311,4 +310,9 @@ public final class Script
     {
         closeables.add(closeable);
     }
+    
+    public void removeCloseable(AutoCloseable closeable)
+    {
+        closeables.remove(closeable);
+    }
 }

+ 3 - 3
src/me/hammerle/snuviscript/code/SignInverter.java

@@ -10,19 +10,19 @@ public class SignInverter extends InputProvider
     }
     
     @Override
-    public Object get(Script sc) 
+    public Object get(Script sc) throws Exception
     {
         return -input.getDouble(sc);
     }
     
     @Override
-    public double getDouble(Script sc) 
+    public double getDouble(Script sc) throws Exception
     {
         return -input.getDouble(sc);
     }
     
     @Override
-    public String getString(Script sc) 
+    public String getString(Script sc) throws Exception
     {
         return String.valueOf(get(sc));
     }

+ 1 - 2
src/me/hammerle/snuviscript/code/SnuviParser.java

@@ -4,7 +4,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Predicate;
 import me.hammerle.snuviscript.exceptions.PreScriptException;
@@ -42,7 +41,7 @@ public class SnuviParser
     // function registry
     // -----------------------------------------------------------------------------------
 
-    public void registerFunction(String s, BiFunction<Script, InputProvider[], Object> f)
+    public void registerFunction(String s, ExceptionBiFunction<Script, InputProvider[], Object> f)
     {
         FunctionLoader.registerFunction(s, f);
     }

+ 2 - 2
src/me/hammerle/snuviscript/code/SnuviUtils.java

@@ -230,7 +230,7 @@ public class SnuviUtils
     // connectors
     // -------------------------------------------------------------------------
     
-    public static String connect(Script sc, InputProvider[] c, int skip)
+    public static String connect(Script sc, InputProvider[] c, int skip) throws Exception
     {
         StringBuilder sb = new StringBuilder();
         for(int i = skip; i < c.length; i++)
@@ -240,7 +240,7 @@ public class SnuviUtils
         return sb.toString();
     }
     
-    public static String connect(Script sc, InputProvider[] c, String s, int skip)
+    public static String connect(Script sc, InputProvider[] c, String s, int skip) throws Exception
     {
         StringBuilder sb = new StringBuilder();
         if(skip < c.length)

+ 0 - 5
src/me/hammerle/snuviscript/code/Syntax.java

@@ -39,11 +39,6 @@ public enum Syntax
     BIT_AND_SET("&=", 15),
     BIT_XOR_SET("^=", 15),
     BIT_OR_SET("|=", 15);
-    
-    /*
-        LEFT_SHIFT_SET("<<=", 15),
-        RIGHT_SHIFT_SET(">>=", 15),
-    */
 
     public static Syntax getSyntax(String s)
     {   

+ 0 - 9
src/me/hammerle/snuviscript/exceptions/AssertionException.java

@@ -1,9 +0,0 @@
-package me.hammerle.snuviscript.exceptions;
-
-public class AssertionException extends RuntimeException
-{
-    public AssertionException(String s) 
-    {
-        super(s);
-    }
-}

+ 0 - 9
src/me/hammerle/snuviscript/exceptions/FileIOException.java

@@ -1,9 +0,0 @@
-package me.hammerle.snuviscript.exceptions;
-
-public class FileIOException extends RuntimeException
-{
-    public FileIOException(String message)
-    {
-        super(message);
-    }
-}

+ 0 - 186
src/me/hammerle/snuviscript/token/Expression.java

@@ -1,186 +0,0 @@
-package me.hammerle.snuviscript.token;
-
-import java.util.LinkedList;
-
-public abstract class Expression 
-{
-    public static class Grouping extends Expression
-    {
-        private final Expression exp;
-        
-        public Grouping(Expression exp)
-        {
-            this.exp = exp;
-        }
-
-        @Override
-        public String toString()
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append('(');
-            sb.append(exp);
-            sb.append(')');
-            return sb.toString();
-        }
-    }
-    
-    public static abstract class PostFunction extends Expression
-    {
-        private final String name;
-        private final LinkedList<Expression> exp = new LinkedList<>();
-        private final char start;
-        private final char end;
-        
-        public PostFunction(String name, char start, char end)
-        {
-            this.name = name;
-            this.start = start;
-            this.end = end;
-        }
-
-        @Override
-        public String toString()
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append(name);
-            sb.append(start);
-            exp.forEach(e -> 
-            {
-                sb.append(e);
-                sb.append(", ");
-            });
-            if(!exp.isEmpty())
-            {
-                sb.delete(sb.length() - 2, sb.length());
-            }
-            sb.append(end);
-            return sb.toString();
-        }
-        
-        public void addExpression(Expression exp)
-        {
-            this.exp.add(exp);
-        }
-    }
-    
-    public static class Function extends PostFunction
-    {
-        public Function(String name)
-        {
-            super(name, '(', ')');
-        }
-    }
-    
-    public static class Array extends PostFunction
-    {
-        public Array(String name)
-        {
-            super(name, '[', ']');
-        }
-    }
-    
-    public static class Binary extends Expression
-    {
-        private final Expression left;
-        private final Token t;
-        private final Expression right;
-        
-        public Binary(Expression left, Token t, Expression right)
-        {
-            this.left = left;
-            this.t = t;
-            this.right = right;
-        }
-
-        @Override
-        public String toString() 
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append('(');
-            sb.append(left);
-            sb.append(' ');
-            sb.append(t);
-            sb.append(' ');
-            sb.append(right);
-            sb.append(')');
-            return sb.toString();
-        } 
-    }
-    
-    public static class PreUnary extends Expression
-    {
-        private final Token t;
-        private final Expression right;
-        
-        public PreUnary(Token t, Expression right)
-        {
-            this.t = t;
-            this.right = right;
-        }
-        
-        @Override
-        public String toString() 
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append('(');
-            sb.append(t);
-            sb.append(right);
-            sb.append(')');
-            return sb.toString();
-        } 
-    }
-    
-    public static class PostUnary extends Expression
-    {
-        private final Expression left;
-        private final Token t;
-        
-        public PostUnary(Expression left, Token t)
-        {
-            this.left = left;
-            this.t = t;
-        }
-        
-        @Override
-        public String toString() 
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append('(');
-            sb.append(left);
-            sb.append(t);
-            sb.append(')');
-            return sb.toString();
-        } 
-    }
-    
-    public static class Literal extends Expression
-    {
-        private final Object o;
-        
-        public Literal(Object o)
-        {
-            this.o = o;
-        }
-
-        @Override
-        public String toString() 
-        {
-            if(o != null)
-            {
-                if(o.getClass() == String.class)
-                {
-                    StringBuilder sb = new StringBuilder();
-                    sb.append('"');
-                    sb.append(o);
-                    sb.append('"');
-                    return sb.toString();
-                }
-                else
-                {
-                    return o.toString();
-                }
-            }
-            return "null";
-        }  
-    }
-}

+ 0 - 635
src/me/hammerle/snuviscript/token/Parser.java

@@ -1,635 +0,0 @@
-package me.hammerle.snuviscript.token;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Stack;
-import me.hammerle.snuviscript.array.DynamicArray;
-import me.hammerle.snuviscript.code.Function;
-import me.hammerle.snuviscript.code.FunctionLoader;
-import me.hammerle.snuviscript.code.InputProvider;
-import me.hammerle.snuviscript.code.Instruction;
-import me.hammerle.snuviscript.code.JumpData;
-import me.hammerle.snuviscript.code.SignInverter;
-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 static me.hammerle.snuviscript.token.TokenType.*;
-import me.hammerle.snuviscript.variable.ArrayVariable;
-import me.hammerle.snuviscript.variable.Variable;
-
-public class Parser 
-{
-    private final HashMap<String, Variable> vars = new HashMap<>();
-    private final HashMap<String, Integer> labels = new HashMap<>();
-    
-    private boolean tryState = false;
-    private boolean cancel = false;
-    
-    private class JumpWrapper
-    {
-        private final JumpData data;
-        private final String function;
-        
-        public JumpWrapper(JumpData data, String function)
-        {
-            this.data = data;
-            this.function = function;
-        }
-    }
-    
-    private final Stack<JumpWrapper> jumps = new Stack<>();
-    private final Stack<JumpWrapper> loopJumps = new Stack<>();
-    private final LinkedList<JumpData> breakContinueJumps = new LinkedList<>();
-    
-    private final Token[] tokens;
-    private int current = 0;
-    private int layer = 0;
-    
-    private final LinkedList<Instruction> inst = new LinkedList<>();
-    
-    public Parser(LinkedList<Token> tokens)
-    {
-        this.tokens = tokens.toArray(new Token[tokens.size()]);
-        //tokens.forEach(t -> System.out.println(t));
-    }
-    
-    // -------------------------------------------------------------------------
-    // utility
-    // -------------------------------------------------------------------------
-    
-    private boolean match(TokenType... types) 
-    {
-        for(TokenType type : types) 
-        {
-            if(check(type)) 
-            {
-                advance();
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    private boolean check(TokenType tokenType) 
-    {
-        if(current >= tokens.length) 
-        {
-            return false;
-        }
-        return tokens[current].getToken() == tokenType;
-    }
-    
-    private Token advance() 
-    {
-        if(current < tokens.length)
-        {
-            current++;
-        }
-        return previous();
-    }
-
-    private Token previous() 
-    {
-        return tokens[current - 1];
-    }
-    
-    private void consume(TokenType type, String s)
-    {
-        if(tokens[current].getToken() != type)
-        {
-            throw new PreScriptException(s, tokens[current].getLine());
-        }
-        current++;
-    }
-    
-    private void peek(TokenType type, String s)
-    {
-        if(tokens[current].getToken() != type)
-        {
-            throw new PreScriptException(s, tokens[current].getLine());
-        }
-    }
-    
-    // -------------------------------------------------------------------------
-    // parsing precedence layers
-    // http://en.cppreference.com/w/c/language/operator_precedence
-    // -------------------------------------------------------------------------
-    
-    private void addInstruction(int line, String function, InputProvider... in)
-    {
-        inst.add(new Instruction(line, (byte) layer, new Function(FunctionLoader.getFunction(function), in)));
-    }
-    
-    public Instruction[] parseTokens()
-    {
-        while(current < tokens.length && tokens[current].getToken() != END_OF_FILE)
-        {
-            while(match(LABEL))
-            {
-                if(labels.put(previous().getData().toString(), inst.size()) != null)
-                {
-                    throw new PreScriptException("label duplicate", previous().getLine());
-                }
-                match(SEMICOLON);
-            }
-            if(match(END_OF_FILE))
-            {
-                break;
-            }
-            
-            int line = tokens[current].getLine();
-            inst.add(new Instruction(line, (byte) layer, parseExpression()));
-            tryState = false;
-            if(cancel)
-            {
-                cancel = false;
-                continue;
-            }
-            
-            if(match(OPEN_CURVED_BRACKET))
-            {
-                layer++;
-            }
-            else
-            {
-                consume(SEMICOLON, "unexpected token after expression: " + tokens[current]);
-            }
-
-            while(match(CLOSE_CURVED_BRACKET))
-            {
-                layer--;
-                
-                if(jumps.isEmpty())
-                {
-                    throw new PreScriptException("} without a corresponding function and / or {", previous().getLine());
-                }
-                JumpWrapper data = jumps.pop();
-                switch(data.function)
-                {
-                    case "try":
-                    {
-                        peek(CATCH, "try without catch");
-                        data.data.setRelativeJump(inst.size());
-                        tryState = true;
-                        break;
-                    }
-                    case "catch":
-                    {
-                        data.data.setRelativeJump(inst.size());
-                        break;
-                    }
-                    case "else":
-                    case "elseif":
-                    case "if":
-                    {
-                        data.data.setRelativeJump(inst.size() + 1);
-                        addInstruction(previous().getLine(), "endif");
-                        break;
-                    }
-                    case "for":
-                    {
-                        loopJumps.pop();
-                        createBreakContinue(inst.size());
-                        JumpData jump = data.data;
-                        jump.setRelativeJump(inst.size());
-                        addInstruction(previous().getLine(), "next", new JumpData(-jump.getInt(null) - 1));
-                        break;
-                    }
-                    case "while":
-                    {
-                        loopJumps.pop();
-                        createBreakContinue(inst.size());
-
-                        JumpData jump = data.data;
-                        jump.setRelativeJump(inst.size() + 1);
-                        addInstruction(previous().getLine(), "wend", new JumpData(-jump.getInt(null) - 1));
-                        break;
-                    }
-                }
-            }
-        }
-        return inst.toArray(new Instruction[inst.size()]);
-    }
-    
-    private void createBreakContinue(int current)
-    {
-        breakContinueJumps.forEach(jump -> jump.setRelativeJump(current));
-        breakContinueJumps.clear();
-    }
-    
-    private InputProvider binaryFunction(InputProvider left, Object t, InputProvider right)
-    {
-        return new Function(FunctionLoader.getFunction(t.toString()), new InputProvider[] {left, right});
-    }
-    
-    private InputProvider unaryFunction(InputProvider in, Object t)
-    {
-        return new Function(FunctionLoader.getFunction(t.toString()), new InputProvider[] {in});
-    }
-    
-    private InputProvider parseExpression()
-    {
-        return parseAssignment();
-    }
-    
-    // level 14
-    private InputProvider parseAssignment() 
-    {
-        InputProvider expr = parseLogicalOr();
-        while(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 operator = previous();
-            InputProvider right = parseAssignment();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 12
-    private InputProvider parseLogicalOr() 
-    {
-        InputProvider expr = parseLogicalAnd();
-        while(match(OR)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseLogicalAnd();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 11
-    private InputProvider parseLogicalAnd() 
-    {
-        InputProvider expr = parseBitOr();
-        while(match(AND)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseBitOr();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 10
-    private InputProvider parseBitOr() 
-    {
-        InputProvider expr = parseBitXor();
-        while(match(BIT_OR)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseBitXor();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 9
-    private InputProvider parseBitXor() 
-    {
-        InputProvider expr = parseBitAnd();
-        while(match(BIT_XOR)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseBitAnd();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 8
-    private InputProvider parseBitAnd() 
-    {
-        InputProvider expr = parseEquality();
-        while(match(BIT_AND)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseEquality();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 7
-    private InputProvider parseEquality() 
-    {
-        InputProvider expr = parseComparison();
-        while(match(EQUAL, NOT_EQUAL)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseComparison();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 6
-    private InputProvider parseComparison() 
-    {
-        InputProvider expr = parseShifting();
-        while(match(GREATER, GREATER_EQUAL, LESS, LESS_EQUAL)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseShifting();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 5
-    private InputProvider parseShifting() 
-    {
-        InputProvider expr = parseAddition();
-        while(match(LEFT_SHIFT, RIGHT_SHIFT)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseAddition();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 4
-    private InputProvider parseAddition() 
-    {
-        InputProvider expr = parseMultiplication();
-        while(match(SUB, ADD)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseMultiplication();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-
-    // level 3
-    private InputProvider parseMultiplication() 
-    {
-        InputProvider expr = parseUnary();
-        while(match(DIV, MUL, MOD)) 
-        {
-            Token operator = previous();
-            InputProvider right = parseUnary();
-            expr = binaryFunction(expr, operator, right);
-        }
-        return expr;
-    }
-    
-    // level 2
-    private InputProvider parseUnary() 
-    {
-        if(match(INVERT, SUB, BIT_INVERT, INC, DEC)) 
-        {
-            if(previous().getToken() == SUB)
-            {
-                return new SignInverter(parseUnary());
-            }
-            Token operator = previous();
-            InputProvider right = parseUnary();
-            return unaryFunction(right, operator);
-        }
-        return parsePost();
-    }
-    
-    // level 1
-    private InputProvider parsePost() 
-    {
-        InputProvider expr = primary();
-        while(true) 
-        {
-            if(match(INC, DEC))
-            {
-                Token operator = previous();
-                expr = unaryFunction(expr, "p" + operator);
-            }
-            else if(match(OPEN_BRACKET))
-            {
-                expr = new Function(FunctionLoader.getFunction(expr.toString()), parseArguments(CLOSE_BRACKET));     
-            }
-            else if(match(OPEN_SQUARE_BRACKET))
-            {
-                String name = expr.toString();
-                Variable oldVar = vars.get(name);
-                if(oldVar == null)
-                {
-                    oldVar = new ArrayVariable(name);
-                    vars.put(name, oldVar);
-                }
-                return new DynamicArray(oldVar, parseArguments(CLOSE_SQUARE_BRACKET));
-            }
-            else
-            {
-                break;
-            }
-        }
-        return expr;
-    }
-    
-    private InputProvider[] parseArguments(TokenType close)
-    {
-        if(match(close))
-        {
-            return new InputProvider[0];
-        }
-        LinkedList<InputProvider> list = new LinkedList<>();
-        while(true)
-        {
-            list.add(parseExpression());
-            if(match(close))
-            {
-                return list.toArray(new InputProvider[list.size()]);
-            }
-            consume(COMMA, "missing ',' in function");
-        }
-    }
-    
-    private InputProvider primary() 
-    {
-        if(match(FALSE)) 
-        {
-            return ConstantBoolean.FALSE;
-        }
-        else if(match(TRUE)) 
-        {
-            return ConstantBoolean.TRUE;
-        }
-        else if(match(NULL)) 
-        {
-            return ConstantNull.NULL;
-        }
-        else if(match(DOUBLE)) 
-        {
-            return new ConstantDouble((double) previous().getData());
-        }
-        else if(match(TEXT)) 
-        {
-            return new ConstantString((String) previous().getData());
-        }
-        else if(match(LABEL)) 
-        {
-            return new ConstantString(((String) previous().getData()).substring(1));
-        }
-        else if(match(VAR)) 
-        {
-            String name = (String) previous().getData();
-            Variable v = vars.get(name);
-            if(v == null)
-            {
-                v = new Variable(name);
-                vars.put(name, v);
-            }
-            return v;
-        }
-        else if(match(IF, ELSE_IF))
-        {
-            String name = previous().getToken() == IF ? "if" : "elseif";
-            
-            consume(OPEN_BRACKET, "if without (");
-            
-            InputProvider[] input = parseArguments(CLOSE_BRACKET);
-            InputProvider[] realInput = new InputProvider[input.length + 1];
-            System.arraycopy(input, 0, realInput, 0, input.length);
-            
-            JumpData jump = new JumpData(inst.size());
-            realInput[input.length] = jump;
-            jumps.push(new JumpWrapper(jump, name));
-            return new Function(FunctionLoader.getFunction(name), realInput);
-        }
-        else if(match(ELSE))
-        {
-            peek(OPEN_CURVED_BRACKET, "unexpected token after 'else': " + tokens[current]);
-            JumpData jump = new JumpData(inst.size());
-            jumps.push(new JumpWrapper(jump, "else"));
-            return unaryFunction(jump, "else");
-        }
-        else if(match(FOR))
-        {
-            consume(OPEN_BRACKET, "for without (");
-            // expected syntax
-            // for(var, start, end, step)
-            // for(var, start, end)
-            InputProvider[] input = parseArguments(CLOSE_BRACKET);
-            if(input.length != 3 && input.length != 4)
-            {
-                throw new PreScriptException("invalid 'for' syntax", previous().getLine());
-            }
-            InputProvider[] realInput = new InputProvider[5];
-
-            System.arraycopy(input, 0, realInput, 0, input.length);
-
-            if(input.length == 3)
-            {
-                realInput[3] = new ConstantDouble(1.0);
-            }
-
-            JumpData jump = new JumpData(inst.size());
-            realInput[4] = jump;
-            JumpWrapper wrapper = new JumpWrapper(jump, "for");
-            jumps.push(wrapper);
-            loopJumps.push(wrapper);
-            return new Function(FunctionLoader.getFunction("for"), realInput);
-        }
-        else if(match(WHILE))
-        {
-            consume(OPEN_BRACKET, "for without (");
-            // expected syntax
-            // while(condition)
-            InputProvider[] input = parseArguments(CLOSE_BRACKET);
-            if(input.length != 1)
-            {
-                throw new PreScriptException("invalid conditions at 'while'", previous().getLine());
-            }
-            InputProvider[] realInput = new InputProvider[2];
-            realInput[0] = input[0];
-
-            JumpData jump = new JumpData(inst.size());
-            realInput[1] = jump;
-
-            JumpWrapper wrapper = new JumpWrapper(jump, "while");
-            jumps.push(wrapper);
-            loopJumps.push(wrapper);
-
-            return new Function(FunctionLoader.getFunction("while"), realInput);
-        }
-        else if(match(FUNCTION))
-        {
-            cancel = true;
-            int counter = 0;
-            while(current < tokens.length && tokens[current].getToken() != OPEN_CURVED_BRACKET)
-            {
-                current++;
-            }
-            counter++;
-            current++;
-            while(current < tokens.length && counter != 0)
-            {
-                if(tokens[current].getToken() == OPEN_CURVED_BRACKET)
-                {
-                    counter++;
-                }
-                else if(tokens[current].getToken() == CLOSE_CURVED_BRACKET)
-                {
-                    counter--;
-                }
-                current++;
-            }
-            return new Function(FunctionLoader.getFunction("nothing"), new InputProvider[0]);
-        }
-        else if(match(BREAK))
-        {
-            if(loopJumps.isEmpty())
-            {
-                throw new PreScriptException("break without a loop", previous().getLine());
-            }
-            JumpData jump = new JumpData(inst.size() - 1);
-            breakContinueJumps.add(jump);
-            return unaryFunction(jump, "break");
-        }
-        else if(match(CONTINUE))
-        {
-            if(loopJumps.isEmpty())
-            {
-                throw new PreScriptException("continue without a loop", previous().getLine());
-            }
-            JumpData jump = new JumpData(inst.size());
-            breakContinueJumps.add(jump);
-            return unaryFunction(jump, "continue");
-        }
-        else if(match(RETURN))
-        {
-            if(match(SEMICOLON))
-            {
-                current--;
-                return new Function(FunctionLoader.getFunction("return"), new InputProvider[0]);
-            }
-            return unaryFunction(parseExpression(), "return");
-        }
-        else if(match(TRY))
-        {
-            peek(OPEN_CURVED_BRACKET, "unexpected token after 'try': " + tokens[current]);
-            JumpData jump = new JumpData(inst.size());
-            jumps.push(new JumpWrapper(jump, "try"));
-            return unaryFunction(jump, "try");
-        }
-        else if(match(CATCH))
-        {
-            if(!tryState)
-            {
-                throw new PreScriptException("catch without try", previous().getLine());
-            }
-            peek(OPEN_CURVED_BRACKET, "unexpected token after 'catch': " + tokens[current]);
-            JumpData jump = new JumpData(inst.size());
-            jumps.push(new JumpWrapper(jump, "catch"));
-            return unaryFunction(jump, "catch");
-        }
-        else if(match(OPEN_BRACKET)) 
-        {
-            InputProvider expr = parseExpression();
-            consume(CLOSE_BRACKET, "'(' without ')'");
-            return expr;
-        }
-        throw new PreScriptException("unexpected token: " + tokens[current], tokens[current].getLine());
-    }
-}

+ 0 - 50
src/me/hammerle/snuviscript/token/Token.java

@@ -1,50 +0,0 @@
-package me.hammerle.snuviscript.token;
-
-public class Token 
-{
-    private final TokenType t;
-    private final int line;
-    private final Object o;
-    
-    public Token(TokenType t, int line, Object o)
-    {
-        this.t = t;
-        this.line = line;
-        this.o = o;
-    }
-    
-    public Token(TokenType t, int line)
-    {
-        this(t, line, null);
-    }
-    
-    public TokenType getToken()
-    {
-        return t;
-    }
-    
-    public Object getData()
-    {
-        return o;
-    }
-    
-    public int getLine()
-    {
-        return line;
-    }
-
-    @Override
-    public String toString() 
-    {
-        if(o != null)
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.append(t);
-            sb.append('(');
-            sb.append(o);
-            sb.append(')');
-            return sb.toString();
-        }
-        return t.toString();
-    }
-}

+ 0 - 81
src/me/hammerle/snuviscript/token/TokenType.java

@@ -1,81 +0,0 @@
-package me.hammerle.snuviscript.token;
-
-public enum TokenType
-{
-    DOUBLE("double"),
-    TRUE("true"),
-    FALSE("false"),
-    NULL("null"),
-    TEXT("String"),
-    LABEL("Label"),
-    VAR("var"),
-    
-    INC("++"),
-    DEC("--"),
-    INVERT("!"), 
-    BIT_INVERT("~"), 
-    MUL("*"), 
-    DIV("/"), 
-    MOD("%"), 
-    ADD("+"), 
-    SUB("-"), 
-    LEFT_SHIFT("<<"), 
-    RIGHT_SHIFT(">>"), 
-    LESS("<"), 
-    LESS_EQUAL("<="), 
-    GREATER(">"), 
-    GREATER_EQUAL(">="), 
-    EQUAL("=="), 
-    NOT_EQUAL("!="), 
-    BIT_AND("&"), 
-    BIT_XOR("^"), 
-    BIT_OR("|"), 
-    AND("&&"), 
-    OR("||"), 
-    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("|="), 
-    COMMA(","), 
-    OPEN_BRACKET("("), 
-    CLOSE_BRACKET(")"), 
-    OPEN_SQUARE_BRACKET("["), 
-    CLOSE_SQUARE_BRACKET("]"), 
-    OPEN_CURVED_BRACKET("{"), 
-    CLOSE_CURVED_BRACKET("}"), 
-    SEMICOLON(";"), 
-    
-    IF("if"),
-    ELSE_IF("elseif"),
-    ELSE("else"),
-    FOR("for"),
-    WHILE("while"),
-    FUNCTION("function"),
-    BREAK("break"),
-    CONTINUE("continue"),
-    RETURN("return"),
-    TRY("try"),
-    CATCH("catch"),
-    
-    END_OF_FILE("end_of_file");
-    
-    private final String name;
-    
-    TokenType(String name)
-    {
-        this.name = name;
-    }
-
-    @Override
-    public String toString() 
-    {
-        return name;
-    }
-}

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

@@ -1,399 +0,0 @@
-package me.hammerle.snuviscript.token;
-
-import java.util.LinkedList;
-import me.hammerle.snuviscript.code.Instruction;
-import me.hammerle.snuviscript.exceptions.PreScriptException;
-
-public class Tokenizer 
-{
-    private final char[] code;
-    private int line;
-    
-    private final LinkedList<Token> data;
-    
-    public Tokenizer(String code)
-    {
-        this.code = code.toCharArray();
-        this.data = new LinkedList<>();
-    }
-    
-    private void addToken(TokenType t)
-    {
-        data.add(new Token(t, line + 1));
-    }
-    
-    private void addToken(TokenType t, Object o)
-    {
-        data.add(new Token(t, line + 1, o));
-    }
-    
-    public void tokenize()
-    {
-        line = 0;
-        for(int index = 0; index < code.length; index++)
-        {
-            if(Character.isLetter(code[index]))
-            {
-                int old = index;
-                index++;
-                while(index < code.length && (Character.isLetterOrDigit(code[index]) || code[index] == '.' || code[index] == '_'))
-                {
-                    index++;
-                }
-                String s = new String(code, old, index - old);
-                switch(s)
-                {
-                    case "if": addToken(TokenType.IF); break;
-                    case "elseif": addToken(TokenType.ELSE_IF); break;
-                    case "else": addToken(TokenType.ELSE); break;
-                    case "for": addToken(TokenType.FOR); break;
-                    case "while": addToken(TokenType.WHILE); break;
-                    case "function": addToken(TokenType.FUNCTION); break;
-                    case "break": addToken(TokenType.BREAK); break;
-                    case "continue": addToken(TokenType.CONTINUE); break;
-                    case "return": addToken(TokenType.RETURN); break;
-                    case "try": addToken(TokenType.TRY); break;
-                    case "catch": addToken(TokenType.CATCH); break;
-                    default:
-                        addToken(TokenType.VAR, s);
-                }
-                index--;
-            }
-            else if(Character.isDigit(code[index]))
-            {
-                int old = index;
-                index++;
-                while(index < code.length)
-                {
-                    switch(code[index])
-                    {
-                        case '0':
-                        case '1':
-                        case '2':
-                        case '3':
-                        case '4':
-                        case '5':
-                        case '6':
-                        case '7':
-                        case '8':
-                        case '9':
-                        {
-                            index++;
-                            continue;
-                        }
-                        case '.':
-                        {
-                            index++;
-                            while(index < code.length && Character.isDigit(code[index]))
-                            {
-                                index++;
-                            }
-                            break;
-                        }
-                    }
-                    break;
-                }
-                addToken(TokenType.DOUBLE, Double.parseDouble(new String(code, old, index - old)));
-                index--;
-            }
-            else
-            {
-                int startLine = line;
-                try
-                {
-                    switch(code[index])
-                    {
-                        case '\n':
-                        {
-                            line++;
-                            break;
-                        }
-                        case '@':
-                        {
-                            int old = index;
-                            index++;
-                            while(index < code.length && (Character.isLetterOrDigit(code[index]) || code[index] == '.' || code[index] == '_'))
-                            {
-                                index++;
-                            }
-                            addToken(TokenType.LABEL, new String(code, old, index - old));
-                            index--;
-                            break;
-                        }
-                        case '"':
-                        {
-                            int old = index + 1;
-                            index++;
-                            while(index < code.length && code[index] != '"')
-                            {
-                                index++;
-                            }
-                            addToken(TokenType.TEXT, new String(code, old, index - old));
-                            break;
-                        }
-                        case '+':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '+':
-                                    addToken(TokenType.INC);
-                                    index++;
-                                    break;
-                                case '=':
-                                    addToken(TokenType.ADD_SET);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.ADD);
-                            }
-                            break;
-                        }
-                        case '-':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '-':
-                                    addToken(TokenType.DEC);
-                                    index++;
-                                    break;
-                                case '=':
-                                    addToken(TokenType.SUB_SET);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.SUB);
-                            }
-                            break;
-                        }
-                        case '*':
-                        {
-                            if(code[index + 1] == '=')
-                            {
-                                addToken(TokenType.MUL_SET);
-                                index++;
-                            }
-                            else
-                            {
-                                addToken(TokenType.MUL);
-                            }
-                            break;
-                        }
-                        case '/':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '/':
-                                    index += 2;
-                                    while(code[index] != '\n')
-                                    {
-                                        index++;
-                                    }
-                                    index--;
-                                    break;
-                                case '*':
-                                    index += 2;
-                                    while(code[index] != '*' || code[index + 1] != '/')
-                                    {
-                                        if(code[index] == '\n')
-                                        {
-                                            line++;
-                                        }
-                                        index++;
-                                    }
-                                    index++;
-                                    break;
-                                case '=':
-                                    addToken(TokenType.DIV_SET);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.DIV);
-                            }
-                            break;
-                        }
-                        case '!':
-                        {
-                            if(code[index + 1] == '=')
-                            {
-                                addToken(TokenType.NOT_EQUAL);
-                                index++;
-                                break;
-                            }
-                            else
-                            {
-                                addToken(TokenType.INVERT);
-                            }
-                            break;
-                        }
-                        case '~':
-                        {
-                            addToken(TokenType.BIT_INVERT);
-                            break;
-                        }
-                        case '%':
-                        {
-                            if(code[index + 1] == '=')
-                            {
-                                addToken(TokenType.MOD_SET);
-                                index++;
-                            }
-                            else
-                            {
-                                addToken(TokenType.MOD);
-                            }
-                            break;
-                        }
-                        case '<':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '<':
-                                    if(code[index + 2] == '=')
-                                    {
-                                        addToken(TokenType.LEFT_SHIFT_SET);
-                                        index += 2;
-                                    }
-                                    else
-                                    {
-                                        addToken(TokenType.LEFT_SHIFT);
-                                        index++;
-                                    }
-                                    break;
-                                case '=':
-                                    addToken(TokenType.LESS_EQUAL);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.LESS);
-                            }
-                            break;
-                        }
-                        case '>':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '>':
-                                    if(code[index + 2] == '=')
-                                    {
-                                        addToken(TokenType.RIGHT_SHIFT_SET);
-                                        index += 2;
-                                    }
-                                    else
-                                    {
-                                        addToken(TokenType.RIGHT_SHIFT);
-                                        index++;
-                                    }
-                                    break;
-                                case '=':
-                                    addToken(TokenType.GREATER_EQUAL);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.GREATER);
-                            }
-                            break;
-                        }
-                        case '=': 
-                        {
-                            if(code[index + 1] == '=')
-                            {
-                                addToken(TokenType.EQUAL);
-                                index++;
-                                break;
-                            }
-                            else
-                            {
-                                addToken(TokenType.SET);
-                            }
-                            break;
-                        }
-                        case '&':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '&':
-                                    addToken(TokenType.AND);
-                                    index++;
-                                    break;
-                                case '=':
-                                    addToken(TokenType.BIT_AND_SET);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.BIT_AND);
-                            }
-                            break;
-                        }
-                        case '^':
-                        {
-                            if(code[index + 1] == '=')
-                            {
-                                addToken(TokenType.BIT_XOR_SET);
-                                index++;
-                                break;
-                            }
-                            else
-                            {
-                                addToken(TokenType.BIT_XOR);
-                            }
-                            break;
-                        }
-                        case '|':
-                        {
-                            switch(code[index + 1])
-                            {
-                                case '|':
-                                    addToken(TokenType.OR);
-                                    index++;
-                                    break;
-                                case '=':
-                                    addToken(TokenType.BIT_OR_SET);
-                                    index++;
-                                    break;
-                                default:
-                                    addToken(TokenType.BIT_OR);
-                            }
-                            break;
-                        }
-                        case ',':
-                            addToken(TokenType.COMMA);
-                            break;
-                        case '(':
-                            addToken(TokenType.OPEN_BRACKET);
-                            break;
-                        case ')':
-                            addToken(TokenType.CLOSE_BRACKET);
-                            break;
-                        case '[':
-                            addToken(TokenType.OPEN_SQUARE_BRACKET);
-                            break;
-                        case ']':
-                            addToken(TokenType.CLOSE_SQUARE_BRACKET);
-                            break;
-                        case '{':
-                            addToken(TokenType.OPEN_CURVED_BRACKET);
-                            break;
-                        case '}':
-                            addToken(TokenType.CLOSE_CURVED_BRACKET);
-                            break;
-                        case ';':
-                            addToken(TokenType.SEMICOLON);
-                            break;
-                    }
-                }
-                catch(ArrayIndexOutOfBoundsException ex)
-                {
-                    throw new PreScriptException("unexpected code end", startLine, line);
-                }
-            }
-        }       
-        addToken(TokenType.END_OF_FILE);
-        //data.forEach(e -> System.out.println(e));
-        
-        Parser p = new Parser(data);
-        for(Instruction in : p.parseTokens())
-        {
-            System.out.println(in);
-        }
-    }
-}

+ 11 - 1
test.sbasic

@@ -1 +1,11 @@
-print(usedmemory(), " / ", allocatedmemory());
+print("START");
+
+wusi(array);
+
+function wusi(array) 
+{
+    temp = array[0];
+    return temp;
+}
+
+print("HMM");