/** * Scans an external ID. * * @param f full flag * @param r root flag * @return id * @throws IOException I/O exception */ private byte[] externalID(final boolean f, final boolean r) throws IOException { byte[] cont = null; final boolean pub = consume(PUBLIC); if (pub || consume(SYSTEM)) { checkS(); if (pub) { pubidLit(); if (f) checkS(); } final int qu = consume(); // [11] if (qu == '\'' || qu == '"') { int ch; final TokenBuilder tok = new TokenBuilder(); while ((ch = nextChar()) != qu) tok.add(ch); if (!f) return null; final String name = string(tok.finish()); if (!dtd && r) return cont; final XMLInput tin = input; try { final IO file = input.io().merge(name); cont = file.read(); } catch (final IOException ex) { Util.debug(ex); // skip unknown DTDs/entities cont = new byte[] {'?'}; } input = new XMLInput(new IOContent(cont, name)); if (consume(XDECL)) { check(XML); s(); if (version()) checkS(); s(); if (encoding() == null) error(TEXTENC); ch = nextChar(); if (s(ch)) ch = nextChar(); if (ch != '?') error(WRONGCHAR, '?', ch); ch = nextChar(); if (ch != '>') error(WRONGCHAR, '>', ch); cont = Arrays.copyOfRange(cont, input.pos(), cont.length); } s(); if (r) { extSubsetDecl(); if (!consume((char) 0)) error(INVEND); } input = tin; } else { if (f) error(SCANQUOTE, (char) qu); prev(1); } } return cont; }
/** * Parses a module. * * @param io input reference * @return query parser * @throws QueryException query exception */ final QueryParser parseQuery(final IO io) throws QueryException { try (final QueryContext qctx = new QueryContext(qc)) { final String input = string(io.read()); // parse query final QueryParser qp = new QueryParser(input, io.path(), qctx, null); module = QueryProcessor.isLibrary(input) ? qp.parseLibrary(true) : qp.parseMain(); return qp; } catch (final IOException | QueryException ex) { throw IOERR_X.get(info, ex); } }
/** * Reads a stop words file. * * @param fl file reference * @return true if everything went alright */ public boolean read(final IO fl) { try { for (final byte[] sl : split(fl.read(), '\n')) { byte[] val = null; for (final byte[] st : split(normalize(sl), ' ')) { if (val == null) val = st; else put(st, val); } } return true; } catch (final IOException ex) { return false; } }
public void run() { try { int opCode; while (true) { opCode = programMemory.read(programCounter); programCounter++; ioSystem.displayRuntimeError("@" + (programCounter - 1) + ": "); switch (opCode) { case HALT: { this.ioSystem.displayProgramTermination(); return; } case PUSH: { expStack.push(programMemory.read(programCounter)); programCounter++; break; } case ADD: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(a + b); break; } case SUB: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(a - b); break; } case MUL: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(a * b); break; } case DIV: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(a / b); break; } case MOD: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(a % b); break; } case NEG: { int a = expStack.pop(); expStack.push(-a); break; } case LT: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b < a ? 0 : 1); break; } case LE: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b <= a ? 0 : 1); break; } case GT: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b > a ? 0 : 1); break; } case GE: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b >= a ? 0 : 1); break; } case EQ: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b == a ? 0 : 1); break; } case NE: { int a = expStack.pop(); int b = expStack.pop(); expStack.push(b != a ? 0 : 1); break; } case IN: { int a = ioSystem.read(); expStack.push(a); break; } case OUT: { ioSystem.write(expStack.pop()); break; } case CALL: { callStack.push(programCounter); break; } case RET: { programCounter = callStack.pop(); break; } case JP: { programCounter = programMemory.read(programCounter); break; } case JZ: { int a = expStack.pop(); if (a == 0) programCounter = a; break; } case DUP: { expStack.dup(); break; } case POP: { expStack.pop(); break; } default: { ioSystem.displayRuntimeError("Bad instruction"); return; } } } } catch (AddressOutOfBoundsException e) { ioSystem.displayRuntimeError("Adress out of bounds."); } catch (IOException e) { ioSystem.displayRuntimeError("Error with IO system."); } catch (StackOverflowException e) { ioSystem.displayRuntimeError("Stack overflow."); } catch (StackUnderflowException e) { ioSystem.displayRuntimeError("Stack underflow."); } }