home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.vrml;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.StreamTokenizer;
- import java.util.Vector;
-
- public class Parser {
- private StreamTokenizer _st;
-
- public Object parse() throws IOException, SyntaxError {
- return this.parseNode();
- }
-
- private Object parseRotation() throws IOException, SyntaxError {
- double var1 = (double)50.0F;
- double var3 = (double)0.0F;
- double var5 = (double)0.0F;
- double var7 = (Math.PI / 2D);
-
- while(true) {
- this._st.nextToken();
- if (this._st.ttype == 125) {
- double var9 = Math.sqrt(var1 * var1 + var3 * var3 + var5 * var5);
- var1 /= var9;
- var3 /= var9;
- var5 /= var9;
- return new Rotation((double)0.0F, (double)0.0F, (double)0.0F, var1, var3, var5, var7);
- }
-
- if (this._st.ttype != -3) {
- throw new SyntaxError("missing field name");
- }
-
- if (!this._st.sval.equals("rotation")) {
- throw new SyntaxError("invalid field name: " + this._st.sval);
- }
-
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var1 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var3 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var5 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var7 = this._st.nval;
- }
- }
-
- private Object parseSeparator() throws IOException, SyntaxError {
- Vector var1 = new Vector();
-
- while(true) {
- this._st.nextToken();
- if (this._st.ttype == 125) {
- return var1;
- }
-
- this._st.pushBack();
- var1.addElement(this.parseNode());
- }
- }
-
- public Parser(InputStream var1) {
- this._st = new StreamTokenizer(var1);
- }
-
- private Object parseTranslation() throws IOException, SyntaxError {
- double var1 = (double)50.0F;
- double var3 = (double)0.0F;
- double var5 = (double)0.0F;
-
- while(true) {
- this._st.nextToken();
- if (this._st.ttype == 125) {
- return new Translation(var1, var3, var5);
- }
-
- if (this._st.ttype != -3) {
- throw new SyntaxError("missing field name");
- }
-
- if (!this._st.sval.equals("translation")) {
- throw new SyntaxError("invalid field name: " + this._st.sval);
- }
-
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var1 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var3 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var5 = this._st.nval;
- }
- }
-
- private Object parseNode() throws IOException, SyntaxError {
- this._st.nextToken();
- if (this._st.ttype != -3) {
- throw new SyntaxError("missing node type");
- } else {
- String var1 = this._st.sval;
- this._st.nextToken();
- if (this._st.ttype != 123) {
- throw new SyntaxError("'{' expected");
- } else if (var1.equals("Separator")) {
- return this.parseSeparator();
- } else if (var1.equals("Triangle")) {
- return this.parseTriangle();
- } else if (var1.equals("Translation")) {
- return this.parseTranslation();
- } else if (var1.equals("Rotation")) {
- return this.parseRotation();
- } else {
- throw new SyntaxError("invalid node type: " + var1);
- }
- }
- }
-
- private Object parseTriangle() throws IOException, SyntaxError {
- Coordinates var1 = new Coordinates((double)0.0F, (double)0.0F, (double)0.0F);
- Coordinates var2 = new Coordinates((double)50.0F, (double)0.0F, (double)0.0F);
- Coordinates var3 = new Coordinates((double)50.0F, (double)0.0F, (double)50.0F);
-
- while(true) {
- this._st.nextToken();
- if (this._st.ttype == 125) {
- return new TriangleShape(var1, var2, var3);
- }
-
- if (this._st.ttype != -3) {
- throw new SyntaxError("missing field name");
- }
-
- String var4 = this._st.sval;
- double var5 = (double)0.0F;
- double var7 = (double)0.0F;
- double var9 = (double)0.0F;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var5 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var7 = this._st.nval;
- this._st.nextToken();
- if (this._st.ttype != -2) {
- throw new SyntaxError("missing field value");
- }
-
- var9 = this._st.nval;
- if (var4.equals("a")) {
- var1 = new Coordinates(var5, var7, var9);
- } else if (var4.equals("b")) {
- var2 = new Coordinates(var5, var7, var9);
- } else {
- if (!var4.equals("c")) {
- throw new SyntaxError("invalid field name: " + var4);
- }
-
- var3 = new Coordinates(var5, var7, var9);
- }
- }
- }
- }
-