public ReturnObject remove(int index) { ErrorMessage em = this.testBounds(index); if (em.toString() != "NO_ERROR") return new ReturnObjectImpl(em); if (index == 0) { ReturnObject result = this.object; if (this.next == null) { this.object = null; } else { this.object = this.next.getObject(); this.next = this.next.getNext(); } return result; } LinkedList current = this; LinkedList last = current; for (int i = 0; i < index; i++) { last = current; current = current.next; } last.next = current.next; return current.object; }
/** * Adds an element to the list, inserting it at the given position. The indeces of elements at and * after that position must be updated accordignly. * * <p>If the index is negative or greater or equal than the size of the list, then an appropriate * error must be returned. * * <p>If a null object is provided to insert in the list, the request must be ignored and an * appropriate error must be returned. * * @param index the position at which the item should be inserted in the list * @param item the value to insert into the list * @return an ReturnObject, empty if the operation is successful or containing an appropriate * error message otherwise */ public ReturnObject add(int index, Object item) { ErrorMessage error1; ReturnObject returnobj; if (item.equals(null)) { error1 = ErrorMessage.INVALID_ARGUMENT; } else if (index < 0 || index >= size_list) { error1 = ErrorMessage.INDEX_OUT_OF_BOUNDS; } else { error1 = ErrorMessage.NO_ERROR; } if (error1.equals(ErrorMessage.NO_ERROR)) { Element elem = startElement; for (int j = 0; j < index + 1; j++) { elem = elem.getNext(); } Element newElement = new Element(item); newElement.setNext(elem.getNext()); elem.setNext(newElement); size_list++; returnobj = new ReturnObjectImpl(item); } else { returnobj = new ReturnObjectImpl(error1); } return returnobj; }
/** {@inheritDoc} */ @Override public String getMessage() { if (errorMessages != null && errorMessages.length > 0) { final ErrorMessage errorMessage = errorMessages[0]; return "Error " + errorMessage.getCode() + " - " + errorMessage.getMessage(); } if (statusCode != -1) return getCause(statusCode); return super.getMessage(); }
public ReturnObject get(int index) { ErrorMessage em = this.testBounds(index); if (em.toString() != "NO_ERROR") return new ReturnObjectImpl(em); LinkedList current = this; for (int i = 0; i < index; i++) { current = current.next; } return current.object; }
/** * Returns a list with the elements in this list except the head. The elements must be in the same * order. The original list must not change or be affected by changes in the new list. * * <p>If the list is empty, another empty list is returned. */ public FunctionalList rest() { ErrorMessage error1 = errortype(0); FunctionalList list1 = new FunctionalLinkedList(); if (error1.equals(ErrorMessage.NO_ERROR)) { // list1.setList(this.getList()); list1.remove(0); return list1; } else { return list1; } }
public SyntaxTree SimpleExpr() throws java.io.IOException { SyntaxTree syntaxTree = null; if (token.symbol() == TokenClass.NIL || token.symbol() == TokenClass.INTEGER) { syntaxTree = Literal(); } else if (token.symbol() == TokenClass.LEFTPAREN) { // (Expr getToken(); syntaxTree = Expr(); if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print( ") expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); } else { if (token.symbol() != TokenClass.ID) { ErrorMessage.print( "ID expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } String tmpID = token.lexeme(); syntaxTree = new SyntaxTree(token.lexeme()); getToken(); if (token.symbol() == TokenClass.LEFTPAREN) { getToken(); // should be an optional ListExpr SyntaxTree tmp = ListExpr(); // followed by 0 or more list expr preceded by a comma while (token.symbol() == TokenClass.COMMA) { getToken(); // TODO check this tmp = new SyntaxTree(",", tmp, ListExpr()); } if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print( ") expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); syntaxTree = new SyntaxTree("APPLY", syntaxTree, tmp); return syntaxTree; } } return syntaxTree; }
/** * Returns the element at the beginning of the list. * * <p>If the list is empty, an appropriate error is returned. * * @return a copy of the element at the beginning of the list or an error if the list is empty. */ public ReturnObject head() { ErrorMessage error1 = errortype(0); ReturnObject returnobj; if (error1.equals(ErrorMessage.NO_ERROR)) { Element elem = startElement; returnobj = new ReturnObjectImpl(elem.getNext().returnObject()); } else { returnobj = new ReturnObjectImpl(error1); } return returnobj; }
/** * Returns the element at the given position. * * <p>If the index is negative or greater or equal than the size of the list, then an appropriate * error must be returned. * * @param index the position in the list of the item to be retrieved * @return the element or an appropriate error message, encapsulated in a ReturnObject */ public ReturnObject get(int index) { ErrorMessage error1 = errortype(index); ReturnObject returnobj; if (error1.equals(ErrorMessage.NO_ERROR)) { Element elem = startElement; for (int j = 0; j < index + 1; j++) { elem = elem.getNext(); } returnobj = new ReturnObjectImpl(elem.returnObject()); } else { returnobj = new ReturnObjectImpl(error1); } return returnobj; }
public void onException(ErrorMessage msg) throws MuleException { Class eClass = null; ExceptionHandler eh = null; try { eClass = msg.getException().toException().getClass(); eh = getHandler(eClass); eh.onException(msg); } catch (Exception e) { logger.error(e); if (eh instanceof DefaultHandler) { logger.error(LocaleMessage.defaultFatalHandling(FatalHandler.class)); handleFatal(e); } else if (eh instanceof FatalHandler) { logger.fatal(LocaleMessage.fatalHandling(e)); MuleServer.getMuleContext().dispose(); System.exit(-1); } else { logger.error(LocaleMessage.defaultHandling(DefaultHandler.class, eh, e)); handleDefault(msg, e); } } }
// compilationUnit parses MicroScala programs. public CompEnvironment CompilationUnit() throws java.io.IOException { CompEnvironment env; VariableEnvironment varEnv = null; String componentId; // object id { {Def} MainDef } // object if (token.symbol() != TokenClass.OBJECT) { ErrorMessage.print("object expected"); } getToken(); // id if (token.symbol() != TokenClass.ID) { ErrorMessage.print("id expected"); } componentId = token.lexeme(); env = new CompEnvironment(componentId); varEnv = new VariableEnvironment(componentId); getToken(); // { if (token.symbol() != TokenClass.LEFTBRACE) { ErrorMessage.print("Left Brace expected"); } getToken(); // one or more defs while (token.symbol() == TokenClass.DEF || token.symbol() == TokenClass.VAR) { if (token.symbol() == TokenClass.DEF) { Def(env); } else { VarDef(varEnv); } } // } if (token.symbol() != TokenClass.RIGHTBRACE) { ErrorMessage.print("Right BRACE Expected"); } getToken(); if (token.symbol() != TokenClass.EOF) { ErrorMessage.print("EOF expected"); } varEnv.print(); return env; }
public void addSequences() { JFileChooser choose = new JFileChooser("Add sequence(s)..."); choose.setCurrentDirectory(new File(System.getProperty("user.dir"))); if (choose.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { inFile = choose.getSelectedFile(); // System.out.println(inFile.toString().substring(inFile.toString().length()-3,inFile.toString().length())); if (!(inFile.toString().endsWith(".fasta") || inFile.toString().endsWith(".fas"))) { // ErrorMessage.showPane(this, "File is not a valid Fasta file.", true); // return; } FileFormatReader reader = new FastaReader(); try { manager.inputData.seqs.alphabet = ""; manager.inputData.seqs.add(reader.read(inFile)); manager.inputgui.updateSequences(); manager.fullPath = inFile.getAbsolutePath(); if (manager.inputData.model != null) { try { manager.inputData.model.acceptable(manager.inputData.seqs); } catch (RecognitionError e) { tryModels(); } } else { tryModels(); } if (manager.inputData.model != null) { runItem.setEnabled(true); runButton.setEnabled(true); if (!manager.inputData.seqs.isRNA()) { rnaButton.setEnabled(false); } else { rnaButton.setEnabled(true); RNAPopup.showPane(this); } } } catch (IOException e) { ErrorMessage.showPane(this, "An I/O error occured while reading input file.", true); } catch (ExceptionNonFasta e) { ErrorMessage.showPane( this, "The input sequences do not appear to be in Fasta format.", true); } } }
public String VarDef(VariableEnvironment env) throws java.io.IOException { String varId; Type varType; if (token.symbol() != TokenClass.VAR) { ErrorMessage.print( "Var expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.ID) { ErrorMessage.print( "ID expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } varId = token.lexeme(); getToken(); if (token.symbol() != TokenClass.COLON) { ErrorMessage.print( ": expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); varType = Type(); if (token.symbol() != TokenClass.ASSIGN) { ErrorMessage.print( "= expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); Literal(); if (token.symbol() != TokenClass.SEMICOLON) { ErrorMessage.print( "; expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); // TODO this needs to have the value of the var in the null spot, taken from the literal. env.update(varId, new ExpressibleValue(varType, null)); return varId; }
public SyntaxTree ListMethodCall() throws java.io.IOException { SyntaxTree syntaxTree = null; if (token.symbol() != TokenClass.PERIOD) { ErrorMessage.print(". expected, current token is " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.LISTOP) { ErrorMessage.print( "List Operand expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } syntaxTree = new SyntaxTree(token.lexeme()); getToken(); return syntaxTree; }
public SyntaxTree MulOper() throws java.io.IOException { SyntaxTree syntaxTree = null; if (token.symbol() != TokenClass.MULTOP) { ErrorMessage.print( "* or / expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } syntaxTree = new SyntaxTree(token.lexeme()); getToken(); return syntaxTree; }
/** * Returns the elements at the given position and removes it from the list. The indeces of * elements after the removed element must be updated accordignly. * * <p>If the index is negative or greater or equal than the size of the list, then an appropriate * error must be returned. * * @param index the position in the list of the item to be retrieved * @return the element or an appropriate error message, encapsulated in a ReturnObject */ public ReturnObject remove(int index) { ErrorMessage error1 = errortype(index); ReturnObject returnobj; if (error1.equals(ErrorMessage.NO_ERROR) && size_list > 0) { Element elem = startElement; // Element elem2=startElement; for (int j = 0; j < index + 1; j++) { elem = elem.getNext(); } elem.setNext(elem.getNext().getNext()); returnobj = new ReturnObjectImpl(elem.getNext().returnObject()); size_list--; } else { returnobj = new ReturnObjectImpl(error1); } return returnobj; }
public Type Type() throws java.io.IOException { if (token.symbol() == TokenClass.INT) { getToken(); return Type.INT; } else if (token.symbol() == TokenClass.LIST) { getToken(); if (token.symbol() != TokenClass.LEFTBRACKET) { ErrorMessage.print("[ expected"); } getToken(); if (token.symbol() != TokenClass.INT) { ErrorMessage.print("int expected"); } getToken(); if (token.symbol() != TokenClass.RIGHTBRACKET) { ErrorMessage.print("] expected"); } getToken(); return Type.LIST; } else { ErrorMessage.print("Type expected"); return null; } }
public SyntaxTree Literal() throws java.io.IOException { SyntaxTree syntaxTree = null; if (token.symbol() != TokenClass.INTEGER) { if (token.symbol() != TokenClass.NIL) { ErrorMessage.print("Integer expected"); } else { syntaxTree = new SyntaxTree("NIL"); getToken(); } } else { syntaxTree = new SyntaxTree(token.lexeme()); getToken(); } return syntaxTree; }
public static Optional<GameActionMessage> convertLine(String line) { if (line.startsWith(GameActionFormat.CHOSEN_MOVES_PREFIX)) { return Optional.of(ChosenMovesMessage.parse(line)); } else if (line.startsWith(GameActionFormat.GOALS_PREFIX)) { return Optional.of(GoalsMessage.parse(line)); } else if (line.startsWith(GameActionFormat.LEGAL_MOVES_PREFIX)) { return Optional.of(LegalMovesMessage.parse(line)); } else if (line.startsWith(GameActionFormat.ROLES_PREFIX)) { return Optional.of(RolesMessage.parse(line)); } else if (line.startsWith(GameActionFormat.TERMINAL_PREFIX)) { return Optional.of(TerminalityMessage.parse(line)); } else if (line.startsWith(GameActionFormat.ERROR_PREFIX)) { return Optional.of(ErrorMessage.parse(line)); } else if (line.startsWith(GameActionFormat.TEST_FINISHED_PREFIX)) { return Optional.of(GameActionMessage.endOfMessages()); } return Optional.empty(); }
public Message.Response execute(QueryState state) { try { if (options.getPageSize() == 0) throw new ProtocolException("The page size cannot be 0"); UUID tracingId = null; if (isTracingRequested()) { tracingId = UUIDGen.getTimeUUID(); state.prepareTracingSession(tracingId); } if (state.traceNextQuery()) { state.createTracingSession(); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("query", query); if (options.getPageSize() > 0) builder.put("page_size", Integer.toString(options.getPageSize())); Tracing.instance.begin("Execute CQL3 query", builder.build()); } Message.Response response = state.getClientState().getCQLQueryHandler().process(query, state, options); if (options.skipMetadata() && response instanceof ResultMessage.Rows) ((ResultMessage.Rows) response).result.metadata.setSkipMetadata(); if (tracingId != null) response.setTracingId(tracingId); return response; } catch (Exception e) { if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException))) logger.error("Unexpected error during query", e); return ErrorMessage.fromException(e); } finally { Tracing.instance.stopSession(); } }
public Message.Response execute(QueryState state) { try { UUID tracingId = null; if (isTracingRequested()) { tracingId = UUIDGen.getTimeUUID(); state.prepareTracingSession(tracingId); } if (state.traceNextQuery()) { state.createTracingSession(); Tracing.instance().begin("Preparing CQL3 query", ImmutableMap.of("query", query)); } Message.Response response = QueryProcessor.prepare(query, state.getClientState(), false); if (tracingId != null) response.setTracingId(tracingId); return response; } catch (Exception e) { return ErrorMessage.fromException(e); } finally { Tracing.instance().stopSession(); } }
public SyntaxTree Statement(VariableEnvironment env) throws java.io.IOException { SyntaxTree syntaxTree = null; if (token.symbol() == TokenClass.IF) { getToken(); if (token.symbol() != TokenClass.LEFTPAREN) { ErrorMessage.print("( expected, current token is " + token.lexeme()); } getToken(); SyntaxTree tmpExpr = Expr(); if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print(") expected, current token is " + token.lexeme()); } getToken(); SyntaxTree result1 = Statement(env); if (token.symbol() == TokenClass.ELSE) { getToken(); SyntaxTree result2 = Statement(env); syntaxTree = new SyntaxTree("IF", tmpExpr, result1, result2); } else { syntaxTree = new SyntaxTree("IF", tmpExpr, result1); } } else if (token.symbol() == TokenClass.WHILE) { getToken(); if (token.symbol() != TokenClass.LEFTPAREN) { ErrorMessage.print("( expected, current token is " + token.lexeme()); } getToken(); SyntaxTree tmpExpr = Expr(); if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print(") expected, current token is " + token.lexeme()); } getToken(); syntaxTree = new SyntaxTree("WHILE", tmpExpr, Statement(env)); } else if (token.symbol() == TokenClass.ID) { // TODO handle this assignment statement here. SyntaxTree tmpID = new SyntaxTree(token.lexeme()); String varID = token.lexeme(); getToken(); if (token.symbol() != TokenClass.ASSIGN) { ErrorMessage.print("= expected, current token is " + token.lexeme()); } getToken(); syntaxTree = new SyntaxTree("=", tmpID, ListExpr()); if (token.symbol() != TokenClass.SEMICOLON) { ErrorMessage.print("; expected, current token is " + token.lexeme()); } getToken(); // TODO fix this // env.update(varID, new ExpressibleValue (Type.INT, null)); } else if (token.symbol() == TokenClass.PRINTLN) { getToken(); if (token.symbol() != TokenClass.LEFTPAREN) { ErrorMessage.print("( expected, current token is " + token.lexeme()); } getToken(); SyntaxTree listExp = ListExpr(); syntaxTree = new SyntaxTree("PRINTLN", listExp); if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print(") expected, current token is " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.SEMICOLON) { ErrorMessage.print("; expected, current token is " + token.lexeme()); } getToken(); } else if (token.symbol() == TokenClass.LEFTBRACE) { getToken(); int stmtNum = 0; do { if (stmtNum == 0) { syntaxTree = Statement(env); stmtNum = 1; } else { syntaxTree = new SyntaxTree(";", syntaxTree, Statement(env)); } } while (token.symbol() == TokenClass.IF || token.symbol() == TokenClass.WHILE || token.symbol() == TokenClass.ID || token.symbol() == TokenClass.PRINTLN || token.symbol() == TokenClass.LEFTBRACE); if (token.symbol() != TokenClass.RIGHTBRACE) { ErrorMessage.print("} expected, current token is " + token.lexeme()); } getToken(); } else { ErrorMessage.print("Statement expected, current token is " + token.lexeme()); } return syntaxTree; }
/** * An ActioListener is implemented, so we have to implement this function. It handles actions on * the menu bar. */ @Override public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand() == "Add sequence(s)...") { addSequences(); } else if (ev.getActionCommand() == "Exit") { System.exit(0); } else if (ev.getActionCommand() == "Preferences...") { // System.out.println("here!!!"); op = new OutputPreferences(this); } else if (ev.getActionCommand() == "Settings") { mcmcSettingsDlg.display(this); } else if (ev.getActionCommand() == "Set up and run") { if (manager.inputData.seqs.sequences.size() < 2) { JOptionPane.showMessageDialog( this, "At least two sequences are needed!!!", "Not enough sequences", JOptionPane.ERROR_MESSAGE); // manager.finished(); return; } // disableAllButtons(); mcmcSettingsDlg.display(this); // start(); } else if (ev.getActionCommand() == "Pause") { pauseItem.setEnabled(false); pauseButton.setEnabled(false); resumeItem.setEnabled(true); resumeButton.setEnabled(true); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final String savTit = getTitle(); setTitle("Pausing..."); manager.thread.suspendSoft(); setTitle(savTit); setCursor(Cursor.getDefaultCursor()); } else if (ev.getActionCommand() == "Resume") { manager.thread.resumeSoft(); pauseItem.setEnabled(true); pauseButton.setEnabled(true); resumeItem.setEnabled(false); resumeButton.setEnabled(false); } else if (ev.getActionCommand() == "Stop") { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final String savTit = getTitle(); setTitle("Stopping..."); manager.thread.stopSoft(); finished(); setTitle(savTit); setCursor(Cursor.getDefaultCursor()); } else if (ev.getActionCommand() == "RNA mode") { if (rnaButton.isSelected()) { dlg = new RNASettingsDlg(this); dlg.display(this); // manager.inputgui = input.inputgui; // manager.inputgui.updateSequences(); // tab.addTab(input.getTabName(), input.getIcon(), input.getJPanel(), input.getTip()); manager.inputgui = input.inputgui; manager.inputgui.updateSequences(); // System.out.println("SELECTED!!!"); manager.postProcMan.rnaMode = true; // manager.postProcMan.reload(); int count = tab.getTabCount(); for (Postprocess plugin : pluginTabs) { // System.out.println(plugin.getTabName() + ": " + plugin.screenable); if (plugin.rnaAssociated) { tabPluginMap.put(count, plugin); tab.addTab(plugin.getTabName(), plugin.getIcon(), plugin.getJPanel(), plugin.getTip()); count++; } // manager.postProcMan.init(); } } else { manager.postProcMan.rnaMode = false; // System.out.println("NOT SELECTED!!!"); manager.inputgui = input.inputgui; manager.inputgui.updateSequences(); int count = 0; for (Postprocess plugin : pluginTabs) { if (plugin.rnaAssociated) { tabPluginMap.remove(plugin); String removePlugin = tab.getTitleAt(count + 1); tab.remove(count + 1); count--; } count++; } } } else if (ev.getActionCommand() == "About...") { new HelpWindow( this, "About", getClass().getClassLoader().getResource("doc/about/index.html"), false); } else if (ev.getActionCommand() == "Html doc for developers") { new HelpWindow( this, "Html doc for Developers", ClassLoader.getSystemResource("doc/index.html"), true); } else if (ev.getActionCommand() == "Description of plugins") { new HelpWindow( this, "Description of plugins", ClassLoader.getSystemResource("doc/plugin_description/index.html"), true); } else if (ev.getActionCommand() == "Help for users") { helpUsers(); } else { // new substitution model selected for (Class<? extends SubstitutionModel> cl : substModels) { try { if (ev.getActionCommand().equals(SubstitutionModel.getMenuName(cl))) { try { SubstitutionModel model = cl.newInstance(); model.acceptable(manager.inputData.seqs); manager.inputData.model = model; break; } catch (RecognitionError e) { selectModel(manager.inputData.model); JOptionPane.showMessageDialog( this, e.message, "Cannot apply this model...", JOptionPane.ERROR_MESSAGE); break; } } } catch (Exception e) { ErrorMessage.showPane(this, e, true); } } } }
public static ByteBuf encode(ErrorMessage errorMessage) throws UaException { return encode( MessageType.Error, (b) -> ErrorMessage.encode(errorMessage, b), Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN)); }
// Def public void Def(CompEnvironment env) throws java.io.IOException { SyntaxTree syntaxTree = null; String defID = ""; Type defType = null; DefDenot defDenot; ArrayList<String> parameterList = null; VariableEnvironment varEnv = null; if (token.symbol() != TokenClass.DEF) { ErrorMessage.print( "Def expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() == TokenClass.MAIN) { defID = "MAIN"; varEnv = new VariableEnvironment(defID); defType = Type.NULL; // this is a maindef getToken(); if (token.symbol() != TokenClass.LEFTPAREN) { ErrorMessage.print( "( expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); // time to get the args parameterList = new ArrayList<String>(); if (token.symbol() != TokenClass.ARGS) { ErrorMessage.print( "args expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.COLON) { ErrorMessage.print( ": expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.ARRAY) { ErrorMessage.print( "Array expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.LEFTBRACKET) { ErrorMessage.print( "[ expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.STRING) { ErrorMessage.print( "String expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.RIGHTBRACKET) { ErrorMessage.print( "] expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print( ") expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.LEFTBRACE) { ErrorMessage.print( "{ expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); while (token.symbol() == TokenClass.VAR) { VarDef(varEnv); } int stmtNum = 0; do { if (stmtNum == 0) { syntaxTree = Statement(varEnv); stmtNum++; } else { syntaxTree = new SyntaxTree(";", syntaxTree, Statement(varEnv)); } } while (token.symbol() == TokenClass.IF || token.symbol() == TokenClass.WHILE || token.symbol() == TokenClass.ID || token.symbol() == TokenClass.PRINTLN || token.symbol() == TokenClass.LEFTBRACE); if (token.symbol() != TokenClass.RIGHTBRACE) { ErrorMessage.print( "} expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); } else if (token.symbol() == TokenClass.ID) { defID = token.lexeme(); varEnv = new VariableEnvironment(defID); // normal def getToken(); if (token.symbol() != TokenClass.LEFTPAREN) { ErrorMessage.print( "( expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); parameterList = new ArrayList<String>(); if (token.symbol() == TokenClass.ID) { String varID = token.lexeme(); getToken(); if (token.symbol() != TokenClass.COLON) { ErrorMessage.print( ": expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); Type varType = Type(); varEnv.update(varID, new ExpressibleValue(varType, null)); while (token.symbol() == TokenClass.COMMA) { getToken(); if (token.symbol() != TokenClass.ID) { ErrorMessage.print( "ID expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } varID = token.lexeme(); getToken(); if (token.symbol() != TokenClass.COLON) { ErrorMessage.print( ": expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); varType = Type(); varEnv.update(varID, new ExpressibleValue(varType, null)); } if (token.symbol() != TokenClass.RIGHTPAREN) { ErrorMessage.print( ") expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.COLON) { ErrorMessage.print( ": expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); // TODO this is where the return value of the def is set defType = Type(); if (token.symbol() != TokenClass.ASSIGN) { ErrorMessage.print( "= expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.LEFTBRACE) { ErrorMessage.print( "{ expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); while (token.symbol() == TokenClass.VAR) { VarDef(varEnv); } int stmtNum = 0; while (token.symbol() == TokenClass.IF || token.symbol() == TokenClass.WHILE || token.symbol() == TokenClass.ID || token.symbol() == TokenClass.PRINTLN || token.symbol() == TokenClass.LEFTBRACE) { if (stmtNum == 0) { syntaxTree = Statement(varEnv); stmtNum++; } else { syntaxTree = new SyntaxTree(";", syntaxTree, Statement(varEnv)); stmtNum++; } } if (token.symbol() != TokenClass.RETURN) { ErrorMessage.print( "Return expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); // TODO fix this. syntaxTree = new SyntaxTree(";", syntaxTree, new SyntaxTree("RETURN", ListExpr())); if (token.symbol() != TokenClass.SEMICOLON) { ErrorMessage.print("; expected, current token is " + token.lexeme()); } getToken(); if (token.symbol() != TokenClass.RIGHTBRACE) { ErrorMessage.print( "} expected, current token is " + token.symbol() + " with the lexeme " + token.lexeme()); } getToken(); } } else { varEnv = new VariableEnvironment(defID); VarDef(varEnv); } defDenot = new DefDenot(parameterList, defType, varEnv, syntaxTree); env.update(defID, defDenot); // syntaxTree.print(defID); System.out.println(); System.out.println(); }
public boolean hasError() { return (errorMessage.equals(ErrorMessage.NO_ERROR) == false); }
public Response toResponse(MDMAPIException exception) { ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setErrorMessage(exception.getErrorMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); }