|
@@ -20,16 +20,9 @@ public class Code implements Comparable<Code>
|
|
|
private final Object value;
|
|
|
private int jump;
|
|
|
|
|
|
- public Code(String function, int level, int pars, int line, int subline, Object value, int jump)
|
|
|
+ private Code(String function, int level, int pars, int line, int subline, Object value, int jump)
|
|
|
{
|
|
|
- if(function != null)
|
|
|
- {
|
|
|
- this.function = function.toLowerCase();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- this.function = null;
|
|
|
- }
|
|
|
+ this.function = function;
|
|
|
this.level = level;
|
|
|
this.pars = pars;
|
|
|
this.line = line;
|
|
@@ -61,6 +54,11 @@ public class Code implements Comparable<Code>
|
|
|
stack.push(value);
|
|
|
return;
|
|
|
}
|
|
|
+ else if(value == null && function == null)
|
|
|
+ {
|
|
|
+ stack.push(value);
|
|
|
+ return;
|
|
|
+ }
|
|
|
Object[] input;
|
|
|
if(pars > 0)
|
|
|
{
|
|
@@ -89,7 +87,7 @@ public class Code implements Comparable<Code>
|
|
|
@Override
|
|
|
public String toString()
|
|
|
{
|
|
|
- StringBuilder sb = new StringBuilder(">>>");
|
|
|
+ StringBuilder sb = new StringBuilder(">");
|
|
|
for(int i = 1; i < level; i++)
|
|
|
{
|
|
|
sb.append(">");
|
|
@@ -103,8 +101,15 @@ public class Code implements Comparable<Code>
|
|
|
if(value != null)
|
|
|
{
|
|
|
sb.append("push ");
|
|
|
- sb.append(value.getClass());
|
|
|
- sb.append(" value = '");
|
|
|
+ sb.append(value.getClass().getSimpleName());
|
|
|
+ sb.append(" '");
|
|
|
+ sb.append(value);
|
|
|
+ sb.append("'");
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ else if(value == null && function == null)
|
|
|
+ {
|
|
|
+ sb.append("push Null '");
|
|
|
sb.append(value);
|
|
|
sb.append("'");
|
|
|
return sb.toString();
|
|
@@ -184,7 +189,7 @@ public class Code implements Comparable<Code>
|
|
|
return start;
|
|
|
}
|
|
|
|
|
|
- private static int findStartOfSyntax(String code, int pos)
|
|
|
+ private static int findStartOfSyntax(StringBuilder code, int pos)
|
|
|
{
|
|
|
int bracketCounter = 0;
|
|
|
char c;
|
|
@@ -217,6 +222,7 @@ public class Code implements Comparable<Code>
|
|
|
case '*':
|
|
|
case '/':
|
|
|
case '^':
|
|
|
+ case '@':
|
|
|
case '=':
|
|
|
case '>':
|
|
|
case '<':
|
|
@@ -249,7 +255,12 @@ public class Code implements Comparable<Code>
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- private static int findEndOfSyntax(String code, int pos)
|
|
|
+ private static int findEndOfSyntax(StringBuilder code, int pos)
|
|
|
+ {
|
|
|
+ return findEndOfSyntax(code, pos, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int findEndOfSyntax(StringBuilder code, int pos, boolean b)
|
|
|
{
|
|
|
int bracketCounter = 0;
|
|
|
char c;
|
|
@@ -266,6 +277,15 @@ public class Code implements Comparable<Code>
|
|
|
pos++;
|
|
|
continue;
|
|
|
}
|
|
|
+ if(b && c == '\n')
|
|
|
+ {
|
|
|
+ if(bracketCounter != 0)
|
|
|
+ {
|
|
|
+ pos++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
switch(c)
|
|
|
{
|
|
|
case ';':
|
|
@@ -282,6 +302,7 @@ public class Code implements Comparable<Code>
|
|
|
case '*':
|
|
|
case '/':
|
|
|
case '^':
|
|
|
+ case '@':
|
|
|
case '=':
|
|
|
case '>':
|
|
|
case '<':
|
|
@@ -314,7 +335,7 @@ public class Code implements Comparable<Code>
|
|
|
return code.length();
|
|
|
}
|
|
|
|
|
|
- private static int findSyntax(String find, String code, int pos)
|
|
|
+ private static int findSyntax(String find, StringBuilder code, int pos)
|
|
|
{
|
|
|
int length = code.length();
|
|
|
char c;
|
|
@@ -354,13 +375,13 @@ public class Code implements Comparable<Code>
|
|
|
StringBuilder newSyntax;
|
|
|
while(pos < sb.length())
|
|
|
{
|
|
|
- pos = findSyntax(syntax, sb.toString(), pos + 1);
|
|
|
+ pos = findSyntax(syntax, sb, pos + 1);
|
|
|
if(pos == -1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- start = findStartOfSyntax(sb.toString(), pos - 1);
|
|
|
- end = findEndOfSyntax(sb.toString(), pos + slength);
|
|
|
+ start = findStartOfSyntax(sb, pos - 1);
|
|
|
+ end = findEndOfSyntax(sb, pos + slength);
|
|
|
newSyntax = new StringBuilder(f);
|
|
|
newSyntax.append("(");
|
|
|
if(b)
|
|
@@ -394,13 +415,13 @@ public class Code implements Comparable<Code>
|
|
|
StringBuilder newSyntax;
|
|
|
while(pos < sb.length())
|
|
|
{
|
|
|
- pos = findSyntax(syntax, sb.toString(), pos + 1);
|
|
|
+ pos = findSyntax(syntax, sb, pos + 1);
|
|
|
if(pos == -1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- start = findStartOfSyntax(sb.toString(), pos - 1);
|
|
|
- end = findEndOfSyntax(sb.toString(), pos + slength);
|
|
|
+ start = findStartOfSyntax(sb, pos - 1);
|
|
|
+ end = findEndOfSyntax(sb, pos + slength);
|
|
|
newSyntax = new StringBuilder("setvar(\"");
|
|
|
first = sb.substring(start, pos).trim();
|
|
|
newSyntax.append(first);
|
|
@@ -453,11 +474,21 @@ public class Code implements Comparable<Code>
|
|
|
int pos = 0;
|
|
|
while(true)
|
|
|
{
|
|
|
- pos = findSyntax(keyWord, sb.toString(), pos);
|
|
|
+ pos = findSyntax(keyWord, sb, pos);
|
|
|
if(pos == -1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
+ if(pos >= 1 && Character.isLetter(sb.charAt(pos - 1)))
|
|
|
+ {
|
|
|
+ pos += length;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(pos + length < sb.length() && Character.isLetter(sb.charAt(pos + length)))
|
|
|
+ {
|
|
|
+ pos += length;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if(!sb.substring(pos).startsWith(with))
|
|
|
{
|
|
|
sb.replace(pos, pos + length, with);
|
|
@@ -476,12 +507,12 @@ public class Code implements Comparable<Code>
|
|
|
StringBuilder sb = new StringBuilder(code);
|
|
|
while(true)
|
|
|
{
|
|
|
- old = findSyntax("/*", sb.toString(), old);
|
|
|
+ old = findSyntax("/*", sb, old);
|
|
|
if(old == -1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- pos = findSyntax("*/", sb.toString(), old);
|
|
|
+ pos = findSyntax("*/", sb, old);
|
|
|
if(pos == -1)
|
|
|
{
|
|
|
throw new PrescriptException(scriptName, sb.substring(old, Math.min(old + 20, sb.length())), "/* without */");
|
|
@@ -491,12 +522,12 @@ public class Code implements Comparable<Code>
|
|
|
old = 0;
|
|
|
while(true)
|
|
|
{
|
|
|
- old = findSyntax("//", sb.toString(), old);
|
|
|
+ old = findSyntax("//", sb, old);
|
|
|
if(old == -1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- pos = findSyntax("\n", sb.toString(), old);
|
|
|
+ pos = findSyntax("\n", sb, old);
|
|
|
if(pos == -1)
|
|
|
{
|
|
|
sb.replace(old, sb.length(), "");
|
|
@@ -505,11 +536,34 @@ public class Code implements Comparable<Code>
|
|
|
sb.replace(old, pos + 1, "");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ old = 0;
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ pos = findSyntax("@", sb, old);
|
|
|
+ if(pos == -1)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pos++;
|
|
|
+ old = pos;
|
|
|
+ pos = findEndOfSyntax(sb, pos, true);
|
|
|
+ if(pos == -1)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(sb.charAt(pos) != ';')
|
|
|
+ {
|
|
|
+ sb.insert(pos, ';');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
addKeyWordBrackets("else", sb);
|
|
|
addKeyWordBrackets("try", sb);
|
|
|
addKeyWordBrackets("catch", sb);
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -536,8 +590,22 @@ public class Code implements Comparable<Code>
|
|
|
changeUnSyntax("*=", "mul", sb);
|
|
|
|
|
|
changeBiSyntax("=", "setvar", sb, true);
|
|
|
+
|
|
|
+
|
|
|
+ pos = 0;
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ pos = findSyntax("sub(,", sb, pos);
|
|
|
+ if(pos == -1)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ sb.insert(pos + 4, '0');
|
|
|
+ pos++;
|
|
|
+ }
|
|
|
|
|
|
code = sb.toString();
|
|
|
+
|
|
|
|
|
|
|
|
|
ArrayList<Code> list = new ArrayList<>();
|
|
@@ -815,16 +883,16 @@ public class Code implements Comparable<Code>
|
|
|
int end = findClosingBracket(f, start);
|
|
|
if((start != -1 || end != -1) && (((start == -1 || end == -1) && start != end) || end != f.length() - 1))
|
|
|
{
|
|
|
- throw new PrescriptException(scriptName, "unbalanced ()", f);
|
|
|
+ throw new PrescriptException(scriptName, f, "unbalanced ()");
|
|
|
}
|
|
|
if(start == -1)
|
|
|
{
|
|
|
- list.add(new Code(level, 0, line, sublines, convertInput(f)));
|
|
|
+ list.add(new Code(level, 0, line, sublines, convertInput(f, true)));
|
|
|
return;
|
|
|
}
|
|
|
else if(start >= end - 1)
|
|
|
{
|
|
|
- String functionName = f.substring(0, start).trim();
|
|
|
+ String functionName = f.substring(0, start).trim().toLowerCase();
|
|
|
if(!parser.isRegisteredFunction(functionName))
|
|
|
{
|
|
|
throw new NoSuchMethodException(scriptName, f, functionName);
|
|
@@ -833,7 +901,7 @@ public class Code implements Comparable<Code>
|
|
|
return;
|
|
|
}
|
|
|
ArrayList<String> splitted = splitComma(f.substring(start + 1, end));
|
|
|
- String functionName = f.substring(0, start).trim();
|
|
|
+ String functionName = f.substring(0, start).trim().toLowerCase();
|
|
|
if(!parser.isRegisteredFunction(functionName))
|
|
|
{
|
|
|
throw new NoSuchMethodException(scriptName, f, functionName);
|
|
@@ -842,7 +910,7 @@ public class Code implements Comparable<Code>
|
|
|
splitted.forEach(s -> splitFunctions(list, s, level, line));
|
|
|
}
|
|
|
|
|
|
- public static Object convertInput(String s)
|
|
|
+ public static Object convertInput(String s, boolean variable)
|
|
|
{
|
|
|
if(s == null)
|
|
|
{
|
|
@@ -883,7 +951,11 @@ public class Code implements Comparable<Code>
|
|
|
}
|
|
|
catch(NumberFormatException ex)
|
|
|
{
|
|
|
- return new Variable(s);
|
|
|
+ if(variable)
|
|
|
+ {
|
|
|
+ return new Variable(s);
|
|
|
+ }
|
|
|
+ return s;
|
|
|
}
|
|
|
}
|
|
|
}
|