diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 62ec6e3..3327130 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -3,4 +3,4 @@ do.depend=false do.jar=true javac.debug=true javadoc.preview=true -user.properties.file=/home/anderson/.netbeans/7.4/build.properties +user.properties.file=/home/antunes/.netbeans/8.0/build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 0fcd2ce..8d0d0ef 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -3,11 +3,7 @@ - file:/home/andy/Projects/RobotInterface/src/robotinterface/gui/ShortcutsWindow.java - file:/home/andy/Projects/RobotInterface/src/robotinterface/gui/panels/SimulationPanel.java - file:/home/andy/Projects/RobotInterface/src/robotinterface/robot/Robot.java - file:/home/andy/Projects/RobotInterface/src/robotinterface/gui/GUI.java - file:/home/andy/Projects/RobotInterface/src/robotinterface/drawable/DrawingPanel.java + file:/home/andy/Projects/RobotInterface/src/robotinterface/algorithm/procedure/Block.java diff --git a/src/robotinterface/algorithm/parser/decoder/Decoder.java b/src/robotinterface/algorithm/parser/decoder/Decoder.java index 90b9123..f250fe3 100644 --- a/src/robotinterface/algorithm/parser/decoder/Decoder.java +++ b/src/robotinterface/algorithm/parser/decoder/Decoder.java @@ -8,6 +8,7 @@ import robotinterface.algorithm.parser.parameterparser.Argument; import robotinterface.algorithm.parser.parameterparser.ParameterParser; import robotinterface.gui.panels.editor.EditorPanel; +import robotinterface.interpreter.Get; import robotinterface.gui.panels.robot.RobotControlPanel; import robotinterface.robot.device.Device; @@ -69,8 +70,9 @@ private void checkVar() throws ParseException break; } } - jep.initSymTab(); // clear the contents of the function table + jep.initSymTab(); // clear the contents of the function table jep.addStandardConstants(); + jep.addFunction("get", new Get()); for (Object o : jep.getSymbolTable().keySet()) { if (o.toString().equals(token.toString())) @@ -104,7 +106,7 @@ private String getString() mark = null; if (sb.length() > 1) { - //System.out.println("~ '" + sb.substring(1) + "'"); + //System.out.println("~ '" + sb.substring(1) + "'"); return sb.substring(1); } else @@ -679,7 +681,7 @@ final public void primaryPrefix() throws ParseException { break; default: jj_la1[30] = jj_gen; - if (jj_2_4(2)) { + if (jj_2_4(2147483647)) { functionCall(localBlock); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -950,6 +952,7 @@ final public void functionCall(Block block) throws ParseException { } jep.initFunTab(); // clear the contents of the function table jep.addStandardFunctions(); + jep.addFunction("get", new Get()); for (Object o : jep.getFunctionTable().keySet()) { if (o.toString().equals(functionID.toString())) @@ -1052,56 +1055,50 @@ private boolean jj_2_4(int xla) { finally { jj_save(3, xla); } } - private boolean jj_3R_47() { - if (jj_scan_token(BIT_OR)) return true; - if (jj_3R_43()) return true; - return false; - } - - private boolean jj_3R_60() { + private boolean jj_3R_61() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(36)) { jj_scanpos = xsp; if (jj_scan_token(37)) return true; } - if (jj_3R_58()) return true; + if (jj_3R_59()) return true; return false; } - private boolean jj_3R_58() { + private boolean jj_3R_59() { Token xsp; xsp = jj_scanpos; - if (jj_3R_60()) { - jj_scanpos = xsp; if (jj_3R_61()) { jj_scanpos = xsp; if (jj_3R_62()) { jj_scanpos = xsp; - if (jj_3R_63()) return true; + if (jj_3R_63()) { + jj_scanpos = xsp; + if (jj_3R_64()) return true; } } } return false; } - private boolean jj_3R_41() { - if (jj_3R_43()) return true; + private boolean jj_3R_42() { + if (jj_3R_44()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_47()) { jj_scanpos = xsp; break; } + if (jj_3R_48()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_44() { + private boolean jj_3R_45() { if (jj_scan_token(SC_AND)) return true; - if (jj_3R_41()) return true; + if (jj_3R_42()) return true; return false; } - private boolean jj_3R_64() { + private boolean jj_3R_65() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(38)) { @@ -1111,33 +1108,33 @@ private boolean jj_3R_64() { if (jj_scan_token(43)) return true; } } - if (jj_3R_58()) return true; + if (jj_3R_59()) return true; return false; } - private boolean jj_3R_39() { - if (jj_3R_41()) return true; + private boolean jj_3R_40() { + if (jj_3R_42()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_44()) { jj_scanpos = xsp; break; } + if (jj_3R_45()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_56() { - if (jj_3R_58()) return true; + private boolean jj_3R_57() { + if (jj_3R_59()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_64()) { jj_scanpos = xsp; break; } + if (jj_3R_65()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_42() { + private boolean jj_3R_43() { if (jj_scan_token(SC_OR)) return true; - if (jj_3R_39()) return true; + if (jj_3R_40()) return true; return false; } @@ -1147,18 +1144,18 @@ private boolean jj_3_3() { return false; } - private boolean jj_3R_35() { + private boolean jj_3R_36() { if (jj_scan_token(DOT)) return true; if (jj_scan_token(IDENTIFIER)) return true; return false; } - private boolean jj_3R_37() { - if (jj_3R_39()) return true; + private boolean jj_3R_38() { + if (jj_3R_40()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_42()) { jj_scanpos = xsp; break; } + if (jj_3R_43()) { jj_scanpos = xsp; break; } } return false; } @@ -1166,47 +1163,47 @@ private boolean jj_3R_37() { private boolean jj_3R_30() { Token xsp; xsp = jj_scanpos; - if (jj_3R_34()) { + if (jj_3R_35()) { jj_scanpos = xsp; - if (jj_3R_35()) return true; + if (jj_3R_36()) return true; } return false; } - private boolean jj_3R_34() { + private boolean jj_3R_35() { if (jj_scan_token(LBRACKET)) return true; - if (jj_3R_26()) return true; + if (jj_3R_25()) return true; if (jj_scan_token(RBRACKET)) return true; return false; } - private boolean jj_3R_59() { + private boolean jj_3R_60() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(36)) { jj_scanpos = xsp; if (jj_scan_token(37)) return true; } - if (jj_3R_56()) return true; + if (jj_3R_57()) return true; return false; } private boolean jj_3R_32() { - if (jj_3R_37()) return true; + if (jj_3R_38()) return true; return false; } - private boolean jj_3R_54() { - if (jj_3R_56()) return true; + private boolean jj_3R_55() { + if (jj_3R_57()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_59()) { jj_scanpos = xsp; break; } + if (jj_3R_60()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_26() { + private boolean jj_3R_25() { Token xsp; xsp = jj_scanpos; if (jj_3R_31()) { @@ -1217,7 +1214,7 @@ private boolean jj_3R_26() { } private boolean jj_3R_31() { - if (jj_3R_36()) return true; + if (jj_3R_37()) return true; return false; } @@ -1234,7 +1231,13 @@ private boolean jj_3R_33() { return false; } - private boolean jj_3R_36() { + private boolean jj_3_4() { + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_37() { if (jj_3R_20()) return true; if (jj_scan_token(ASSIGN)) return true; if (jj_3R_19()) return true; @@ -1243,12 +1246,12 @@ private boolean jj_3R_36() { private boolean jj_3R_29() { if (jj_scan_token(LPAREN)) return true; - if (jj_3R_26()) return true; + if (jj_3R_25()) return true; if (jj_scan_token(RPAREN)) return true; return false; } - private boolean jj_3R_57() { + private boolean jj_3R_58() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(53)) { @@ -1258,7 +1261,7 @@ private boolean jj_3R_57() { if (jj_scan_token(55)) return true; } } - if (jj_3R_54()) return true; + if (jj_3R_55()) return true; return false; } @@ -1273,22 +1276,22 @@ private boolean jj_3_2() { return false; } - private boolean jj_3_4() { - if (jj_3R_21()) return true; + private boolean jj_3R_27() { + if (jj_3R_34()) return true; return false; } - private boolean jj_3R_27() { + private boolean jj_3R_26() { if (jj_3R_33()) return true; return false; } - private boolean jj_3R_24() { + private boolean jj_3R_23() { Token xsp; xsp = jj_scanpos; - if (jj_3R_27()) { + if (jj_3R_26()) { jj_scanpos = xsp; - if (jj_3_4()) { + if (jj_3R_27()) { jj_scanpos = xsp; if (jj_3R_28()) { jj_scanpos = xsp; @@ -1299,17 +1302,17 @@ private boolean jj_3R_24() { return false; } - private boolean jj_3R_52() { - if (jj_3R_54()) return true; + private boolean jj_3R_53() { + if (jj_3R_55()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_57()) { jj_scanpos = xsp; break; } + if (jj_3R_58()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_46() { + private boolean jj_3R_47() { if (jj_3R_19()) return true; Token xsp; while (true) { @@ -1319,48 +1322,48 @@ private boolean jj_3R_46() { return false; } - private boolean jj_3R_25() { + private boolean jj_3R_24() { if (jj_3R_30()) return true; return false; } - private boolean jj_3R_23() { + private boolean jj_3R_22() { if (jj_scan_token(LBRACKET)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_46()) jj_scanpos = xsp; + if (jj_3R_47()) jj_scanpos = xsp; xsp = jj_scanpos; if (jj_scan_token(51)) jj_scanpos = xsp; if (jj_scan_token(RBRACKET)) return true; return false; } - private boolean jj_3R_20() { - if (jj_3R_24()) return true; + private boolean jj_3R_19() { Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_25()) { jj_scanpos = xsp; break; } + xsp = jj_scanpos; + if (jj_3R_21()) { + jj_scanpos = xsp; + if (jj_3R_22()) return true; } return false; } - private boolean jj_3R_22() { - if (jj_3R_26()) return true; + private boolean jj_3R_21() { + if (jj_3R_25()) return true; return false; } - private boolean jj_3R_19() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_22()) { - jj_scanpos = xsp; + private boolean jj_3R_20() { if (jj_3R_23()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_24()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_55() { + private boolean jj_3R_56() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(27)) { @@ -1373,11 +1376,11 @@ private boolean jj_3R_55() { } } } - if (jj_3R_52()) return true; + if (jj_3R_53()) return true; return false; } - private boolean jj_3R_71() { + private boolean jj_3R_72() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(34)) { @@ -1393,37 +1396,37 @@ private boolean jj_3_1() { return false; } - private boolean jj_3R_50() { - if (jj_3R_52()) return true; + private boolean jj_3R_51() { + if (jj_3R_53()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_55()) { jj_scanpos = xsp; break; } + if (jj_3R_56()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_70() { + private boolean jj_3R_71() { if (jj_3R_20()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_71()) jj_scanpos = xsp; + if (jj_3R_72()) jj_scanpos = xsp; return false; } - private boolean jj_3R_69() { - if (jj_3R_70()) return true; + private boolean jj_3R_70() { + if (jj_3R_71()) return true; return false; } - private boolean jj_3R_53() { + private boolean jj_3R_54() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(28)) { jj_scanpos = xsp; if (jj_scan_token(31)) return true; } - if (jj_3R_50()) return true; + if (jj_3R_51()) return true; return false; } @@ -1432,119 +1435,125 @@ private boolean jj_3R_18() { return false; } - private boolean jj_3R_48() { - if (jj_3R_50()) return true; + private boolean jj_3R_49() { + if (jj_3R_51()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_53()) { jj_scanpos = xsp; break; } + if (jj_3R_54()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_68() { + private boolean jj_3R_69() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(56)) { jj_scanpos = xsp; if (jj_scan_token(57)) return true; } - if (jj_3R_58()) return true; + if (jj_3R_59()) return true; return false; } - private boolean jj_3R_67() { + private boolean jj_3R_68() { Token xsp; xsp = jj_scanpos; - if (jj_3R_68()) { + if (jj_3R_69()) { jj_scanpos = xsp; - if (jj_3R_69()) return true; + if (jj_3R_70()) return true; } return false; } - private boolean jj_3R_40() { + private boolean jj_3R_41() { if (jj_scan_token(COMMA)) return true; - if (jj_3R_26()) return true; + if (jj_3R_25()) return true; return false; } - private boolean jj_3R_51() { + private boolean jj_3R_52() { if (jj_scan_token(BIT_AND)) return true; - if (jj_3R_48()) return true; + if (jj_3R_49()) return true; return false; } - private boolean jj_3R_66() { + private boolean jj_3R_67() { if (jj_scan_token(DECR)) return true; if (jj_3R_20()) return true; return false; } - private boolean jj_3R_45() { - if (jj_3R_48()) return true; + private boolean jj_3R_46() { + if (jj_3R_49()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_51()) { jj_scanpos = xsp; break; } + if (jj_3R_52()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_65() { + private boolean jj_3R_66() { if (jj_scan_token(INCR)) return true; if (jj_3R_20()) return true; return false; } - private boolean jj_3R_49() { + private boolean jj_3R_50() { if (jj_scan_token(XOR)) return true; - if (jj_3R_45()) return true; + if (jj_3R_46()) return true; return false; } - private boolean jj_3R_38() { - if (jj_3R_26()) return true; + private boolean jj_3R_39() { + if (jj_3R_25()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_40()) { jj_scanpos = xsp; break; } + if (jj_3R_41()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_43() { - if (jj_3R_45()) return true; + private boolean jj_3R_44() { + if (jj_3R_46()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_49()) { jj_scanpos = xsp; break; } + if (jj_3R_50()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_63() { - if (jj_3R_67()) return true; + private boolean jj_3R_64() { + if (jj_3R_68()) return true; return false; } - private boolean jj_3R_21() { + private boolean jj_3R_34() { if (jj_scan_token(IDENTIFIER)) return true; if (jj_scan_token(LPAREN)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_38()) jj_scanpos = xsp; + if (jj_3R_39()) jj_scanpos = xsp; if (jj_scan_token(RPAREN)) return true; return false; } + private boolean jj_3R_63() { + if (jj_3R_67()) return true; + return false; + } + private boolean jj_3R_62() { if (jj_3R_66()) return true; return false; } - private boolean jj_3R_61() { - if (jj_3R_65()) return true; + private boolean jj_3R_48() { + if (jj_scan_token(BIT_OR)) return true; + if (jj_3R_44()) return true; return false; } @@ -1737,18 +1746,21 @@ private void jj_add_error_token(int kind, int pos) { for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + boolean exists = false; + for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + exists = true; int[] oldentry = (int[])(it.next()); if (oldentry.length == jj_expentry.length) { for (int i = 0; i < jj_expentry.length; i++) { if (oldentry[i] != jj_expentry[i]) { - continue jj_entries_loop; + exists = false; + break; } } - jj_expentries.add(jj_expentry); - break jj_entries_loop; + if (exists) break; } } + if (!exists) jj_expentries.add(jj_expentry); if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; } } diff --git a/src/robotinterface/algorithm/parser/decoder/DecoderTokenManager.java b/src/robotinterface/algorithm/parser/decoder/DecoderTokenManager.java index 9b9dc65..ac1483a 100644 --- a/src/robotinterface/algorithm/parser/decoder/DecoderTokenManager.java +++ b/src/robotinterface/algorithm/parser/decoder/DecoderTokenManager.java @@ -8,6 +8,7 @@ import robotinterface.algorithm.parser.parameterparser.Argument; import robotinterface.algorithm.parser.parameterparser.ParameterParser; import robotinterface.gui.panels.editor.EditorPanel; +import robotinterface.interpreter.Get; import robotinterface.gui.panels.robot.RobotControlPanel; import robotinterface.robot.device.Device; diff --git a/src/robotinterface/algorithm/parser/decoder/Function.jj b/src/robotinterface/algorithm/parser/decoder/Function.jj index a1b4dfc..cab067a 100644 --- a/src/robotinterface/algorithm/parser/decoder/Function.jj +++ b/src/robotinterface/algorithm/parser/decoder/Function.jj @@ -6,16 +6,772 @@ * * * - */ options { JAVA_UNICODE_ESCAPE = true; STATIC = false; //DEBUG_PARSER = true; } PARSER_BEGIN(Decoder) package robotinterface.algorithm.parser.decoder; import java.util.Stack; import org.nfunk.jep.JEP; import robotinterface.algorithm.parser.FunctionToken; import robotinterface.algorithm.procedure.*; import robotinterface.algorithm.parser.Parser; import robotinterface.algorithm.parser.parameterparser.Argument; import robotinterface.algorithm.parser.parameterparser.ParameterParser; import robotinterface.gui.panels.editor.EditorPanel; import robotinterface.gui.panels.robot.RobotControlPanel; import robotinterface.robot.device.Device; public class Decoder { private JEP jep = new JEP(); private boolean functionCall = false; private Procedure last = null; private Stack < Token > markStack = new Stack < Token > (); private Stack < String > varList = new Stack < String > (); private Block localBlock = null; public static void main(String [] args) throws ParseException { Decoder parser = new Decoder(System.in); Function f = parser.decode(); System.out.println(Parser.encode(f)); } private int mark() { markStack.push(token); return markStack.size(); } private String getString(int m) { while (markStack.size() > 1 && markStack.size() > m) { markStack.pop(); } String str = getString(); return str; } private void checkVar() throws ParseException { boolean error = true; if (varList.contains(token.toString())) { error = false; } for (Class < ? extends Device > c : RobotControlPanel.getAvailableDevices()) { String str = c.getSimpleName(); try { str = c.newInstance().getName(); } catch (Exception ex) {} if (str.equals(token.toString())) { error = false; break; } } jep.initSymTab(); // clear the contents of the function table - jep.addStandardConstants(); for (Object o : jep.getSymbolTable().keySet()) { if (o.toString().equals(token.toString())) { error = false; break; } } if (error) { throw new ParseException(token, new int [] [] {} , new String [] { "Variavel \"" + token.toString() + "\" não declarada" } ); } } private String getString() { if (markStack.isEmpty()) return null; Token mark = markStack.pop(); StringBuilder sb = new StringBuilder(); while (mark != token) { mark = mark.next; sb.append(' ').append(mark); } mark = null; if (sb.length() > 1) { //System.out.println("~ '" + sb.substring(1) + "'"); return sb.substring(1); } else { return ""; } } } PARSER_END(Decoder) SKIP : { " " | "\r" | "\t" | "\n" } TOKEN : /* COMMENTS */ { < COMMENT : "//" (~[ "\n", "\r" ])* ( "\n" | "\r" | "\r\n" ) > | < MULTICOMMENT : "/*" (~[ "*" ])* "*" ( "*" | ~[ "*", "/" ] (~[ "*" ])* "*" )* "/" > } TOKEN : /* RESERVED WORDS */ { < VARIABLE : "var" > | < FUNCTION : "func" > | < IF : "if" > | < ELSE : "else" > | < WHILE : "while" > | < BREAK : "break" > | < CONTINUE : "continue" > | < RETURN : "return" > } TOKEN : /* LITERALS */ { < INTEGER_LITERAL : < DECIMAL_LITERAL > ([ "l", "L" ])? | < HEX_LITERAL > ([ "l", "L" ])? | < OCTAL_LITERAL > ([ "l", "L" ])? > | < #DECIMAL_LITERAL : [ "1"-"9" ] ([ "0"-"9" ])* > | < #HEX_LITERAL : "0" [ "x", "X" ] ([ "0"-"9", "a"-"f", "A"-"F" ])+ > | < #OCTAL_LITERAL : "0" ([ "0"-"7" ])* > | < FLOATING_POINT_LITERAL : ([ "0"-"9" ])+ "." ([ "0"-"9" ])* (< EXPONENT >)? ([ "f", "F", "d", "D" ])? | "." ([ "0"-"9" ])+ (< EXPONENT >)? ([ "f", "F", "d", "D" ])? | ([ "0"-"9" ])+ < EXPONENT > ([ "f", "F", "d", "D" ])? | ([ "0"-"9" ])+ (< EXPONENT >)? [ "f", "F", "d", "D" ] > | < #EXPONENT : [ "e", "E" ] ([ "+", "-" ])? ([ "0"-"9" ])+ > | < STRING_LITERAL : "\"" ( (~[ "\"", "\\", "\n", "\r" ]) | ( "\\" ( [ "n", "t", "b", "r", "f", "\\", "'", "\"" ] | [ "0"-"7" ] ([ "0"-"7" ])? | [ "0"-"3" ] [ "0"-"7" ] [ "0"-"7" ] ) ) )* "\"" > } TOKEN : /* IDENTIFIERS */ { < IDENTIFIER : < LETTER > ( < LETTER > | < DIGIT > )* > | < #LETTER : [ "$", "A"-"Z", "_", "a"-"z", "À"-"Ö", "Ø"-"ö", "ø"-"ÿ", "Ā"-"῿", "぀"-"㆏", "㌀"-"㍿", "㐀"-"㴭", "一"-"鿿", "豈"-"﫿" ] > | < #DIGIT : [ "0"-"9", "٠"-"٩", "۰"-"۹", "०"-"९", "০"-"৯", "੦"-"੯", "૦"-"૯", "୦"-"୯", "௧"-"௯", "౦"-"౯", "೦"-"೯", "൦"-"൯", "๐"-"๙", "໐"-"໙", "၀"-"၉" ] > } /* OPERATORS */ TOKEN : { < ASSIGN : "=" > | < GT : ">" > | < LT : "<" > | < EQ : "==" > | < LE : "<=" > | < GE : ">=" > | < NE : "!=" > | < SC_OR : "||" > | < SC_AND : "&&" > | < INCR : "++" > | < DECR : "--" > | < PLUS : "+" > | < MINUS : "-" > | < STAR : "*" > | < SLASH : "/" > | < BIT_AND : "&" > | < BIT_OR : "|" > | < XOR : "^" > | < REM : "%" > } TOKEN : /* SEPARATORS */ { < LPAREN : "(" > | < RPAREN : ")" > | < LBRACE : "{" > | < RBRACE : "}" > | < LBRACKET : "[" > | < RBRACKET : "]" > | < SEMICOLON : ";" > | < COMMA : "," > | < DOT : "." > } Function decode() : { Token tFunction; String args; Block block; } { < FUNCTION > tFunction = < IDENTIFIER > args = arguments() { Function f = new Function(tFunction.image, args); } block(f, false) { return f; } } String arguments() : { String str; } { "(" { int m = mark(); } [ argumentList() ] { str = getString(m); } ")" { return str; } } void argumentList() : {} { < VARIABLE > simpleVariableDeclaration() ( "," < VARIABLE > simpleVariableDeclaration() )* } void simpleVariableDeclaration() : { Token newVar = null; } { newVar = < IDENTIFIER > ("[" "]")* [ "=" variableInitialization() ] { varList.push(newVar.toString()); } } void variableDeclaration() : {} { < VARIABLE > simpleVariableDeclaration() ( LOOKAHEAD(2) "," simpleVariableDeclaration() )* } void variableInitialization() : {} { expression() | //alterar para {}!! - "[" [ variableInitialization() ( LOOKAHEAD(2) "," variableInitialization() )* ] [ "," ] "]" } void assignment() : {} { PrimaryExpression() "=" variableInitialization() } void expression() : {} { LOOKAHEAD(PrimaryExpression() "=") assignment() | ConditionalOrExpression() } void ConditionalOrExpression() : {} { ConditionalAndExpression() ( "||" ConditionalAndExpression() )* } void ConditionalAndExpression() : {} { InclusiveOrExpression() ( "&&" InclusiveOrExpression() )* } void InclusiveOrExpression() : {} { ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )* } void ExclusiveOrExpression() : {} { AndExpression() ( "^" AndExpression() )* } void AndExpression() : {} { EqualityExpression() ( "&" EqualityExpression() )* } void EqualityExpression() : {} { RelationalExpression() ( ( "==" | "!=" ) RelationalExpression() )* } void RelationalExpression() : {} { ShiftExpression() ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )* } void ShiftExpression() : {} { AdditiveExpression() ( ( "<<" | ">>" | ">>>" ) AdditiveExpression() )* } void AdditiveExpression() : {} { MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* } void MultiplicativeExpression() : {} { UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* } void UnaryExpression() : {} { ( "+" | "-" ) UnaryExpression() | PreIncrementExpression() | PreDecrementExpression() | UnaryExpressionNotPlusMinus() } void PreIncrementExpression() : {} { "++" PrimaryExpression() } void PreDecrementExpression() : {} { "--" PrimaryExpression() } void UnaryExpressionNotPlusMinus() : {} { ( "~" | "!" ) UnaryExpression() | PostfixExpression() } void PostfixExpression() : {} { PrimaryExpression() [ "++" | "--" ] } void PrimaryExpression() : {} { primaryPrefix() ( primarySuffix() )* } void primaryPrefix() : {} { literal() | LOOKAHEAD(2) functionCall(localBlock) | < IDENTIFIER > { checkVar(); } | "(" expression() ")" } void literal() : {} { < INTEGER_LITERAL > | < FLOATING_POINT_LITERAL > | < STRING_LITERAL > } void primarySuffix() : {} { "[" expression() "]" | "." < IDENTIFIER > } void name() : {} { literal() | < IDENTIFIER > { checkVar(); } } void block(Block block, boolean add) : { if (add) { Block b = new Block(); block.add(b); block = b; } localBlock = block; } { "{" ( statement(block) )* "}" { last = null; } } void statement(Block block) : { int m = 0; boolean add = ( block != null && block.getClass() == Block.class ) ; } { block(block, add) | ";" | { m = mark(); } < COMMENT > - { //System.out.println("c:" + getString(m)); + */ +options +{ + JAVA_UNICODE_ESCAPE = true; + STATIC = false; + //DEBUG_PARSER = true; +} + +PARSER_BEGIN(Decoder) +package robotinterface.algorithm.parser.decoder; +import java.util.Stack; +import org.nfunk.jep.JEP; +import robotinterface.algorithm.parser.FunctionToken; +import robotinterface.algorithm.procedure.*; +import robotinterface.algorithm.parser.Parser; +import robotinterface.algorithm.parser.parameterparser.Argument; +import robotinterface.algorithm.parser.parameterparser.ParameterParser; +import robotinterface.gui.panels.editor.EditorPanel; +import robotinterface.interpreter.Get; +import robotinterface.gui.panels.robot.RobotControlPanel; +import robotinterface.robot.device.Device; + +public class Decoder +{ + private JEP jep = new JEP(); + + private boolean functionCall = false; + + private Procedure last = null; + + private Stack < Token > markStack = new Stack < Token > (); + + private Stack < String > varList = new Stack < String > (); + + private Block localBlock = null; + + public static void main(String [] args) throws ParseException + { + Decoder parser = new Decoder(System.in); + Function f = parser.decode(); + System.out.println(Parser.encode(f)); + } + + private int mark() + { + markStack.push(token); + return markStack.size(); + } + + private String getString(int m) + { + while (markStack.size() > 1 && markStack.size() > m) + { + markStack.pop(); + } + String str = getString(); + return str; + } + + private void checkVar() throws ParseException + { + boolean error = true; + if (varList.contains(token.toString())) + { + error = false; + } + for (Class < ? extends Device > c : RobotControlPanel.getAvailableDevices()) + { + String str = c.getSimpleName(); + try + { + str = c.newInstance().getName(); + } + catch (Exception ex) + {} + if (str.equals(token.toString())) + { + error = false; + break; + } + } + jep.initSymTab(); // clear the contents of the function table + jep.addStandardConstants(); + jep.addFunction("get", new Get()); + for (Object o : jep.getSymbolTable().keySet()) + { + if (o.toString().equals(token.toString())) + { + error = false; + break; + } + } + if (error) + { + throw new ParseException(token, new int [] [] + {} + , new String [] + { + "Variavel \"" + token.toString() + "\" não declarada" + } + ); + } + } + + private String getString() + { + if (markStack.isEmpty()) return null; + Token mark = markStack.pop(); + StringBuilder sb = new StringBuilder(); + while (mark != token) + { + mark = mark.next; + sb.append(' ').append(mark); + } + mark = null; + if (sb.length() > 1) + { + //System.out.println("~ '" + sb.substring(1) + "'"); + return sb.substring(1); + } + else + { + return ""; + } + } +} + +PARSER_END(Decoder) + +SKIP : +{ + " " +| "\r" +| "\t" +| "\n" +} + +TOKEN : /* COMMENTS */ +{ + < COMMENT : + "//" (~[ "\n", "\r" ])* + ( + "\n" + | "\r" + | "\r\n" + ) > +| < MULTICOMMENT : + "/*" (~[ "*" ])* "*" + ( + "*" + | ~[ "*", "/" ] (~[ "*" ])* "*" + )* + "/" > +} + +TOKEN : /* RESERVED WORDS */ +{ + < VARIABLE : "var" > +| < FUNCTION : "func" > +| < IF : "if" > +| < ELSE : "else" > +| < WHILE : "while" > +| < BREAK : "break" > +| < CONTINUE : "continue" > +| < RETURN : "return" > +} + +TOKEN : /* LITERALS */ +{ + < INTEGER_LITERAL : + < DECIMAL_LITERAL > ([ "l", "L" ])? + | < HEX_LITERAL > ([ "l", "L" ])? + | < OCTAL_LITERAL > ([ "l", "L" ])? > +| < #DECIMAL_LITERAL : [ "1"-"9" ] ([ "0"-"9" ])* > +| < #HEX_LITERAL : "0" [ "x", "X" ] ([ "0"-"9", "a"-"f", "A"-"F" ])+ > +| < #OCTAL_LITERAL : "0" ([ "0"-"7" ])* > +| < FLOATING_POINT_LITERAL : + ([ "0"-"9" ])+ "." ([ "0"-"9" ])* (< EXPONENT >)? ([ "f", "F", "d", "D" ])? + | "." ([ "0"-"9" ])+ (< EXPONENT >)? ([ "f", "F", "d", "D" ])? + | ([ "0"-"9" ])+ < EXPONENT > ([ "f", "F", "d", "D" ])? + | ([ "0"-"9" ])+ (< EXPONENT >)? [ "f", "F", "d", "D" ] > +| < #EXPONENT : [ "e", "E" ] ([ "+", "-" ])? ([ "0"-"9" ])+ > +| < STRING_LITERAL : + "\"" + ( + (~[ "\"", "\\", "\n", "\r" ]) + | + ( + "\\" + ( + [ "n", "t", "b", "r", "f", "\\", "'", "\"" ] + | [ "0"-"7" ] ([ "0"-"7" ])? + | [ "0"-"3" ] [ "0"-"7" ] [ "0"-"7" ] + ) + ) + )* + "\"" > +} + +TOKEN : /* IDENTIFIERS */ +{ + < IDENTIFIER : + < LETTER > + ( + < LETTER > + | < DIGIT > + )* > +| < #LETTER : [ "$", "A"-"Z", "_", "a"-"z", "À"-"Ö", "Ø"-"ö", "ø"-"ÿ", "Ā"-"῿", "぀"-"㆏", "㌀"-"㍿", "㐀"-"㴭", "一"-"鿿", "豈"-"﫿" ] > +| < #DIGIT : [ "0"-"9", "٠"-"٩", "۰"-"۹", "०"-"९", "০"-"৯", "੦"-"੯", "૦"-"૯", "୦"-"୯", "௧"-"௯", "౦"-"౯", "೦"-"೯", "൦"-"൯", "๐"-"๙", "໐"-"໙", "၀"-"၉" ] > +} + +/* OPERATORS */ +TOKEN : +{ + < ASSIGN : "=" > +| < GT : ">" > +| < LT : "<" > +| < EQ : "==" > +| < LE : "<=" > +| < GE : ">=" > +| < NE : "!=" > +| < SC_OR : "||" > +| < SC_AND : "&&" > +| < INCR : "++" > +| < DECR : "--" > +| < PLUS : "+" > +| < MINUS : "-" > +| < STAR : "*" > +| < SLASH : "/" > +| < BIT_AND : "&" > +| < BIT_OR : "|" > +| < XOR : "^" > +| < REM : "%" > +} + +TOKEN : /* SEPARATORS */ +{ + < LPAREN : "(" > +| < RPAREN : ")" > +| < LBRACE : "{" > +| < RBRACE : "}" > +| < LBRACKET : "[" > +| < RBRACKET : "]" > +| < SEMICOLON : ";" > +| < COMMA : "," > +| < DOT : "." > +} + +Function decode() : +{ + Token tFunction; + String args; + Block block; +} +{ + < FUNCTION > tFunction = < IDENTIFIER > args = arguments() + { + Function f = new Function(tFunction.image, args); + } + block(f, false) + { + return f; + } +} + +String arguments() : +{ + String str; +} +{ + "(" + { + int m = mark(); + } + [ argumentList() ] + { + str = getString(m); + } + ")" + { + return str; + } +} + +void argumentList() : +{} +{ + < VARIABLE > simpleVariableDeclaration() + ( + "," < VARIABLE > simpleVariableDeclaration() + )* +} + +void simpleVariableDeclaration() : +{ + Token newVar = null; +} +{ + newVar = < IDENTIFIER > ("[" "]")* [ "=" variableInitialization() ] + { + varList.push(newVar.toString()); + } +} + +void variableDeclaration() : +{} +{ + < VARIABLE > simpleVariableDeclaration() + ( + LOOKAHEAD(2) + "," simpleVariableDeclaration() + )* +} + +void variableInitialization() : +{} +{ + expression() +| //alterar para {}!! + "[" + [ + variableInitialization() + ( + LOOKAHEAD(2) + "," variableInitialization() + )* + ] + [ "," ] "]" +} + +void assignment() : +{} +{ + PrimaryExpression() "=" variableInitialization() +} + +void expression() : +{} +{ + LOOKAHEAD(PrimaryExpression() "=") + assignment() +| ConditionalOrExpression() +} + +void ConditionalOrExpression() : +{} +{ + ConditionalAndExpression() + ( + "||" ConditionalAndExpression() + )* +} + +void ConditionalAndExpression() : +{} +{ + InclusiveOrExpression() + ( + "&&" InclusiveOrExpression() + )* +} + +void InclusiveOrExpression() : +{} +{ + ExclusiveOrExpression() + ( + "|" ExclusiveOrExpression() + )* +} + +void ExclusiveOrExpression() : +{} +{ + AndExpression() + ( + "^" AndExpression() + )* +} + +void AndExpression() : +{} +{ + EqualityExpression() + ( + "&" EqualityExpression() + )* +} + +void EqualityExpression() : +{} +{ + RelationalExpression() + ( + ( + "==" + | "!=" + ) + RelationalExpression() + )* +} + +void RelationalExpression() : +{} +{ + ShiftExpression() + ( + ( + "<" + | ">" + | "<=" + | ">=" + ) + ShiftExpression() + )* +} + +void ShiftExpression() : +{} +{ + AdditiveExpression() + ( + ( + "<<" + | ">>" + | ">>>" + ) + AdditiveExpression() + )* +} + +void AdditiveExpression() : +{} +{ + MultiplicativeExpression() + ( + ( + "+" + | "-" + ) + MultiplicativeExpression() + )* +} + +void MultiplicativeExpression() : +{} +{ + UnaryExpression() + ( + ( + "*" + | "/" + | "%" + ) + UnaryExpression() + )* +} + +void UnaryExpression() : +{} +{ + ( + "+" + | "-" + ) + UnaryExpression() +| PreIncrementExpression() +| PreDecrementExpression() +| UnaryExpressionNotPlusMinus() +} + +void PreIncrementExpression() : +{} +{ + "++" PrimaryExpression() +} + +void PreDecrementExpression() : +{} +{ + "--" PrimaryExpression() +} + +void UnaryExpressionNotPlusMinus() : +{} +{ + ( + "~" + | "!" + ) + UnaryExpression() +| PostfixExpression() +} + +void PostfixExpression() : +{} +{ + PrimaryExpression() + [ + "++" + | "--" + ] +} + +void PrimaryExpression() : +{} +{ + primaryPrefix() + ( + primarySuffix() + )* +} + +void primaryPrefix() : +{} +{ + literal() +| LOOKAHEAD(< IDENTIFIER > "(") + functionCall(localBlock) +| < IDENTIFIER > + { + checkVar(); + } +| "(" expression() ")" +} + +void literal() : +{} +{ + < INTEGER_LITERAL > +| < FLOATING_POINT_LITERAL > +| < STRING_LITERAL > +} + +void primarySuffix() : +{} +{ + "[" expression() "]" +| "." < IDENTIFIER > +} + +void name() : +{} +{ + literal() +| < IDENTIFIER > + { + checkVar(); + } +} + +void block(Block block, boolean add) : +{ + if (add) + { + Block b = new Block(); + block.add(b); + block = b; + } + localBlock = block; +} +{ + "{" + ( + statement(block) + )* + "}" + { + last = null; + } +} + +void statement(Block block) : +{ + int m = 0; + boolean add = + ( + block != null && block.getClass() == Block.class + ) + ; +} +{ + block(block, add) +| ";" +| + { + m = mark(); + } + < COMMENT > + { + //System.out.println("c:" + getString(m)); block.add(new Comment(getString(m))); - } | { m = mark(); } < MULTICOMMENT > + } +| + { + m = mark(); + } + < MULTICOMMENT > { //System.out.println("mc:" + getString(m)); block.add(new Comment(getString(m))); - } | { m = mark(); } expression() ";" { if (block != null && !functionCall) { if (last == null || last.getClass() != Procedure.class) { last = new Procedure(getString(m)); block.add(last); } else { last.append(getString(m)); } } functionCall = false; } | ifStatement(block) | whileStatement(block) | < BREAK > ";" { block.add(new BreakLoop()); } | { m = mark(); } variableDeclaration() //alterar para statementExpression() para permitir a++ - { if (block != null) { if (last == null || last.getClass() != Procedure.class) { last = new Procedure(getString(m)); block.add(last); } else { last.append(getString(m)); } } } } void functionCall(Block block) : { int m = 0; Stack < Integer > argType = new Stack < Integer > (); Stack < String > argEx = new Stack < String > (); Token tmpToken; Token functionID; } { functionID = < IDENTIFIER > "(" [ { m = mark(); tmpToken = token; } expression() { argType.push(((tmpToken.next.image == token.image) ? token.kind : - 1)); argEx.push(getString(m)); } ( "," { m = mark(); tmpToken = token; } expression() { argType.push(((tmpToken.next.image == token.image) ? token.kind : - 1)); argEx.push(getString(m)); } )* ] { boolean error = true; for (FunctionToken ftoken : EditorPanel.getFunctionTokens()) { if (ftoken.getToken().equals(functionID.toString())) { Argument [ ] args = ParameterParser.parse(functionID.toString(), argType, argEx, - 1 /*ftoken.getParameters()*/, token); block.add(ftoken.createInstance(args)); //parameters = parameters.trim(); //block.add(ftoken.createInstance(parameters)); error = false; functionCall = true; last = null; break; } } jep.initFunTab(); // clear the contents of the function table - jep.addStandardFunctions(); for (Object o : jep.getFunctionTable().keySet()) { if (o.toString().equals(functionID.toString())) { error = false; break; } } if (error) { throw new ParseException(token, new int [ ] [ ] {} , new String [ ] { "Função \"" + functionID.toString() + "\" inválida" } ); } } ")" } void ifStatement(Block b) : { String ex; If i = new If(); last = i; Block bTrue = i.getBlockTrue(), bFalse = i.getBlockFalse(); } { < IF > "(" { int m = mark(); } expression() { ex = getString(m); } ")" block(bTrue, false) [ < ELSE > (block(bFalse, false) | ifStatement(bFalse)) ] { i.addLineArg(0, Argument.EXPRESSION, ex); b.add(i); localBlock = b; } } void whileStatement(Block b) : { While w = new While(); last = w; String ex; } { < WHILE > "(" { int m = mark(); } expression() { ex = getString(m); } ")" block(w, false) { - w.addLineArg(0, Argument.EXPRESSION, ex); b.add(w); localBlock = b; } } \ No newline at end of file + } +| + { + m = mark(); + } + expression() ";" + { + if (block != null && !functionCall) + { + if (last == null || last.getClass() != Procedure.class) + { + last = new Procedure(getString(m)); + block.add(last); + } + else + { + last.append(getString(m)); + } + } + functionCall = false; + } +| ifStatement(block) +| whileStatement(block) +| < BREAK > ";" + { + block.add(new BreakLoop()); + } +| + { + m = mark(); + } + variableDeclaration() //alterar para statementExpression() para permitir a++ + { + if (block != null) + { + if (last == null || last.getClass() != Procedure.class) + { + last = new Procedure(getString(m)); + block.add(last); + } + else + { + last.append(getString(m)); + } + } + } +} + +void functionCall(Block block) : +{ + int m = 0; + Stack < Integer > argType = new Stack < Integer > (); + Stack < String > argEx = new Stack < String > (); + Token tmpToken; + Token functionID; +} +{ + functionID = < IDENTIFIER > "(" + [ + { + m = mark(); + tmpToken = token; + } + expression() + { + argType.push(((tmpToken.next.image == token.image) ? token.kind : - 1)); + argEx.push(getString(m)); + } + ( + "," + { + m = mark(); + tmpToken = token; + } + expression() + { + argType.push(((tmpToken.next.image == token.image) ? token.kind : - 1)); + argEx.push(getString(m)); + } + )* + ] + { + boolean error = true; + for (FunctionToken ftoken : EditorPanel.getFunctionTokens()) + { + if (ftoken.getToken().equals(functionID.toString())) + { + Argument [ ] args = ParameterParser.parse(functionID.toString(), argType, argEx, - 1 /*ftoken.getParameters()*/, token); + block.add(ftoken.createInstance(args)); + //parameters = parameters.trim(); + //block.add(ftoken.createInstance(parameters)); + error = false; + functionCall = true; + last = null; + break; + } + } + jep.initFunTab(); // clear the contents of the function table + jep.addStandardFunctions(); + jep.addFunction("get", new Get()); + for (Object o : jep.getFunctionTable().keySet()) + { + if (o.toString().equals(functionID.toString())) + { + error = false; + break; + } + } + if (error) + { + throw new ParseException(token, new int [ ] [ ] + {} + , new String [ ] + { + "Função \"" + functionID.toString() + "\" inválida" + } + ); + } + } + ")" +} + +void ifStatement(Block b) : +{ + String ex; + If i = new If(); + last = i; + Block bTrue = i.getBlockTrue(), bFalse = i.getBlockFalse(); +} +{ + < IF > "(" + { + int m = mark(); + } + expression() + { + ex = getString(m); + } + ")" block(bTrue, false) [ < ELSE > (block(bFalse, false) | ifStatement(bFalse)) ] + { + i.addLineArg(0, Argument.EXPRESSION, ex); + b.add(i); + localBlock = b; + } +} + +void whileStatement(Block b) : +{ + While w = new While(); + last = w; + String ex; +} +{ + < WHILE > "(" + { + int m = mark(); + } + expression() + { + ex = getString(m); + } + ")" block(w, false) + { + w.addLineArg(0, Argument.EXPRESSION, ex); + b.add(w); + localBlock = b; + } +} diff --git a/src/robotinterface/drawable/DrawingPanel.java b/src/robotinterface/drawable/DrawingPanel.java index d51977f..d43e826 100644 --- a/src/robotinterface/drawable/DrawingPanel.java +++ b/src/robotinterface/drawable/DrawingPanel.java @@ -73,7 +73,7 @@ public class DrawingPanel extends JPanel implements KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, ActionListener, ComponentListener, GraphicObject { //outras constantes - public final double MIN_ZOOM = 0.5; + public final double MIN_ZOOM = 0.2; public final double MAX_ZOOM = 4.0; protected long PAINT_DELAY = 20; protected long NO_PAINT_DELAY = 100; diff --git a/src/robotinterface/gui/GUI.java b/src/robotinterface/gui/GUI.java index 233a269..8325b2d 100644 --- a/src/robotinterface/gui/GUI.java +++ b/src/robotinterface/gui/GUI.java @@ -1672,7 +1672,7 @@ private void mainTabbedPaneMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRS }//GEN-LAST:event_mainTabbedPaneMouseMoved private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed - keyboardShortcutsButtonActionPerformed(null); + keyboardShortcutsButtonActionPerformed(null); }//GEN-LAST:event_jMenuItem4ActionPerformed private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed @@ -1832,6 +1832,9 @@ public static void main(String args[]) { path = path.substring(0, path.lastIndexOf('/') + 1); path += "natives/" + JniNamer.os() + "/" + JniNamer.arch(); + String defaultPath = System.getProperty("java.library.path"); + System.out.println("Carregando algo do tipo: \"" + JniNamer.getJniName("librxtxSerial") + "\""); + try { String newPath = path; /* @@ -1846,11 +1849,21 @@ public static void main(String args[]) { * something like OpenJDK Runtime Environment (build 1.6.0_0-b11), * try installing the official Sun JDK and see if that works. */ -// setLibraryPath(newPath); -// System.loadLibrary("rxtxSerial"); + setLibraryPath(newPath); + System.loadLibrary("rxtxSerial"); + System.out.println("Biblioteca librxtxSerial." + JniNamer.extension(JniNamer.os()) + " carregada com sucesso em " + path); } catch (Error | Exception e) { // e.printStackTrace(); - System.exit(0); + System.out.println("Falha ao caregar librxtxSerial." + JniNamer.extension(JniNamer.os()) + " em " + path); + try { + setLibraryPath(defaultPath); + System.loadLibrary("rxtxSerial"); + System.out.println("Biblioteca librxtxSerial." + JniNamer.extension(JniNamer.os()) + " carregada com sucesso em " + defaultPath); + } catch (Error | Exception e2) { + e.printStackTrace(); + System.out.println("Falha ao caregar librxtxSerial." + JniNamer.extension(JniNamer.os()) + " em " + defaultPath); + e2.printStackTrace(); + } } /* Set the Nimbus look and feel */ diff --git a/src/robotinterface/interpreter/ForceInterruptionException.java b/src/robotinterface/interpreter/ForceInterruptionException.java new file mode 100644 index 0000000..7cbf4fc --- /dev/null +++ b/src/robotinterface/interpreter/ForceInterruptionException.java @@ -0,0 +1,34 @@ +/** + * @file .java + * @author Anderson Antunes + * *seu nome* <*seu email*> + * @version 1.0 + * + * @section LICENSE + * + * Copyright (C) 2013 by Anderson Antunes + * *seu nome* <*seu email*> + * + * RobotInterface is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * RobotInterface is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * RobotInterface. If not, see . + * + */ +package robotinterface.interpreter; + + +public class ForceInterruptionException extends ExecutionException { + + public ForceInterruptionException() { + super("ForceInterruptionException"); + } +} diff --git a/src/robotinterface/interpreter/Get.java b/src/robotinterface/interpreter/Get.java new file mode 100644 index 0000000..1588793 --- /dev/null +++ b/src/robotinterface/interpreter/Get.java @@ -0,0 +1,62 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package robotinterface.interpreter; + +import java.util.Stack; +import java.util.Vector; +import org.nfunk.jep.ParseException; +import org.nfunk.jep.function.PostfixMathCommand; + +/** + * + * @author antunes + */ +public class Get extends PostfixMathCommand { + + public Get() { + numberOfParameters = 2; + } + + @Override + public void run(Stack s) throws ParseException { + checkStack(s);// check the stack + Object rhs = s.pop(); + Object lhs = s.pop(); + if (!(lhs instanceof Vector || lhs instanceof String)) { + throw new ParseException("Get: lhs must be an instance of Vector or String"); + } + + if (rhs instanceof Number) { + int index = ((Number) rhs).intValue(); + Object val = null; + if (lhs instanceof Vector) { + val = ((Vector) lhs).elementAt(index - 1); + } else if (lhs instanceof String) { + val = "" + (((String) lhs).toCharArray()[index - 1]); + } + + s.push(val); + return; + } + if (rhs instanceof Vector) { + Vector vec = (Vector) rhs; + if (vec.size() != 1) { + throw new ParseException("Get: only single dimension arrays supported in JEP"); + } + Object val = null; + int index = ((Number) vec.firstElement()).intValue(); + if (lhs instanceof Vector) { + val = ((Vector) lhs).elementAt(index - 1); + } else if (lhs instanceof String) { + val = "" + (((String) lhs).toCharArray()[index - 1]); + } + s.push(val); + return; + + } + throw new ParseException("Get: only single dimension arrays supported in JEP"); + } +} diff --git a/src/robotinterface/interpreter/Interpreter.java b/src/robotinterface/interpreter/Interpreter.java index 15338f2..6132295 100644 --- a/src/robotinterface/interpreter/Interpreter.java +++ b/src/robotinterface/interpreter/Interpreter.java @@ -73,6 +73,7 @@ public class Interpreter extends Thread { public Interpreter() { super("Interpreter"); parser = new JEP(); + parser.addFunction("get", new Get()); clock = new Clock(); resourceManager = new ResourceManager(); @@ -113,6 +114,7 @@ public void reset() { } parser.setAllowAssignment(true); + parser.addFunction("get", new Get()); if (robot != null && robot.getMainConnection() != null) { robot.stopAll(); robot.stop(); @@ -207,6 +209,8 @@ public boolean step() { } currentCmd = currentCmd.step(resourceManager); + } catch (ForceInterruptionException e) { + return false; } catch (ExecutionException e) { //GUI.print("Erro: " + e.getMessage()); errorCmd = currentCmd; @@ -215,6 +219,7 @@ public boolean step() { int PromptResult = JOptionPane.showOptionDialog(null, msg, "Erro", JOptionPane.NO_OPTION, JOptionPane.ERROR_MESSAGE, null, ObjButtons, ObjButtons[1]); if (PromptResult == JOptionPane.NO_OPTION) { JOptionPane.showMessageDialog(null, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); } System.err.println(e.getMessage()); return false; diff --git a/src/robotinterface/plugin/cmdpack/begginer/KeyboardInput.java b/src/robotinterface/plugin/cmdpack/begginer/KeyboardInput.java new file mode 100644 index 0000000..8fa10ee --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/KeyboardInput.java @@ -0,0 +1,224 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package robotinterface.plugin.cmdpack.begginer; + +import java.awt.Color; +import java.awt.Polygon; +import java.awt.Shape; +import java.awt.geom.Area; +import java.awt.geom.GeneralPath; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import javax.swing.JComboBox; +import javax.swing.JOptionPane; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import org.fife.ui.autocomplete.Completion; +import org.fife.ui.autocomplete.CompletionProvider; +import org.fife.ui.autocomplete.FunctionCompletion; +import org.nfunk.jep.JEP; +import robotinterface.algorithm.parser.FunctionToken; +import robotinterface.algorithm.parser.parameterparser.Argument; +import robotinterface.algorithm.procedure.Procedure; +import robotinterface.drawable.GraphicObject; +import robotinterface.drawable.swing.DrawableProcedureBlock; +import robotinterface.drawable.swing.MutableWidgetContainer; +import robotinterface.drawable.swing.component.Component; +import robotinterface.drawable.swing.component.SubLineBreak; +import robotinterface.drawable.swing.component.TextLabel; +import robotinterface.drawable.swing.component.Widget; +import robotinterface.drawable.swing.component.WidgetLine; +import robotinterface.drawable.util.QuickFrame; +import robotinterface.gui.panels.sidepanel.Classifiable; +import robotinterface.gui.panels.sidepanel.Item; +import robotinterface.interpreter.ExecutionException; +import robotinterface.interpreter.ForceInterruptionException; +import robotinterface.interpreter.ResourceManager; +import robotinterface.util.trafficsimulator.Clock; +import robotinterface.util.trafficsimulator.Timer; + +/** + * + * @author antunes + */ +public class KeyboardInput extends Procedure implements FunctionToken { + + private static Color myColor = Color.decode("#996622"); + private Argument arg0; + private Argument arg1; + + public KeyboardInput() { + arg0 = new Argument("", Argument.SINGLE_VARIABLE); + arg1 = new Argument("", Argument.TEXT); + } + + private KeyboardInput(Argument[] args) { + this(); + arg0.set(args[0]); + if (args.length > 1) { + arg1.set(args[1]); + } + } + + @Override + public void begin(ResourceManager rm) throws ExecutionException { + JEP parser = rm.getResource(JEP.class); + arg0.parse(parser); + String message = arg1.getStringValue(); + String result = JOptionPane.showInputDialog(null, (message.isEmpty()) ? "Insira um valor:" : message, "Entrada", JOptionPane.QUESTION_MESSAGE); + if (result == null || result.isEmpty()) { + throw new ForceInterruptionException(); + } + if (!arg0.getVariableName().isEmpty()) { + execute(arg0.getVariableName() + " = " + result, rm); + } + } + + @Override + public Item getItem() { + Area myShape = new Area(); + Polygon tmpShape = new Polygon(); + tmpShape.addPoint(4, 0); + tmpShape.addPoint(16,0); + tmpShape.addPoint(12,16); + tmpShape.addPoint(0,16); + myShape.add(new Area(tmpShape)); + + tmpShape.reset(); + tmpShape.addPoint(6, 4); + tmpShape.addPoint(12, 4); + tmpShape.addPoint(10, 12); + tmpShape.addPoint(4, 12); + myShape.subtract(new Area(tmpShape)); + return new Item("Entrada", myShape, myColor, "Mantém o robô se movendo ou faz o programa esperar por alguns milissegundos"); + } + + @Override + public Object createInstance() { + return new KeyboardInput(); + } + + @Override + public Completion getInfo(CompletionProvider provider) { + FunctionCompletion fc = new FunctionCompletion(provider, "kin(v);", null); + fc.setShortDescription("..."); + return fc; + } + + @Override + public String getToken() { + return "kin"; + } + + @Override + public void toString(String ident, StringBuilder sb) { + if (!arg1.getStringValue().isEmpty()) { + setProcedure("kin(" + arg0 + ",\"" + arg1 + "\")"); + } else { + setProcedure("kin(" + arg0 + ")"); + } + super.toString(ident, sb); + } + + private GraphicObject resource = null; + + @Override + public GraphicObject getDrawableResource() { + if (resource == null) { + resource = createDrawableMove(this); + } + return resource; + } + + public static MutableWidgetContainer createDrawableMove(final KeyboardInput k) { + + //HEADER LINE + final WidgetLine headerLine = new WidgetLine() { + @Override + public void createRow(Collection components, final MutableWidgetContainer container, int index) { + components.add(new TextLabel("Entrada:", true)); + components.add(new SubLineBreak()); + JComboBox comboboxVar = new JComboBox(); + MutableWidgetContainer.setAutoFillComboBox(comboboxVar, k, false); + Widget wcomboboxvar = new Widget(comboboxVar, 100, 25); + components.add(new TextLabel("Variavel:")); + components.add(wcomboboxvar); + container.entangle(k.arg0, wcomboboxvar); + components.add(new SubLineBreak()); + createGenericField(k, k.arg1, "Texto:", 130, 25, components, container, WidgetLine.ARG_TEXTFIELD); + components.add(new SubLineBreak(true)); + } + + @Override + public void toString(StringBuilder sb, ArrayList arguments, MutableWidgetContainer container) { + sb.append("kin("); + sb.append(arguments.get(0)); + + String text = arguments.get(1).getStringValue(); + + if (!text.isEmpty()) { + sb.append(",\"").append(text).append("\""); + } + sb.append(")"); + } + }; + + DrawableProcedureBlock dcb = new DrawableProcedureBlock(k, myColor) { + private GeneralPath myShape = new GeneralPath(); + + { + super.shapeStartX = 10; + } + + @Override + public void updateStructure() { + clear(); + addLine(headerLine); + boxLabel = getBoxLabel(); + } + + @Override + public Shape updateShape(Rectangle2D bounds) { + double w = bounds.getWidth(); + double h = bounds.getHeight(); + + int x = 10; + + myShape.reset(); + myShape.moveTo(x, 0); + myShape.lineTo(w + 2 * x, 0); + myShape.lineTo(w + x, h); + myShape.lineTo(0, h); + myShape.closePath(); + + return myShape; + } + }; + + return dcb; + } + + @Override + public Procedure copy(Procedure copy) { + super.copy(copy); + if (copy instanceof KeyboardInput) { + ((KeyboardInput) copy).arg0.set(arg0); + ((KeyboardInput) copy).arg1.set(arg1); + } + return copy; + } + + @Override + public int getParameters() { + return -2; + } + + @Override + public KeyboardInput createInstance(Argument[] args) { + KeyboardInput w = new KeyboardInput(args); + return w; + } +} diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/JavaCharStream.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/JavaCharStream.java new file mode 100644 index 0000000..cadfaff --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/JavaCharStream.java @@ -0,0 +1,617 @@ +/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 5.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package robotinterface.plugin.cmdpack.low.decoder; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (with java-like unicode escape processing). + */ + +public +class JavaCharStream +{ + /** Whether parser is static. */ + public static final boolean staticFlag = false; + + static final int hexval(char c) throws java.io.IOException { + switch(c) + { + case '0' : + return 0; + case '1' : + return 1; + case '2' : + return 2; + case '3' : + return 3; + case '4' : + return 4; + case '5' : + return 5; + case '6' : + return 6; + case '7' : + return 7; + case '8' : + return 8; + case '9' : + return 9; + + case 'a' : + case 'A' : + return 10; + case 'b' : + case 'B' : + return 11; + case 'c' : + case 'C' : + return 12; + case 'd' : + case 'D' : + return 13; + case 'e' : + case 'E' : + return 14; + case 'f' : + case 'F' : + return 15; + } + + throw new java.io.IOException(); // Should never come here + } + +/** Position in buffer. */ + public int bufpos = -1; + int bufsize; + int available; + int tokenBegin; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] nextCharBuf; + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int nextCharInd = -1; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + bufpos += (bufsize - tokenBegin); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + bufpos -= tokenBegin; + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + available = (bufsize += 2048); + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + int i; + if (maxNextCharInd == 4096) + maxNextCharInd = nextCharInd = 0; + + try { + if ((i = inputStream.read(nextCharBuf, maxNextCharInd, + 4096 - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + if (bufpos != 0) + { + --bufpos; + backup(0); + } + else + { + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + throw e; + } + } + + protected char ReadByte() throws java.io.IOException + { + if (++nextCharInd >= maxNextCharInd) + FillBuff(); + + return nextCharBuf[nextCharInd]; + } + +/** @return starting character for token. */ + public char BeginToken() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + tokenBegin = bufpos; + return buffer[bufpos]; + } + + tokenBegin = 0; + bufpos = -1; + + return readChar(); + } + + protected void AdjustBuffSize() + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = 0; + available = tokenBegin; + } + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + char c; + + if (++bufpos == available) + AdjustBuffSize(); + + if ((buffer[bufpos] = c = ReadByte()) == '\\') + { + UpdateLineColumn(c); + + int backSlashCnt = 1; + + for (;;) // Read all the backslashes + { + if (++bufpos == available) + AdjustBuffSize(); + + try + { + if ((buffer[bufpos] = c = ReadByte()) != '\\') + { + UpdateLineColumn(c); + // found a non-backslash char. + if ((c == 'u') && ((backSlashCnt & 1) == 1)) + { + if (--bufpos < 0) + bufpos = bufsize - 1; + + break; + } + + backup(backSlashCnt); + return '\\'; + } + } + catch(java.io.IOException e) + { + // We are returning one backslash so we should only backup (count-1) + if (backSlashCnt > 1) + backup(backSlashCnt-1); + + return '\\'; + } + + UpdateLineColumn(c); + backSlashCnt++; + } + + // Here, we have seen an odd number of backslash's followed by a 'u' + try + { + while ((c = ReadByte()) == 'u') + ++column; + + buffer[bufpos] = c = (char)(hexval(c) << 12 | + hexval(ReadByte()) << 8 | + hexval(ReadByte()) << 4 | + hexval(ReadByte())); + + column += 4; + } + catch(java.io.IOException e) + { + throw new Error("Invalid escape character at line " + line + + " column " + column + "."); + } + + if (backSlashCnt == 1) + return c; + else + { + backup(backSlashCnt - 1); + return '\\'; + } + } + else + { + UpdateLineColumn(c); + return c; + } + } + + @Deprecated + /** + * @deprecated + * @see #getEndColumn + */ + public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + public int getLine() { + return bufline[bufpos]; + } + +/** Get end column. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + +/** Get end line. */ + public int getEndLine() { + return bufline[bufpos]; + } + +/** @return column of token start */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + +/** @return line number of token start */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Retreat. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + +/** Constructor. */ + public JavaCharStream(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + +/** Constructor. */ + public JavaCharStream(java.io.Reader dstream, + int startline, int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + +/** Constructor. */ + public JavaCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } +/** Reinitialise. */ + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + nextCharInd = bufpos = -1; + } + +/** Reinitialise. */ + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + +/** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + } + +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + +/** Constructor. */ + public JavaCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + +/** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + + /** @return token image as String */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** @return suffix */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Set buffers back to null when finished. */ + public void Done() + { + nextCharBuf = null; + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} +/* JavaCC - OriginalChecksum=e6f7ffe5ce0de33147f8a1aa34ba2067 (do not edit this line) */ diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/ParseException.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/ParseException.java new file mode 100644 index 0000000..20f77b6 --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/ParseException.java @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package robotinterface.plugin.cmdpack.low.decoder; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=f338b3dcede02d37cd21271fc6c4c457 (do not edit this line) */ diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.java new file mode 100644 index 0000000..de4ed98 --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.java @@ -0,0 +1,634 @@ +/* Generated By:JavaCC: Do not edit this line. SendBytesArgumentDecoder.java */ +package robotinterface.plugin.cmdpack.low.decoder; + +import java.nio.ByteBuffer; +import java.util.Vector; +import java.math.BigInteger; +import org.nfunk.jep.JEP; + +/** Simple brace matcher. */ +public class SendBytesArgumentDecoder implements SendBytesArgumentDecoderConstants { + + final public Object decode(ByteBuffer msg, JEP parser) throws ParseException { + Object o; + o = expression(parser); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 17: + o = suffix(o, parser, msg); + break; + default: + jj_la1[0] = jj_gen; + ; + } + if (o instanceof String){ + //System.out.println("string:" + o); + parser.parseExpression((String) o); + o = parser.getValueAsObject(); + //System.out.println("result:" + o); + } + {if (true) return o;} + throw new Error("Missing return statement in function"); + } + + final private String expression(JEP parser) throws ParseException { + boolean invertBytes = false; + String statement = ""; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 16: + jj_consume_token(16); + invertBytes = true; + break; + default: + jj_la1[1] = jj_gen; + ; + } + statement = evaluableThing(); + parser.parseExpression(statement); + Object value = parser.getValueAsObject(); + StringBuilder sb = new StringBuilder(); + if (invertBytes){ + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + sb.append("[").append(d).append("]"); + } else if (value instanceof String) { + sb.append("["); + boolean first = true; + char [] array = ((String)value).toCharArray(); + for (int i = array.length-1; i >= 0; i--){ + char c = array[i]; + if (first){ + sb.append(((byte)c)); + first = false; + } else { + sb.append(",").append(((byte)c)); + } + } + sb.append("]"); + } else if (value instanceof Vector) { + Vector v = (Vector) value; + sb.append("["); + boolean first = true; + for (int i = v.size()-1; i >= 0; i--){ + if (first){ + sb.append(v.get(i)); + first = false; + } else { + sb.append(",").append(v.get(i)); + } + } + sb.append("]"); + } else { + //System.out.println("ND:" + value); + {if (true) return "";} + } + //System.out.println("-:" + value + " -> '" + sb.toString()+ "'"); + {if (true) return sb.toString();} + } else { + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + sb.append("[").append(d).append("]"); + } else if (value instanceof String) { + sb.append("["); + boolean first = true; + for (char c : ((String)value).toCharArray()){ + if (first){ + sb.append(((byte)c)); + first = false; + } else { + sb.append(",").append(((byte)c)); + } + } + sb.append("]"); + } else { + sb.append("[").append(statement).append("]"); + } + //System.out.println("p:" + statement + " -> " + sb.toString()); + {if (true) return sb.toString();} + } + throw new Error("Missing return statement in function"); + } + + final private String evaluableThing() throws ParseException { + String statement = ""; + Token t; + Object o; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + statement = literal(); + {if (true) return statement;} + break; + case LBRACE: + statement = codeExpression(); + {if (true) return statement;} + break; + case 17: + jj_consume_token(17); + StringBuilder sb = new StringBuilder(); + sb.append("["); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LBRACE: + case 17: + statement = evaluableThing(); + sb.append(statement); + label_1: + while (true) { + if (jj_2_1(2)) { + ; + } else { + break label_1; + } + jj_consume_token(18); + statement = evaluableThing(); + sb.append(",").append(statement); + } + break; + default: + jj_la1[2] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + jj_consume_token(18); + break; + default: + jj_la1[3] = jj_gen; + ; + } + jj_consume_token(19); + sb.append("]"); + {if (true) return sb.toString();} + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + final private String literal() throws ParseException { + Token t; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + t = jj_consume_token(INTEGER_LITERAL); + {if (true) return t.image;} + break; + case STRING_LITERAL: + t = jj_consume_token(STRING_LITERAL); + {if (true) return t.image;} + break; + case IDENTIFIER: + t = jj_consume_token(IDENTIFIER); + {if (true) return t.image;} + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + final private Object suffix(Object o, JEP parser, ByteBuffer msg) throws ParseException { + String statement = ""; + int a = 0, b = 8; + Object value; + jj_consume_token(17); + statement = evaluableThing(); + parser.parseExpression(statement); + value = parser.getValueAsObject(); + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + a = (int) d; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + jj_consume_token(18); + statement = evaluableThing(); + parser.parseExpression(statement); + value = parser.getValueAsObject(); + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + b = (int) d; + } + break; + default: + jj_la1[6] = jj_gen; + ; + } + jj_consume_token(19); + double d = 0; + //System.out.println("Parsing:" + o); + parser.parseExpression(o.toString()); + o = parser.getValueAsObject(); + if (o instanceof Number) { + d = ((Number) o).doubleValue(); + } else if (o instanceof Vector){ + Vector v = (Vector) o; + if (v.size() > a){ + o = v.get(a); + if (o instanceof Number) { + d = ((Number) o).doubleValue(); + } + } + } + //System.out.println("d:" + d); + + int umax = (int)Math.pow(2,b); + int min = (int)-Math.pow(2,b-1); + int max = (int)Math.pow(2,b-1)-1; + + if (d >= 0){ + while(d > max){ + d -= umax; + } + } else { + while(d < min){ + d += umax; + } + } + + //System.out.println("cast["+b+":"+max+","+min+"]:" + d); + + BigInteger bi = new BigInteger("" + ((long)d), 10); + //System.out.println("bi:" + bi); + byte[] array = bi.toByteArray(); + //for (int i = 0; i < array.length; i++){ + //System.out.println(i+":" + array[i]); + //} + if (a >= 0 && a < array.length){ + {if (true) return (Byte) array[a];} + } else { + {if (true) return (Byte) array[0];} + } + throw new Error("Missing return statement in function"); + } + + final private String codeExpression() throws ParseException { + Token t; + jj_consume_token(LBRACE); + t = jj_consume_token(RBRACE); + {if (true) return t.image.substring(0, t.image.length() - 1);} + throw new Error("Missing return statement in function"); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_3R_5() { + if (jj_scan_token(17)) return true; + return false; + } + + private boolean jj_3R_4() { + if (jj_3R_7()) return true; + return false; + } + + private boolean jj_3R_10() { + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + private boolean jj_3R_2() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_3()) { + jj_scanpos = xsp; + if (jj_3R_4()) { + jj_scanpos = xsp; + if (jj_3R_5()) return true; + } + } + return false; + } + + private boolean jj_3R_3() { + if (jj_3R_6()) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_scan_token(18)) return true; + if (jj_3R_2()) return true; + return false; + } + + private boolean jj_3R_9() { + if (jj_scan_token(STRING_LITERAL)) return true; + return false; + } + + private boolean jj_3R_7() { + if (jj_scan_token(LBRACE)) return true; + return false; + } + + private boolean jj_3R_6() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_8()) { + jj_scanpos = xsp; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_3R_10()) return true; + } + } + return false; + } + + private boolean jj_3R_8() { + if (jj_scan_token(INTEGER_LITERAL)) return true; + return false; + } + + /** Generated Token Manager. */ + public SendBytesArgumentDecoderTokenManager token_source; + JavaCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[7]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x20000,0x10000,0x22620,0x40000,0x22620,0x620,0x40000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[1]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public SendBytesArgumentDecoder(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public SendBytesArgumentDecoder(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new SendBytesArgumentDecoderTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public SendBytesArgumentDecoder(java.io.Reader stream) { + jj_input_stream = new JavaCharStream(stream, 1, 1); + token_source = new SendBytesArgumentDecoderTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public SendBytesArgumentDecoder(SendBytesArgumentDecoderTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(SendBytesArgumentDecoderTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + boolean exists = false; + for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + exists = true; + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + exists = false; + break; + } + } + if (exists) break; + } + } + if (!exists) jj_expentries.add(jj_expentry); + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[20]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 7; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.jj b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.jj new file mode 100644 index 0000000..9fd71dd --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoder.jj @@ -0,0 +1,326 @@ + +options { + JAVA_UNICODE_ESCAPE = true; + STATIC = false; + DEBUG_PARSER = false; +} + +PARSER_BEGIN(SendBytesArgumentDecoder) +package robotinterface.plugin.cmdpack.low.decoder; + +import java.nio.ByteBuffer; +import java.util.Vector; +import java.math.BigInteger; +import org.nfunk.jep.JEP; + +/** Simple brace matcher. */ +public class SendBytesArgumentDecoder { + + +} + +PARSER_END(SendBytesArgumentDecoder) + + +SKIP : +{ + " " +| "\r" +| "\t" +| "\n" +} + +TOKEN : /* LITERALS */ +{ + < INTEGER_LITERAL : + < DECIMAL_LITERAL > ([ "l", "L" ])? + | < HEX_LITERAL > ([ "l", "L" ])? + | < OCTAL_LITERAL > ([ "l", "L" ])? > +| < #DECIMAL_LITERAL : [ "1"-"9" ] ([ "0"-"9" ])* > +| < #HEX_LITERAL : "0" [ "x", "X" ] ([ "0"-"9", "a"-"f", "A"-"F" ])+ > +| < #OCTAL_LITERAL : "0" ([ "0"-"7" ])* > +| < STRING_LITERAL : + "\"" + ( + (~[ "\"", "\\", "\n", "\r" ]) + | + ( + "\\" + ( + [ "n", "t", "b", "r", "f", "\\", "'", "\"" ] + | [ "0"-"7" ] ([ "0"-"7" ])? + | [ "0"-"3" ] [ "0"-"7" ] [ "0"-"7" ] + ) + ) + )* + "\"" > +} + +TOKEN : /* IDENTIFIERS */ +{ + < IDENTIFIER : + < LETTER > + ( + < LETTER > + | < DIGIT > + )* > +| < #LETTER : [ "$", "A"-"Z", "_", "a"-"z", "À"-"Ö", "Ø"-"ö", "ø"-"ÿ", "Ā"-"῿", "぀"-"㆏", "㌀"-"㍿", "㐀"-"㴭", "一"-"鿿", "豈"-"﫿" ] > +| < #DIGIT : [ "0"-"9", "٠"-"٩", "۰"-"۹", "०"-"९", "০"-"৯", "੦"-"੯", "૦"-"૯", "୦"-"୯", "௧"-"௯", "౦"-"౯", "೦"-"೯", "൦"-"൯", "๐"-"๙", "໐"-"໙", "၀"-"၉" ] > +} + +TOKEN : +{ + < LBRACE : "{" > : STATEWUT +} + + TOKEN : +{ + < RBRACE : "}" > : DEFAULT +} + + MORE : +{ + < ANYTHING : (~["}"]) > +} + +public Object decode (ByteBuffer msg, JEP parser) : +{ + Object o; +} +{ + o = expression(parser) [ o = suffix(o, parser, msg) ] + { + if (o instanceof String){ + //System.out.println("string:" + o); + parser.parseExpression((String) o); + o = parser.getValueAsObject(); + //System.out.println("result:" + o); + } + return o; + } +} + + +private String expression (JEP parser) : +{ + boolean invertBytes = false; + String statement = ""; +} +{ + [ + "-" + { + invertBytes = true; + } + ] + statement = evaluableThing() + { + parser.parseExpression(statement); + Object value = parser.getValueAsObject(); + StringBuilder sb = new StringBuilder(); + if (invertBytes){ + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + sb.append("[").append(d).append("]"); + } else if (value instanceof String) { + sb.append("["); + boolean first = true; + char [] array = ((String)value).toCharArray(); + for (int i = array.length-1; i >= 0; i--){ + char c = array[i]; + if (first){ + sb.append(((byte)c)); + first = false; + } else { + sb.append(",").append(((byte)c)); + } + } + sb.append("]"); + } else if (value instanceof Vector) { + Vector v = (Vector) value; + sb.append("["); + boolean first = true; + for (int i = v.size()-1; i >= 0; i--){ + if (first){ + sb.append(v.get(i)); + first = false; + } else { + sb.append(",").append(v.get(i)); + } + } + sb.append("]"); + } else { + //System.out.println("ND:" + value); + return ""; + } + //System.out.println("-:" + value + " -> '" + sb.toString()+ "'"); + return sb.toString(); + } else { + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + sb.append("[").append(d).append("]"); + } else if (value instanceof String) { + sb.append("["); + boolean first = true; + for (char c : ((String)value).toCharArray()){ + if (first){ + sb.append(((byte)c)); + first = false; + } else { + sb.append(",").append(((byte)c)); + } + } + sb.append("]"); + } else { + sb.append("[").append(statement).append("]"); + } + //System.out.println("p:" + statement + " -> " + sb.toString()); + return sb.toString(); + } + } +} + +private String evaluableThing() : +{ + String statement = ""; + Token t; + Object o; +} +{ + statement = literal() + { + return statement; + } +| statement = codeExpression() + { + return statement; + } +| "[" + { + StringBuilder sb = new StringBuilder(); + sb.append("["); + } + [ + statement = evaluableThing() + { + sb.append(statement); + } + ( + LOOKAHEAD(2) + "," statement = evaluableThing() + { + sb.append(",").append(statement); + } + )* + ] + [ "," ] "]" + { + sb.append("]"); + return sb.toString(); + } +} + +private String literal() : +{ + Token t; +} +{ + t = < INTEGER_LITERAL > + { + return t.image; + } +| t = < STRING_LITERAL > + { + return t.image; + } +| t = < IDENTIFIER > + { + return t.image; + } +} + +private Object suffix(Object o, JEP parser, ByteBuffer msg) : +{ + String statement = ""; + int a = 0, b = 8; + Object value; +} +{ + "[" statement = evaluableThing() + { + parser.parseExpression(statement); + value = parser.getValueAsObject(); + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + a = (int) d; + } + } + [ "," statement = evaluableThing() + { + parser.parseExpression(statement); + value = parser.getValueAsObject(); + if (value instanceof Number) { + double d = ((Number) value).doubleValue(); + b = (int) d; + } + } + ] "]" + { + double d = 0; + //System.out.println("Parsing:" + o); + parser.parseExpression(o.toString()); + o = parser.getValueAsObject(); + if (o instanceof Number) { + d = ((Number) o).doubleValue(); + } else if (o instanceof Vector){ + Vector v = (Vector) o; + if (v.size() > a){ + o = v.get(a); + if (o instanceof Number) { + d = ((Number) o).doubleValue(); + } + } + } + //System.out.println("d:" + d); + + int umax = (int)Math.pow(2,b); + int min = (int)-Math.pow(2,b-1); + int max = (int)Math.pow(2,b-1)-1; + + if (d >= 0){ + while(d > max){ + d -= umax; + } + } else { + while(d < min){ + d += umax; + } + } + + //System.out.println("cast["+b+":"+max+","+min+"]:" + d); + + BigInteger bi = new BigInteger("" + ((long)d), 10); + //System.out.println("bi:" + bi); + byte[] array = bi.toByteArray(); + //for (int i = 0; i < array.length; i++){ + //System.out.println(i+":" + array[i]); + //} + if (a >= 0 && a < array.length){ + return (Byte) array[a]; + } else { + return (Byte) array[0]; + } + + } +} + +private String codeExpression() : +{ + Token t; +} +{ + < LBRACE > t = < RBRACE > + { + return t.image.substring(0, t.image.length() - 1); + } +} diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderConstants.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderConstants.java new file mode 100644 index 0000000..9c74b0b --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderConstants.java @@ -0,0 +1,65 @@ +/* Generated By:JavaCC: Do not edit this line. SendBytesArgumentDecoderConstants.java */ +package robotinterface.plugin.cmdpack.low.decoder; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface SendBytesArgumentDecoderConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int INTEGER_LITERAL = 5; + /** RegularExpression Id. */ + int DECIMAL_LITERAL = 6; + /** RegularExpression Id. */ + int HEX_LITERAL = 7; + /** RegularExpression Id. */ + int OCTAL_LITERAL = 8; + /** RegularExpression Id. */ + int STRING_LITERAL = 9; + /** RegularExpression Id. */ + int IDENTIFIER = 10; + /** RegularExpression Id. */ + int LETTER = 11; + /** RegularExpression Id. */ + int DIGIT = 12; + /** RegularExpression Id. */ + int LBRACE = 13; + /** RegularExpression Id. */ + int RBRACE = 14; + /** RegularExpression Id. */ + int ANYTHING = 15; + + /** Lexical state. */ + int DEFAULT = 0; + /** Lexical state. */ + int STATEWUT = 1; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\r\"", + "\"\\t\"", + "\"\\n\"", + "", + "", + "", + "", + "", + "", + "", + "", + "\"{\"", + "\"}\"", + "", + "\"-\"", + "\"[\"", + "\",\"", + "\"]\"", + }; + +} diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderTokenManager.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderTokenManager.java new file mode 100644 index 0000000..5b4e4b0 --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/SendBytesArgumentDecoderTokenManager.java @@ -0,0 +1,632 @@ +/* Generated By:JavaCC: Do not edit this line. SendBytesArgumentDecoderTokenManager.java */ +package robotinterface.plugin.cmdpack.low.decoder; +import java.nio.ByteBuffer; +import java.util.Vector; +import java.math.BigInteger; +import org.nfunk.jep.JEP; + +/** Token Manager. */ +public class SendBytesArgumentDecoderTokenManager implements SendBytesArgumentDecoderConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 44: + return jjStopAtPos(0, 18); + case 45: + return jjStopAtPos(0, 16); + case 91: + return jjStopAtPos(0, 17); + case 93: + return jjStopAtPos(0, 19); + case 123: + return jjStopAtPos(0, 13); + default : + return jjMoveNfa_0(0, 0); + } +} +static final long[] jjbitVec0 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec2 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec3 = { + 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L +}; +static final long[] jjbitVec4 = { + 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec5 = { + 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec6 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L +}; +static final long[] jjbitVec7 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L +}; +static final long[] jjbitVec8 = { + 0x3fffffffffffL, 0x0L, 0x0L, 0x0L +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 18; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 5) + kind = 5; + jjCheckNAddTwoStates(1, 2); + } + else if (curChar == 48) + { + if (kind > 5) + kind = 5; + jjCheckNAddStates(0, 2); + } + else if (curChar == 36) + { + if (kind > 10) + kind = 10; + jjCheckNAdd(13); + } + else if (curChar == 34) + jjCheckNAddStates(3, 5); + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 5) + kind = 5; + jjCheckNAddTwoStates(1, 2); + break; + case 3: + if (curChar == 34) + jjCheckNAddStates(3, 5); + break; + case 4: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddStates(3, 5); + break; + case 6: + if ((0x8400000000L & l) != 0L) + jjCheckNAddStates(3, 5); + break; + case 7: + if (curChar == 34 && kind > 9) + kind = 9; + break; + case 8: + if ((0xff000000000000L & l) != 0L) + jjCheckNAddStates(6, 9); + break; + case 9: + if ((0xff000000000000L & l) != 0L) + jjCheckNAddStates(3, 5); + break; + case 10: + if ((0xf000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 11: + if ((0xff000000000000L & l) != 0L) + jjCheckNAdd(9); + break; + case 12: + if (curChar != 36) + break; + if (kind > 10) + kind = 10; + jjCheckNAdd(13); + break; + case 13: + if ((0x3ff001000000000L & l) == 0L) + break; + if (kind > 10) + kind = 10; + jjCheckNAdd(13); + break; + case 14: + if (curChar != 48) + break; + if (kind > 5) + kind = 5; + jjCheckNAddStates(0, 2); + break; + case 16: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 5) + kind = 5; + jjCheckNAddTwoStates(16, 2); + break; + case 17: + if ((0xff000000000000L & l) == 0L) + break; + if (kind > 5) + kind = 5; + jjCheckNAddTwoStates(17, 2); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 13: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 10) + kind = 10; + jjCheckNAdd(13); + break; + case 2: + if ((0x100000001000L & l) != 0L && kind > 5) + kind = 5; + break; + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddStates(3, 5); + break; + case 5: + if (curChar == 92) + jjAddStates(10, 12); + break; + case 6: + if ((0x14404410000000L & l) != 0L) + jjCheckNAddStates(3, 5); + break; + case 15: + if ((0x100000001000000L & l) != 0L) + jjCheckNAdd(16); + break; + case 16: + if ((0x7e0000007eL & l) == 0L) + break; + if (kind > 5) + kind = 5; + jjCheckNAddTwoStates(16, 2); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 13: + if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) + break; + if (kind > 10) + kind = 10; + jjCheckNAdd(13); + break; + case 4: + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) + jjAddStates(3, 5); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 18 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +private final int jjStopStringLiteralDfa_1(int pos, long active0) +{ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_1(int pos, long active0) +{ + return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1); +} +private int jjMoveStringLiteralDfa0_1() +{ + switch(curChar) + { + case 125: + return jjStopAtPos(0, 14); + default : + return jjMoveNfa_1(0, 0); + } +} +private int jjMoveNfa_1(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 1; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + kind = 15; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0xdfffffffffffffffL & l) != 0L) + kind = 15; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 15) + kind = 15; + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 15, 17, 2, 4, 5, 7, 4, 5, 9, 7, 6, 8, 10, +}; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec4[i2] & l2) != 0L); + case 48: + return ((jjbitVec5[i2] & l2) != 0L); + case 49: + return ((jjbitVec6[i2] & l2) != 0L); + case 51: + return ((jjbitVec7[i2] & l2) != 0L); + case 61: + return ((jjbitVec8[i2] & l2) != 0L); + default : + if ((jjbitVec3[i1] & l1) != 0L) + return true; + return false; + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, null, null, null, null, null, +"\173", null, null, "\55", "\133", "\54", "\135", }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", + "STATEWUT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xf6621L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoMore = { + 0x8000L, +}; +protected JavaCharStream input_stream; +private final int[] jjrounds = new int[18]; +private final int[] jjstateSet = new int[36]; +protected char curChar; +/** Constructor. */ +public SendBytesArgumentDecoderTokenManager(JavaCharStream stream){ + if (JavaCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public SendBytesArgumentDecoderTokenManager(JavaCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(JavaCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 18; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(JavaCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 2 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + for (;;) + { + switch(curLexState) + { + case 0: + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + break; + case 1: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_1(); + break; + } + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + return matchedToken; + } + else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + continue EOFLoop; + } + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + curPos = 0; + jjmatchedKind = 0x7fffffff; + try { + curChar = input_stream.readChar(); + continue; + } + catch (java.io.IOException e1) { } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } + } +} + +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/Token.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/Token.java new file mode 100644 index 0000000..5b1501d --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/Token.java @@ -0,0 +1,131 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package robotinterface.plugin.cmdpack.low.decoder; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=d41d07e73e9291faac9a0c91a184d2b4 (do not edit this line) */ diff --git a/src/robotinterface/plugin/cmdpack/begginer/decoder/TokenMgrError.java b/src/robotinterface/plugin/cmdpack/begginer/decoder/TokenMgrError.java new file mode 100644 index 0000000..424dfec --- /dev/null +++ b/src/robotinterface/plugin/cmdpack/begginer/decoder/TokenMgrError.java @@ -0,0 +1,147 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* JavaCCOptions: */ +package robotinterface.plugin.cmdpack.low.decoder; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=3cb13a612fb737e41f709551b22b61c5 (do not edit this line) */ diff --git a/src/robotinterface/plugin/cmdpack/plugin.txt b/src/robotinterface/plugin/cmdpack/plugin.txt index 8bf5617..570e777 100644 --- a/src/robotinterface/plugin/cmdpack/plugin.txt +++ b/src/robotinterface/plugin/cmdpack/plugin.txt @@ -1,6 +1,7 @@ # Lista de Plugins # "robotinterface/plugin/cmdpack/plugin.txt" robotinterface.plugin.cmdpack.begginer.ReadDevice +robotinterface.plugin.cmdpack.begginer.KeyboardInput robotinterface.plugin.cmdpack.begginer.Move robotinterface.plugin.cmdpack.begginer.Rotate robotinterface.plugin.cmdpack.begginer.Wait diff --git a/src/robotinterface/plugin/cmdpack/util/PrintString.java b/src/robotinterface/plugin/cmdpack/util/PrintString.java index 7ff0558..2ebc62e 100644 --- a/src/robotinterface/plugin/cmdpack/util/PrintString.java +++ b/src/robotinterface/plugin/cmdpack/util/PrintString.java @@ -82,7 +82,7 @@ public void begin(ResourceManager rm) throws ExecutionException { arg = getArg(i); arg.parse(parser); if (parser.hasError()) { - throw new ExecutionException(parser.getErrorInfo() + " in \"" + arg.getStatement() + "\""); +// throw new ExecutionException(parser.getErrorInfo() + " in \"" + arg.getStatement() + "\""); } int padpi = out.indexOf(padps); //printAllDecimalPlacesIndex int ptdpi = out.indexOf(ptdps); //printTwoDecimalPlacesIndex