private Record readTestRecord(final StreamTokenizer stok) throws IOException { final Record rec = new Record(); final double[] vals; try { rec.poly1 = scanString(stok); } catch (final EOFException e) { return null; } rec.lineNumber = stok.lineno(); rec.poly2 = scanString(stok); rec.X21.scan("[%s]", stok); rec.X12.invert(rec.X21); final Vector pairList = new Vector(10); String s; rec.minDist = Double.POSITIVE_INFINITY; while (true) { s = scanString(stok); if (s.equals("P")) rec.promote = true; else if (s.equals("D")) rec.maxPairDist = TokenScanner.scanDouble(stok); else break; } while (!s.equals("*")) { final ClosestPointPair pair = new ClosestPointPair(); if (!s.equals("N")) { pair.feat1 = getDummyFeature(s, stok); pair.feat2 = getDummyFeature(scanString(stok), stok); final Point3dX p1 = new Point3dX(); p1.scan("[%v]", stok); pair.pnt1.set(p1); } final Vector3dX dir = new Vector3dX(); dir.scan("[%v]", stok); dir.normalize(); pair.nrml.set(dir); pair.dist = TokenScanner.scanDouble(stok); if (!s.equals("N")) pair.pnt2.scaleAdd(pair.dist, pair.nrml, pair.pnt1); if (pair.dist < rec.minDist) { rec.minDist = pair.dist; rec.minNrml = new Vector3d(pair.nrml); } pairList.add(pair); s = scanString(stok); } rec.basePairs = (ClosestPointPair[]) pairList.toArray(new ClosestPointPair[0]); rec.testPairs = new ClosestPointPair[rec.basePairs.length]; for (int i = 0; i < rec.testPairs.length; i++) rec.testPairs[i] = new ClosestPointPair(rec.basePairs[i]); return rec; }
// Parse the input words stream into corresponding statement public Statement parseStatement(TokenScanner scanner) { String token = scanner.nextToken(); if (token.equals("PRINT")) { return new PrintStmt(scanner); } if (token.equals("LET")) { return new LetStmt(scanner); } if (token.equals("INPUT")) { return new InputStmt(scanner); } if (token.equals("GOTO")) { return new GoToStmt(scanner); } if (token.equals("IF")) { return new IfStmt(scanner); } if (token.equals("END")) { return new EndStmt(scanner); } if (token.equals("REM")) { return new RemStmt(scanner); } System.out.println("Not a legal statement"); return null; }
public Expression parseExp(TokenScanner scanner) { Expression exp = readE(scanner, 0); if (scanner.hasMoreTokens()) { System.out.println("Unexpected token"); } return exp; }
// gbufferedimage.setRGB(x, y, rgb); public void execute(TokenScanner paramTokenScanner, JavaBackEnd paramJavaBackEnd) { paramTokenScanner.verifyToken("("); String id = nextString(paramTokenScanner); paramTokenScanner.verifyToken(","); int x = nextInt(paramTokenScanner); paramTokenScanner.verifyToken(","); int y = nextInt(paramTokenScanner); paramTokenScanner.verifyToken(","); int rgb = nextInt(paramTokenScanner); paramTokenScanner.verifyToken(")"); GObject gobj = paramJavaBackEnd.getGObject(id); if (gobj != null && gobj instanceof GBufferedImage) { GBufferedImage img = (GBufferedImage) gobj; img.setRGB(x, y, rgb); } }
public Expression readT(TokenScanner scanner) { String token = scanner.nextToken(); if (token.charAt(0) >= 'A' && token.charAt(0) <= 'Z' || token.charAt(0) >= 'a' && token.charAt(0) <= 'z') { return new IdentifierExp(token); } else if (token.charAt(0) >= '0' && token.charAt(0) <= '9') { return new ConstantExp(Integer.parseInt(token)); } if (!token.equals("(")) { System.out.println("Unexpected token"); } Expression exp = readE(scanner, 0); if (!scanner.nextToken().equals(")")) { System.out.println("Unbalanced parentheses"); } return exp; }
public Expression readE(TokenScanner scanner, int prec) { Expression exp = readT(scanner); String token = null; while (true) { token = scanner.nextToken(); int tprec = precedence(token); if (tprec <= prec) { break; } Expression rhs = readE(scanner, tprec); exp = new CompoundExp(token, exp, rhs); } if (token != null) { scanner.saveToken(token); } return exp; }