|
@@ -4,433 +4,287 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Stack;
|
|
|
import me.hammerle.exceptions.PreScriptException;
|
|
|
-import me.hammerle.math.Fraction;
|
|
|
|
|
|
public class LineCompiler
|
|
|
{
|
|
|
private int realLine;
|
|
|
- // counts brackets to know if we are in a function
|
|
|
- private int bracketCounter;
|
|
|
- // last special character to stop push
|
|
|
- private final Stack<Integer> lastSpecial;
|
|
|
// comma counter, for functions
|
|
|
private final Stack<Integer> commaCounter;
|
|
|
- // store for adding function on next successfull push
|
|
|
- private final HashMap<Integer, String> nextFunction;
|
|
|
- // stores if a function was just called
|
|
|
- private boolean function;
|
|
|
|
|
|
private String line;
|
|
|
private byte layer;
|
|
|
|
|
|
- private SnuviParser parser;
|
|
|
private String scriptName;
|
|
|
|
|
|
public LineCompiler(SnuviParser parser, String scriptName)
|
|
|
{
|
|
|
realLine = 0;
|
|
|
- bracketCounter = 0;
|
|
|
- lastSpecial = new Stack<>();
|
|
|
commaCounter = new Stack<>();
|
|
|
- nextFunction = new HashMap<>();
|
|
|
- function = false;
|
|
|
line = "";
|
|
|
layer = 0;
|
|
|
- this.parser = parser;
|
|
|
this.scriptName = scriptName;
|
|
|
}
|
|
|
|
|
|
public void reset(int realLine, byte layer, String line)
|
|
|
{
|
|
|
this.realLine = realLine;
|
|
|
- bracketCounter = 0;
|
|
|
- lastSpecial.clear();
|
|
|
- lastSpecial.push(line.length());
|
|
|
commaCounter.clear();
|
|
|
- nextFunction.clear();
|
|
|
- function = false;
|
|
|
this.line = line;
|
|
|
this.layer = layer;
|
|
|
}
|
|
|
|
|
|
- private boolean push(HashMap<String, String> strings, ArrayList<Code> co, int index)
|
|
|
- {
|
|
|
- if(function)
|
|
|
- {
|
|
|
- if(index + 1 != lastSpecial.peek())
|
|
|
- {
|
|
|
- co.add(new Code(Code.convertInput(strings, line.substring(index + 1, lastSpecial.pop()), true), realLine, layer));
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- co.add(new Code(Code.convertInput(strings, line.substring(index + 1, lastSpecial.pop()), true), realLine, layer));
|
|
|
- }
|
|
|
- String sNextFunction = nextFunction.remove(bracketCounter);
|
|
|
- if(sNextFunction != null)
|
|
|
- {
|
|
|
- if(sNextFunction.equals("sub") && !co.isEmpty())
|
|
|
- {
|
|
|
- Code c = co.get(co.size() - 1);
|
|
|
- if("".equals(c.value))
|
|
|
- {
|
|
|
- c.value = new Fraction(0);
|
|
|
- }
|
|
|
- }
|
|
|
- co.add(new Code(sNextFunction, 2, realLine, layer));
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
private boolean isAllowedChar(char c)
|
|
|
{
|
|
|
- return Character.isLetterOrDigit(c) || c == '.' || c == '_';
|
|
|
+ return Character.isLetterOrDigit(c) || c == '.' || c == '_' || c == '#';
|
|
|
}
|
|
|
|
|
|
public void compile(ArrayList<Code> co, HashMap<String, String> strings)
|
|
|
{
|
|
|
- try
|
|
|
+ Stack<Stack<Syntax>> syntaxStack = new Stack<>();
|
|
|
+ syntaxStack.push(new Stack<>());
|
|
|
+
|
|
|
+ char[] chars = line.toCharArray();
|
|
|
+ char c;
|
|
|
+ int old = chars.length;
|
|
|
+ Syntax syntax;
|
|
|
+ String s;
|
|
|
+ for(int i = old - 1; i >= 0; i--)
|
|
|
{
|
|
|
- int old;
|
|
|
- int j = line.length() - 1;
|
|
|
- boolean arrayState = true;
|
|
|
- String arrayFunction = null;
|
|
|
- int commas;
|
|
|
- String syntax;
|
|
|
- while(j >= 0)
|
|
|
+ c = chars[i];
|
|
|
+ if(!isAllowedChar(c))
|
|
|
{
|
|
|
- syntax = null;
|
|
|
- switch(line.charAt(j))
|
|
|
+ syntax = getSyntax(line, i);
|
|
|
+ if(syntax == Syntax.UNKNOWN)
|
|
|
{
|
|
|
- case '+':
|
|
|
- if(line.charAt(j - 1) == '+')
|
|
|
- {
|
|
|
- int last = lastSpecial.pop();
|
|
|
- if(last - j >= 2)
|
|
|
- {
|
|
|
- // ++i
|
|
|
- if(j + 1 - last == 0)
|
|
|
- {
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
- }
|
|
|
- co.add(new Code(line.substring(j + 1, last), realLine, layer));
|
|
|
- co.add(new Code("inc", 1, realLine, layer));
|
|
|
- j--;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Code c = co.get(co.size() - 1);
|
|
|
- if("array.get".equals(c.function))
|
|
|
- {
|
|
|
- co.set(co.size() - 1, new Code("array.inc", 2, c.realLine, c.layer));
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- function = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- // i++
|
|
|
- j--;
|
|
|
- old = j;
|
|
|
- j--;
|
|
|
- if(line.charAt(j) == ']')
|
|
|
- {
|
|
|
- arrayFunction = "postinc";
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
- }
|
|
|
- while(j >= 0 && isAllowedChar(line.charAt(j)))
|
|
|
- {
|
|
|
- j--;
|
|
|
- }
|
|
|
- j++;
|
|
|
- if(j - old == 0)
|
|
|
- {
|
|
|
- co.forEach(s -> System.out.println(s));
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
- }
|
|
|
- co.add(new Code(line.substring(j, old), realLine, layer));
|
|
|
- co.add(new Code("postinc", 1, realLine, layer));
|
|
|
- }
|
|
|
- lastSpecial.push(j);
|
|
|
- function = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- syntax = "add";
|
|
|
- break;
|
|
|
- case '-':
|
|
|
- if(line.charAt(j - 1) == '-')
|
|
|
- {
|
|
|
- int last = lastSpecial.pop();
|
|
|
- if(last - j >= 2)
|
|
|
- {
|
|
|
- // ++i
|
|
|
- if(j + 1 - last == 0)
|
|
|
- {
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
- }
|
|
|
- co.add(new Code(line.substring(j + 1, last), realLine, layer));
|
|
|
- co.add(new Code("dec", 1, realLine, layer));
|
|
|
- j--;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Code c = co.get(co.size() - 1);
|
|
|
- if("array.get".equals(c.function))
|
|
|
- {
|
|
|
- co.set(co.size() - 1, new Code("array.dec", 2, c.realLine, c.layer));
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- function = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- // i++
|
|
|
- j--;
|
|
|
- old = j;
|
|
|
- j--;
|
|
|
- if(line.charAt(j) == ']')
|
|
|
- {
|
|
|
- arrayFunction = "postdec";
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
- }
|
|
|
- while(j >= 0 && isAllowedChar(line.charAt(j)))
|
|
|
- {
|
|
|
- j--;
|
|
|
- }
|
|
|
- j++;
|
|
|
- if(j - old == 0)
|
|
|
- {
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
- }
|
|
|
- co.add(new Code(line.substring(j, old), realLine, layer));
|
|
|
- co.add(new Code("postdec", 1, realLine, layer));
|
|
|
- }
|
|
|
- lastSpecial.push(j);
|
|
|
- function = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- syntax = "sub";
|
|
|
- break;
|
|
|
- case '*': syntax = "mul"; break;
|
|
|
- case '/': syntax = "div"; break;
|
|
|
- case '%': syntax = "math.mod"; break;
|
|
|
- case '^': syntax = "math.pow"; break;
|
|
|
- case '<': syntax = "less"; break;
|
|
|
- case '>': syntax = "greater"; break;
|
|
|
- case '|':
|
|
|
+ throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
+ }
|
|
|
+ else if(syntax.isIncOrDec())
|
|
|
+ {
|
|
|
+ Code change = co.get(co.size() - 1);
|
|
|
+ if(change.function.equals("array.get"))
|
|
|
{
|
|
|
- if(line.charAt(j - 1) == '|')
|
|
|
- {
|
|
|
- function = push(strings, co, j);
|
|
|
- nextFunction.put(bracketCounter, "or");
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
- }
|
|
|
- break;
|
|
|
+ change.function = "array." + syntax.getFunction();
|
|
|
}
|
|
|
- case '&':
|
|
|
+ }
|
|
|
+ s = line.substring(i + 1, old);
|
|
|
+ if(!s.isEmpty())
|
|
|
+ {
|
|
|
+ Stack<Syntax> stack = syntaxStack.peek();
|
|
|
+ if(!stack.isEmpty())
|
|
|
{
|
|
|
- if(line.charAt(j - 1) == '&')
|
|
|
+ Syntax sy = stack.peek();
|
|
|
+ if(sy == Syntax.INC)
|
|
|
{
|
|
|
- function = push(strings, co, j);
|
|
|
- nextFunction.put(bracketCounter, "and");
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
+ stack.pop();
|
|
|
+ stack.push(Syntax.POST_INC);
|
|
|
+ }
|
|
|
+ else if(sy == Syntax.DEC)
|
|
|
+ {
|
|
|
+ stack.pop();
|
|
|
+ stack.push(Syntax.POST_DEC);
|
|
|
}
|
|
|
- break;
|
|
|
}
|
|
|
- case ']':
|
|
|
+ co.add(new Code(Code.convertInput(strings, s, true), realLine, layer));
|
|
|
+ }
|
|
|
+ i += 1 - syntax.getFunction().length();
|
|
|
+ old = i;
|
|
|
+ if(syntax.shouldStartLayer())
|
|
|
+ {
|
|
|
+ syntaxStack.push(new Stack<>());
|
|
|
+ commaCounter.push(0);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if(syntax.shouldEndLayer())
|
|
|
+ {
|
|
|
+ Stack<Syntax> currentStack = syntaxStack.pop();
|
|
|
+ while(!currentStack.isEmpty())
|
|
|
{
|
|
|
- bracketCounter++;
|
|
|
- lastSpecial.push(j);
|
|
|
- break;
|
|
|
+ doStackEmptying(co, currentStack.pop());
|
|
|
}
|
|
|
- case '[':
|
|
|
+ old--;
|
|
|
+ int pos = old;
|
|
|
+ while(old >= 0 && isAllowedChar(chars[old]))
|
|
|
{
|
|
|
- old = lastSpecial.pop();
|
|
|
- if(old - j >= 2)
|
|
|
- {
|
|
|
- co.add(new Code(Code.convertInput(strings, line.substring(j + 1, old), true), realLine, layer));
|
|
|
- }
|
|
|
- String sNextFunction = nextFunction.remove(bracketCounter);
|
|
|
- if(sNextFunction != null)
|
|
|
- {
|
|
|
- co.add(new Code(sNextFunction, 2, realLine, layer));
|
|
|
- }
|
|
|
- old = j;
|
|
|
- j--;
|
|
|
- while(j >= 0 && isAllowedChar(line.charAt(j)))
|
|
|
- {
|
|
|
- j--;
|
|
|
- }
|
|
|
- j++;
|
|
|
- co.add(new Code(line.substring(j, old), realLine, layer));
|
|
|
- if(arrayFunction != null)
|
|
|
- {
|
|
|
- if(arrayFunction.equals("postinc") || arrayFunction.equals("postdec"))
|
|
|
- {
|
|
|
- co.add(new Code("array." + arrayFunction, 2, realLine, layer));
|
|
|
- arrayFunction = null;
|
|
|
- lastSpecial.push(j);
|
|
|
- break;
|
|
|
- }
|
|
|
- co.add(new Code("array." + arrayFunction, 3, realLine, layer));
|
|
|
- arrayFunction = null;
|
|
|
- j = -1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- else if(arrayState)
|
|
|
- {
|
|
|
- co.add(new Code("array.get", 2, realLine, layer));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- co.add(new Code("array.set", 3, realLine, layer));
|
|
|
- }
|
|
|
- lastSpecial.push(j);
|
|
|
- function = true;
|
|
|
- bracketCounter--;
|
|
|
- break;
|
|
|
+ old--;
|
|
|
}
|
|
|
- case '=':
|
|
|
+ old++;
|
|
|
+ s = line.substring(old, pos + 1);
|
|
|
+ if(syntax.isArray())
|
|
|
{
|
|
|
- char before = line.charAt(j - 1);
|
|
|
- switch(before)
|
|
|
- {
|
|
|
- case '=': syntax = "equal"; break;
|
|
|
- case '!': syntax = "notequal"; break;
|
|
|
- case '>': syntax = "greaterequal"; break;
|
|
|
- case '<': syntax = "lessequal"; break;
|
|
|
- case ']': syntax = "bracket"; break;
|
|
|
- }
|
|
|
- if(syntax != null)
|
|
|
- {
|
|
|
- if(syntax.equals("bracket"))
|
|
|
- {
|
|
|
- arrayState = false;
|
|
|
- function = push(strings, co, j);
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
- }
|
|
|
- function = push(strings, co, j);
|
|
|
- nextFunction.put(bracketCounter, syntax);
|
|
|
- j--;
|
|
|
- lastSpecial.push(j);
|
|
|
- j--;
|
|
|
- continue;
|
|
|
- }
|
|
|
- function = push(strings, co, j);
|
|
|
- int checker = j - 2;
|
|
|
- char c;
|
|
|
- while(checker >= 0)
|
|
|
+ co.add(new Code(s, realLine, layer));
|
|
|
+ if(!syntaxStack.isEmpty())
|
|
|
{
|
|
|
- c = line.charAt(checker);
|
|
|
- if(c == ']')
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- else if(!isAllowedChar(c))
|
|
|
+ Stack<Syntax> arrayFunction = syntaxStack.pop();
|
|
|
+ if(!arrayFunction.isEmpty())
|
|
|
{
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
- }
|
|
|
- checker--;
|
|
|
- }
|
|
|
- String var;
|
|
|
- switch(before)
|
|
|
- {
|
|
|
- case '+': syntax = "add"; break;
|
|
|
- case '-': syntax = "sub"; break;
|
|
|
- case '*': syntax = "mul"; break;
|
|
|
- case '/': syntax = "div"; break;
|
|
|
- default:
|
|
|
- var = line.substring(0, j);
|
|
|
- co.add(new Code(var, realLine, layer));
|
|
|
- }
|
|
|
- if(syntax != null)
|
|
|
- {
|
|
|
- if(line.charAt(j - 2) == ']')
|
|
|
- {
|
|
|
- arrayFunction = syntax;
|
|
|
- j -= 2;
|
|
|
+ Syntax sy = arrayFunction.pop();
|
|
|
+ if(sy.isIncOrDec())
|
|
|
+ {
|
|
|
+ if(sy == Syntax.INC)
|
|
|
+ {
|
|
|
+ sy = Syntax.POST_INC;
|
|
|
+ }
|
|
|
+ else if(sy == Syntax.DEC)
|
|
|
+ {
|
|
|
+ sy = Syntax.POST_DEC;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co.add(new Code("array." + sy.getFunction(), sy.isIncOrDec() ? 2 : 3, realLine, layer));
|
|
|
continue;
|
|
|
}
|
|
|
- co.add(new Code(line.substring(0, j - 1), realLine, layer));
|
|
|
- co.add(new Code(syntax + "var", 2, realLine, layer));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- co.add(new Code("setvar", 2, realLine, layer));
|
|
|
}
|
|
|
- j = -1;
|
|
|
- continue;
|
|
|
+ co.add(new Code("array.get", 2, realLine, layer));
|
|
|
}
|
|
|
- case ')':
|
|
|
+ else
|
|
|
{
|
|
|
- bracketCounter++;
|
|
|
- lastSpecial.push(j);
|
|
|
- commaCounter.push(0);
|
|
|
- break;
|
|
|
- }
|
|
|
- case ',':
|
|
|
- {
|
|
|
- commaCounter.push(commaCounter.pop() + 1);
|
|
|
- function = push(strings, co, j);
|
|
|
- lastSpecial.push(j);
|
|
|
- break;
|
|
|
- }
|
|
|
- case '(':
|
|
|
- {
|
|
|
- commas = commaCounter.pop() + 1;
|
|
|
- if(line.charAt(j + 1) != ')')
|
|
|
+ if(line.startsWith("()", pos + 1))
|
|
|
{
|
|
|
- if(j + 1 != lastSpecial.peek())
|
|
|
- {
|
|
|
- co.add(new Code(Code.convertInput(strings, line.substring(j + 1, lastSpecial.pop()), true), realLine, layer));
|
|
|
- }
|
|
|
+ co.add(new Code(s, 0, realLine, layer));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- commas = 0;
|
|
|
- }
|
|
|
- String sNextFunction = nextFunction.remove(bracketCounter);
|
|
|
- if(sNextFunction != null)
|
|
|
- {
|
|
|
- co.add(new Code(sNextFunction, 2, realLine, layer));
|
|
|
- }
|
|
|
- bracketCounter--;
|
|
|
- function = true;
|
|
|
- old = j;
|
|
|
- j--;
|
|
|
- while(j >= 0 && isAllowedChar(line.charAt(j)))
|
|
|
- {
|
|
|
- j--;
|
|
|
+ co.add(new Code(s, commaCounter.pop() + 1, realLine, layer));
|
|
|
}
|
|
|
- j++;
|
|
|
- co.add(new Code(line.substring(j, old).toLowerCase(), commas, realLine, layer));
|
|
|
- lastSpecial.push(j);
|
|
|
}
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if(!syntaxStack.isEmpty())
|
|
|
+ {
|
|
|
+ Stack<Syntax> currentStack = syntaxStack.peek();
|
|
|
+ while(!currentStack.isEmpty() && currentStack.peek().getWeight() <= syntax.getWeight())
|
|
|
+ {
|
|
|
+ doStackEmptying(co, currentStack.pop());
|
|
|
+ }
|
|
|
+ currentStack.push(syntax);
|
|
|
}
|
|
|
- if(syntax != null)
|
|
|
+
|
|
|
+ if(syntax == Syntax.COMMA)
|
|
|
{
|
|
|
- function = push(strings, co, j);
|
|
|
- nextFunction.put(bracketCounter, syntax);
|
|
|
- lastSpecial.push(j);
|
|
|
+ commaCounter.push(commaCounter.pop() + 1);
|
|
|
}
|
|
|
- j--;
|
|
|
}
|
|
|
}
|
|
|
- catch(StringIndexOutOfBoundsException ex)
|
|
|
+
|
|
|
+ s = line.substring(0, old);
|
|
|
+ if(!s.isEmpty())
|
|
|
{
|
|
|
- throw new PreScriptException(scriptName, realLine, "unexpected character");
|
|
|
+ co.add(new Code(s, realLine, layer));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!syntaxStack.isEmpty())
|
|
|
+ {
|
|
|
+ Stack<Syntax> currentStack = syntaxStack.peek();
|
|
|
+ while(!currentStack.isEmpty())
|
|
|
+ {
|
|
|
+ doStackEmptying(co, currentStack.pop());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doStackEmptying(ArrayList<Code> co, Syntax sy)
|
|
|
+ {
|
|
|
+ if(sy.isFunction())
|
|
|
+ {
|
|
|
+ if(sy.isIncOrDec())
|
|
|
+ {
|
|
|
+ Code change = co.get(co.size() - 1);
|
|
|
+ if(change.value instanceof Variable)
|
|
|
+ {
|
|
|
+ change.value = ((Variable) change.value).getName();
|
|
|
+ }
|
|
|
+ co.add(new Code(sy.getFunction(), sy.getParameters(), realLine, layer));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ co.add(new Code(sy.getFunction(), sy.getParameters(), realLine, layer));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Syntax getSyntax(String code, int pos)
|
|
|
+ {
|
|
|
+ // priorities from C specification
|
|
|
+ // http://en.cppreference.com/w/c/language/operator_precedence
|
|
|
+ switch(code.charAt(pos))
|
|
|
+ {
|
|
|
+ case '(': return Syntax.OPEN_BRACKET;
|
|
|
+ case ')': return Syntax.CLOSE_BRACKET;
|
|
|
+ case '[': return Syntax.OPEN_SBRACKET;
|
|
|
+ case ']': return Syntax.CLOSE_SBRACKET;
|
|
|
+ case '!': return Syntax.NOT;
|
|
|
+ case '~': return Syntax.BIT_NOT;
|
|
|
+ case '*': return Syntax.MUL;
|
|
|
+ case '/': return Syntax.DIV;
|
|
|
+ case '%': return Syntax.MOD;
|
|
|
+ case '^': return Syntax.BIT_XOR;
|
|
|
+ case ',': return Syntax.COMMA;
|
|
|
+ case '+':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '+')
|
|
|
+ {
|
|
|
+ return Syntax.INC;
|
|
|
+ }
|
|
|
+ return Syntax.ADD;
|
|
|
+ case '-':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '-')
|
|
|
+ {
|
|
|
+ return Syntax.DEC;
|
|
|
+ }
|
|
|
+ return Syntax.SUB;
|
|
|
+ case '<':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '<')
|
|
|
+ {
|
|
|
+ return Syntax.LEFT_SHIFT;
|
|
|
+ }
|
|
|
+ return Syntax.SMALLER;
|
|
|
+ case '>':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '>')
|
|
|
+ {
|
|
|
+ return Syntax.RIGHT_SHIFT;
|
|
|
+ }
|
|
|
+ return Syntax.GREATER;
|
|
|
+ case '&':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '&')
|
|
|
+ {
|
|
|
+ return Syntax.AND;
|
|
|
+ }
|
|
|
+ return Syntax.BIT_AND;
|
|
|
+ case '|':
|
|
|
+ if(pos >= 1 && code.charAt(pos - 1) == '|')
|
|
|
+ {
|
|
|
+ return Syntax.OR;
|
|
|
+ }
|
|
|
+ return Syntax.BIT_OR;
|
|
|
+ case '=':
|
|
|
+ if(pos >= 1)
|
|
|
+ {
|
|
|
+ switch(code.charAt(pos - 1))
|
|
|
+ {
|
|
|
+ case '<':
|
|
|
+ if(pos >= 2 && code.charAt(pos - 2) == '<')
|
|
|
+ {
|
|
|
+ return Syntax.SET_SHIFT_LEFT;
|
|
|
+ }
|
|
|
+ return Syntax.SMALLER_EQUAL;
|
|
|
+ case '>':
|
|
|
+ if(pos >= 2 && code.charAt(pos - 2) == '>')
|
|
|
+ {
|
|
|
+ return Syntax.SET_SHIFT_RIGHT;
|
|
|
+ }
|
|
|
+ return Syntax.GREATER_EQUAL;
|
|
|
+ case '=': return Syntax.EQUAL;
|
|
|
+ case '!': return Syntax.NOT_EQUAL;
|
|
|
+ case '+': return Syntax.SET_ADD;
|
|
|
+ case '-': return Syntax.SET_SUB;
|
|
|
+ case '*': return Syntax.SET_MUL;
|
|
|
+ case '/': return Syntax.SET_DIV;
|
|
|
+ case '%': return Syntax.SET_MOD;
|
|
|
+ case '&': return Syntax.SET_BIT_AND;
|
|
|
+ case '^': return Syntax.SET_BIT_XOR;
|
|
|
+ case '|': return Syntax.SET_BIT_OR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Syntax.SET;
|
|
|
}
|
|
|
+ return Syntax.UNKNOWN;
|
|
|
}
|
|
|
}
|