PARSER_BEGIN(Vrml) public class Vrml { static String readLine(java.io.InputStream i) { StringBuffer s=new StringBuffer(); char c; try { do { c=(char)i.read(); if (c!='\n'&&c!='\r') s.append(c);} while (c!='\n'&&c!='\r'); } catch (java.io.IOException e) {return null;} return new String(s); } static int cameras=0; static java.util.Vector DEFS=new java.util.Vector(); static java.util.Vector images=new java.util.Vector(); static java.util.Vector inlines=new java.util.Vector(); static java.util.Vector anchors=new java.util.Vector(); static void addDef(String s) {DEFS.addElement(s);} static void addImage(String s) {images.addElement(s);} static void addInline(String s) {inlines.addElement(s);} static void addAnchor(String s) {anchors.addElement(s);} static void addCamera() {cameras++;} public static void main(String args[]) throws ParseError { System.out.println("Parsing ..."); java.io.InputStream str=System.in; try { str=new java.io.FileInputStream(args[0]); } catch(Exception e) {} Vrml parser = new Vrml(str); String first=readLine(str); if (!first.startsWith("#VRML V1.0 ascii")) System.out.println("warning : first line must be '#VRML V1.0 ascii'"); parser.Input(); System.out.println("File conforms to VRML 1.0 spec"); if (cameras==0) System.out.println("No cameras defined"); else System.out.println(cameras+"camera"+((cameras>1)?"s ":" ")+"defined"); if (DEFS.size()!=0) { System.out.println("DEFS :"); for (java.util.Enumeration enum=DEFS.elements();enum.hasMoreElements();) { String s=(String)enum.nextElement(); System.out.println(s); } } if (images.size()!=0) { System.out.println("images :"); for (java.util.Enumeration enum=images.elements();enum.hasMoreElements();) { String s=(String)enum.nextElement(); System.out.println(s); } } if (inlines.size()!=0) { System.out.println("WWWInlines :"); for (java.util.Enumeration enum=inlines.elements();enum.hasMoreElements();) { String s=(String)enum.nextElement(); System.out.println(s); } } if (anchors.size()!=0) { System.out.println("WWWAnchors :"); for (java.util.Enumeration enum=anchors.elements();enum.hasMoreElements();) { String s=(String)enum.nextElement(); System.out.println(s); } } } } PARSER_END(Vrml) IGNORE_IN_BNF : {} { " " | "\t" | "\n" | "\r" | <"#" (~["\n","\r"])* ("\n"|"\r\n")> } TOKEN : /* LITERALS */ {} { < INTEGER : (["+","-"])? > | < FLOATING_POINT : (["+","-"])? (|) > | < INTEGER_LITERAL: (["l","L"])? | (["l","L"])? | (["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"])* ()? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"] > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < CHARACTER_LITERAL: "'" ( (~["'","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) ) "'" > | < STRING_LITERAL: "\"" ( (~["\"","\\"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > } TOKEN : {} { } void Input() : {} { (Node())+ } void Node() : {Token t;} { [ "DEF" t= {addDef(t.image);}] NodeBody() | "USE" } void NodeBody() : {} { AsciiText() | Cone() | Coordinate3() | Cube() | Cylinder() | Dlight() | FontStyle() | Group() | IdxFaceSet() | IdxLineSet() | Info() | Lod() | Material() | MaterialBinding() | MatrixTransform() | Normal() | NormalBinding() | OrthographicCamera() | PerspectiveCamera() | PointLight() | PointSet() | Rotation() | Scale() | Separator() | ShapeHints() | Sphere() | SpotLight() | Switch() | Texture2() | Tex2Transform() | TexCoordinate2() | Transform() | TransSeparator() | Translation() | WWWAnchor() | WWWInline() } void asciitextfield() : {} { "string" MFString() | "spacing" SFFloat() | "justification" SFEnum() | "width" MFFloat() } void AsciiText() : {} { "AsciiText" "{" [FieldSpecs()] (asciitextfield())+ "}" } void conefield() : {} { "parts" SFBitMask() | "bottomradius" SFFloat() | "height" SFFloat() } void Cone() : {} { "Cone" "{" [FieldSpecs()] (conefield())* "}" } void coordinatefield() : {} { "point" MFVec3f() } void Coordinate3() : {} { "Coordinate3" "{" [FieldSpecs()] coordinatefield() "}" } void cubefield() : {} { "width" SFFloat() | "height" SFFloat() | "depth" SFFloat() } void Cube() : {} { "Cube" "{" [FieldSpecs()] (cubefield())* "}" } void cylinderfield() : {} { "parts" SFBitMask() | "radius" SFFloat() | "height" SFFloat() } void Cylinder() : {} { "Cylinder" "{" [FieldSpecs()] (cylinderfield())* "}" } void dlightfield() : {} { "on" SFBool() | "intensity" SFFloat() | "color" SFColor() | "direction" SFVec3f() } void Dlight() : {} { "DirectionalLight" "{" [FieldSpecs()] (dlightfield())* "}" } void fstylefield() : {} { "size" SFFloat() | "family" SFEnum() | "style" SFBitMask() } void FontStyle() : {} { "fontstyle" "{" [FieldSpecs()] (fstylefield())* "}" } void Group() : {} { "Group" "{" (Node())* "}" } void ifacesetfield() : {} { "coordIndex" MFLong() | "materialIndex" MFLong() | "normalIndex" MFLong() | "textureCoordIndex" MFLong() } void IdxFaceSet() : {} { "IndexedFaceSet" "{" [FieldSpecs()] (ifacesetfield())* "}" } void ilinesetfield() : {} { "coordIndex" MFLong() | "materialIndex" MFLong() | "normalIndex" MFLong() | "textureCoordIndex" MFLong() } void IdxLineSet() : {} { "IndexedLineSet" "{" [FieldSpecs()] (ilinesetfield())* "}" } void infofield() : {} { "string" SFString() } void Info() : {} { "Info" "{" [FieldSpecs()] infofield() "}" } void lodfield() : {} { "range" MFFloat() | "center" SFVec3f() } void Lod() : {} { "LOD" "{" [FieldSpecs()] (lodfield())* (Node())* "}" } void materialfield() : {} { "ambientColor" MFColor() | "diffuseColor" MFColor() | "specularColor" MFColor() | "emissiveColor" MFColor() | "shininess" MFFloat() | "transparency" MFFloat() } void Material() : {} { "Material" "{" [FieldSpecs()] (materialfield())* "}" } void mbindingfield() : {} { "value" SFEnum() } void MaterialBinding() : {} { "MaterialBinding" "{" [FieldSpecs()] (mbindingfield())* "}" } void mxtransformfield() : {} { "matrix" SFMatrix() } void MatrixTransform() : {} { "MatrixTransform" "{" [FieldSpecs()] (mxtransformfield())* "}" } void normalfield() : {} { "vector" MFVec3f() } void Normal() : {} { "Normal" "{" [FieldSpecs()] normalfield() "}" } void nbindingfield() : {} { "value" SFEnum() } void NormalBinding() : {} { "NormalBinding" "{" [FieldSpecs()] (nbindingfield())* "}" } void ocamerafield() : {} { "position" SFVec3f() | "orientation" SFRotation() | "focalDistance" SFFloat() | "height" SFFloat() } void OrthographicCamera() : {} { "OrthographicCamera" {addCamera();} "{" [FieldSpecs()] (ocamerafield())* "}" } void pcamerafield() : {} { "position" SFVec3f() | "orientation" SFRotation() | "focalDistance" SFFloat() | "heightAngle" SFFloat() } void PerspectiveCamera() : {} { "PerspectiveCamera" {addCamera();} "{" [FieldSpecs()] (pcamerafield())* "}" } void plightfield() : {} { "on" SFBool() | "intensity" SFFloat() | "color" SFColor() | "location" SFVec3f() } void PointLight() : {} { "PointLight" "{" [FieldSpecs()] (plightfield())* "}" } void psetfield() : {} { "startIndex" SFLong() | "numPoints" SFLong() } void PointSet() : {} { "PointSet" "{" [FieldSpecs()] (psetfield())* "}" } void rotationfield() : {} { "rotation" SFRotation() } void Rotation() : {} { "Rotation" "{" [FieldSpecs()] (rotationfield())* "}" } void scalefield() : {} { "scaleFactor" SFVec3f() } void Scale() : {} { "Scale" "{" [FieldSpecs()] (scalefield())* "}" } void separatorfield() : {} { "renderCulling" SFEnum() } void Separator() : {} { "Separator" "{" [FieldSpecs()] (separatorfield())* (Node())* "}" } void shapehintsfield() : {} { "vertexOrdering" SFEnum() | "shapeType" SFEnum() | "faceType" SFEnum() | "creaseAngle" SFFloat() } void ShapeHints() : {} { "ShapeHints" "{" [FieldSpecs()] (shapehintsfield())* "}" } void spherefield() : {} { "radius" SFFloat() } void Sphere() : {} { "Sphere" "{" [FieldSpecs()] (spherefield())* "}" } void spotlightfield() : {} { "on" SFBool() | "intensity" SFFloat() | "color" SFColor() | "location" SFVec3f() | "direction" SFVec3f() | "dropOffRate" SFFloat() | "cutOffAngle" SFFloat() } void SpotLight() : {} { "SpotLight" "{" [FieldSpecs()] (spotlightfield())* "}" } void switchfield() : {} { "whichChild" SFLong() } void Switch() : {} { "Switch""{" [FieldSpecs()] (switchfield())* (Node())* "}" } void texture2field() : {String s;} { "filename" s=SFString() {addImage(s);} | "image" SFImage() | "wrapS" SFEnum() | "wrapT" SFEnum() } void Texture2() : {} { "Texture2" "{" [FieldSpecs()] (texture2field())* "}" } void tex2transfield() : {} { "translation" SFVec2f() | "rotation" SFFloat() | "scaleFactor" SFVec2f() | "center" SFVec2f() } void Tex2Transform() : {} { "Texture2Transform" "{" [FieldSpecs()] (tex2transfield())* "}" } void texcoord2field() : {} { "point" MFVec2f() } void TexCoordinate2() : {} { "TextureCoordinate2" "{" [FieldSpecs()] (texcoord2field())* "}" } void transformfield() : {} { "translation" SFVec3f() | "rotation" SFRotation() | "scaleFactor" SFVec3f() | "scaleOrientation" SFRotation() | "center" SFVec3f() } void Transform() : {} { "Transform" "{" [FieldSpecs()] (transformfield())* "}" } void TransSeparator() : {} { "TransformSeparator" "{" [FieldSpecs()] (Node())* "}" } void translationfield() : {} { "translation" SFVec3f() } void Translation() : {} { "Translation" "{" [FieldSpecs()] (translationfield())* "}" } void WWWanchorfield() : {String n;} { "name" n=SFString() {addAnchor(n);} | "description" SFString() | "map" SFEnum() } void WWWAnchor() : {} { "WWWAnchor" "{" [FieldSpecs()] (WWWanchorfield())* (Node())* "}" } void WWWinlinefield() : {String s;} { "name" s=SFString() {addInline(s);} | "bboxsize" SFVec3f() | "bboxcenter" SFVec3f() } void WWWInline() : {} { "WWWInline" "{" [FieldSpecs()] (WWWinlinefield())* "}" } void bitmasklist() : {} { ("|" )* } void SFBitMask() : {} { | "(" bitmasklist() ")" } void SFBool() : {} { } void SFColor() : {} { SFFloat() SFFloat() SFFloat() } void SFEnum() : {} { } void SFFloat() : {} { | } void imglist() : {} { ( )* } void SFImage() : {} { imglist() } void SFLong() : {} { } void SFMatrix() : {} { SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() SFFloat() } void SFRotation() : {} { SFFloat() SFFloat() SFFloat() SFFloat() } String SFString() : {String s; } { s=VRMLSTRING() {return s;} } void SFVec2f() : {} { SFFloat() SFFloat() } void SFVec3f() : {} { SFFloat() SFFloat() SFFloat() } void colorlist() : {} { SFColor() ( "," SFColor() )* } void MFColor() : {} { SFColor() | "[" colorlist() "]" } void longlist() : {} { SFLong() ( "," SFLong() )* } void MFLong() : {} { SFLong() | "[" longlist() "]" } void floatlist() : {} { SFFloat() ( "," SFFloat() )* } void MFFloat() : {} { SFFloat() | "[" floatlist() "]" } String stringlist() : {String s;StringBuffer b=new StringBuffer();} { s=SFString() {b.append(s);} ( "," s=SFString() {b.append(",").append(s);} )* {return new String(b);} } String MFString() : {String s;} { ( s=SFString() | "[" s=stringlist() "]" ) {return s;} } void vec2flist() : {} { SFVec2f() ( "," SFVec2f() )* } void MFVec2f() : {} { SFVec2f() | "[" vec2flist() "]" } void vec3flist() : {} { SFVec3f() ( "," SFVec3f() )* } void MFVec3f() : {} { SFVec3f() | "[" vec3flist() "]" } void FieldSpecs() : {} { "fields" "[" ("," )* "]" } String VRMLSTRING() : {Token t;} { ( t= {return "\""+t.image+"\"";} | t= {return t.image;} ) } TOKEN : {} { < ID: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","0"-"9"] )* > }