Extensible 3D (X3D) encodings
Part 2: Classic VRML encoding

Annex A

(normative)

Grammar
 

--- X3D separator bar ---

cube A.1 Introduction

A.1.1 Topics

This annex specifies the grammar for each syntactic element in this part of ISO/IEC 19776. Table A.1 contains a table of contents that lists the topics in this clause:

Table A.1 — Topics in this annex

A.1 Introduction
   A.1.1 Topics
   A.1.2 Overview
A.2 General
A.3 Nodes
A.4 Fields

Table A.1 — Topics in this annex
Table A.2 — X3D Classic VRML encoding lexical elements

A.1.2 Overview

It is not possible to parse X3D files using a context-free grammar. Semantic knowledge of the names and types of fields (either built-in or user-defined using PROTO or EXTERNPROTO) shall be used during parsing so that the parser knows which field type is being parsed.

The '#' (0x23) character begins a comment wherever it appears outside of the first line of the X3D file or quoted SFString or MFString fields. The '#' character and all characters until the next line terminator comprise the comment and are treated as whitespace.

The carriage return (0x0d), linefeed (0x0a), space (0x20), tab (0x09), and comma (0x2c) characters are whitespace characters wherever they appear outside of quoted SFString or MFString fields. Any number of whitespace characters and comments may be used to separate the syntactic entities of an X3D file. All reserved keywords are displayed in boldface type.

Any characters (including linefeed and '#') may appear within the quotes of SFString and MFString fields. A double quote character within a string shall be preceded with a backslash (e.g., "Each  double quotes character \" shall have a backslash."). A backslash character within a string shall be preceded with a backslash forming two backslashes (e.g., "One backslash \\ character").

6 Encoding of nodes contains a description of the allowed fields for all pre-defined node types. The double, float, and int32 symbols are expressed using Perl regular expression syntax; see [PERL] for details. The IdFirstChar, IdRestChars, and string symbols have not been formally specified; 5 Encoding of fields, contains a more complete description of their syntax.

The following conventions are used in the semi-formal grammar specified in this clause:

  1. Keywords and terminal symbols which appear literally in the Classic VRML encoded X3D file, are specified in bold.
  2. Non-terminal symbols used in the grammar are specified in italic.
  3. Production rules begin with a non-terminal symbol and the sequence of characters "::=", and end with a semi-colon (";").
  4. Alternation for production rules is specified using the vertical-bar symbol ("|").

Table A.2 contains the complete list of lexical elements for the grammar in this part of ISO/IEC 19776.

Table A.2 — X3D Classic VRML encoding lexical elements

Keywords Terminal
symbols
Other
symbols
COMPONENT
DEF
EXPORT
EXTERNPROTO
FALSE
IMPORT
IS
META
NULL
PROFILE
PROTO
ROUTE
TO
TRUE
USE
inputOnly
outputOnly
inputOutput
initializeOnly
period (.)
open brace ({)
close brace (})
open bracket ([)
close bracket (])
Id
double
fieldType
float
int32
string

Terminal symbols and the string symbol may be separated by one or more whitespace characters. Keywords and the Id, fieldType, float, int32, and double symbols shall be separated by one or more whitespace characters.

--- X3D separator bar ---

cube A.2 General

x3dScene ::=
       headerStatement
       profileStatement
       componentStatements
       metaStatements
statements ;
headerStatement ::=
#X3D 3.0 utf8 string ;
profileStatement ::=
PROFILE profileNameId ;
profileNameId ::=
Id ;
componentStatements ::=
componentStatement |
componentStatement componentStatements |
empty ;
componentStatement ::=
COMPONENT componentNameId:componentSupportLevel ;
componentNameId ::=
Id ;
componentSupportLevel ::=
int32 ;
exportStatement ::=
EXPORT nodeNameId AS exportedNodeNameId ;
importStatement ::=
IMPORT inlineNodeNameId.exportedNodeNameId AS nodeNameId ;
metaStatements ::=
metaStatement |
metaStatement metaStatements |
empty ;
metaStatement ::=
META metakey metavalue ;
metakey ::=
string ;
metavalue ::=
string ;
statements ::=
statement |
statement statements |
empty ;
statement ::=
nodeStatement |
importStatement |
protoStatement |
routeStatement ;
nodeStatement ::=
node |
DEF nodeNameId node |
USE nodeNameId ;
rootNodeStatement ::=
node | DEF nodeNameId node ;
protoStatement ::=
proto |
externproto ;
protoStatements ::=
protoStatement |
protoStatement protoStatements |
empty ;
proto ::=
PROTO nodeTypeId [ interfaceDeclarations ] { protoBody } ;
protoBody ::=
protoStatements rootNodeStatement statements ;
interfaceDeclarations ::=
interfaceDeclaration |
interfaceDeclaration interfaceDeclarations |
empty ;
restrictedInterfaceDeclaration ::=
inputOnly fieldType inputOnlyId |
outputOnly fieldType outputOnlyId |
initializeOnly fieldType initializeOnlyId fieldValue;
interfaceDeclaration ::=
restrictedInterfaceDeclaration |
inputOutput fieldType fieldId fieldValue ;
externproto ::=
EXTERNPROTO nodeTypeId [ externInterfaceDeclarations ] URLList ;
externInterfaceDeclarations ::=
externInterfaceDeclaration |
externInterfaceDeclaration externInterfaceDeclarations |
empty ;
externInterfaceDeclaration ::=
inputOnly fieldType inputOnlyId |
outputOnly fieldType outputOnlyId |
initializeOnly fieldType initializeOnlyId |
inputOutput fieldType inputOutputFieldId ;
routeStatement ::=
ROUTE nodeNameId . outputOnlyId TO nodeNameId . inputOnlyId ;
URLList ::=
mfstringValue ;
empty ::=
;
--- X3D separator bar ---

cube A.3 Nodes

node ::=
nodeTypeId { nodeBody } |
Script { scriptBody } ;
nodeBody ::=
nodeBodyElement |
nodeBodyElement nodeBody |
empty ;
scriptBody ::=
scriptBodyElement |
scriptBodyElement scriptBody |
empty ;
scriptBodyElement ::=
nodeBodyElement |
restrictedInterfaceDeclaration |
inputOnly fieldType inputOnlyId IS inputOnlyId |
outputOnly fieldType outputOnlyId IS outputOnlyId |
initializeOnly fieldType initializeOnlyId IS initializeOnlyId;
inputOutput fieldType inputOutputId IS inputOutputId;
nodeBodyElement ::=
initializeOnlyId fieldValue |
initializeOnlyId IS initializeOnlyId |
inputOnlyId IS inputOnlyId |
outputOnlyId IS outputOnlyId |
inputOutputId IS inputOutputId |
routeStatement |
protoStatement ;
nodeNameId ::=
Id ;
nodeTypeId ::=
Id ;
inlineNodeNameId ::=
Id ;
exportedNodeNameId ::=
Id ;
nodeTypeId ::=
Id ;
initializeOnlyId ::=
Id ;
inputOnlyId ::=
Id ;
inputOutputId ::=
Id ;
outputOnlyId ::=
Id ;
Id ::=
IdFirstChar |
IdFirstChar IdRestChars ;
IdFirstChar ::=
Any ISO-10646 character encoded using UTF-8 except: 0x30-0x39, 0x0-0x20, 0x22, 0x23, 0x27, 0x2b, 0x2c, 0x2d, 0x2e, 0x5b, 0x5c, 0x5d, 0x7b, 0x7d, 0x7f ;
IdRestChars ::=
Any number of ISO-10646 characters except: 0x0-0x20, 0x22, 0x23, 0x27, 0x2c, 0x2e, 0x5b, 0x5c, 0x5d, 0x7b, 0x7d, 0x7f ;
--- X3D separator bar ---

cube A.4 Fields

fieldType ::=
MFBool |
MFColor |
MFColorRGBA |
MFDouble |
MFFloat |
MFImage |
MFInt32 |
MFNode |
MFRotation |
MFString |
MFTime |
MFVec2d |
MFVec2f |
MFVec3d |
MFVec3f |
SFBool |
SFColor |
SFColorRGBA |
SFDouble |
SFFloat |
SFImage |
SFInt32 |
SFNode |
SFRotation |
SFString |
SFTime |
SFVec2d |
SFVec2f |
SFVec3d |
SFVec3f ;
fieldValue ::=
sfboolValue |
sfcolorValue |
sfcolorRGBAValue |
sfdoubleValue |
sffloatValue |
sfimageValue |
sfint32Value |
sfnodeValue |
sfrotationValue |
sfstringValue |
sftimeValue |
sfvec2dValue |
sfvec2fValue |
sfvec3dValue |
sfvec3fValue |
mfboolValue |
mfcolorValue |
mfcolorRGBAValue |
mfdoubleValue |
mffloatValue |
mfimageValue |
mfint32Value |
mfnodeValue |
mfrotationValue |
mfstringValue |
mftimeValue |
mfvec2dValue |
mfvec2fValue |
sfvec3dValue |
mfvec3fValue ;
sfboolValue ::=
TRUE |
FALSE ;
sfcolorValue ::=
float float float ;
sfcolorRGBAValue ::=
float float float float ;
sfdoubleValue ::=
double ;
double ::=
([+/-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+\-]?[0-9]+)?))
sffloatValue ::=
float ;
float ::=
([+/-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+\-]?[0-9]+)?)).
sfimageValue ::=
int32 int32 int32 ...
sfint32Value ::=
int32 ;
int32 ::=
([+\-]?(([0-9]+)|(0[xX][0-9a-fA-F]+)))
sfnodeValue ::=
nodeStatement |
NULL ;
sfrotationValue ::=
float float float float ;
sfstringValue ::=
string ;
string ::=
".*" ... double-quotes must be \", backslashes must be \\...
sftimeValue ::=
double ;
sfvec2dValue ::=
double double ;
sfvec3dValue ::=
double double double ;
sfvec2fValue ::=
float float ;
sfvec3fValue ::=
float float float ;
mfboolValue ::=
sfboolValue |
[ ] |
[ sfboolValues ] ;
sfboolValues ::=
sfboolValue |
sfboolValue sfboolValues ;
mfcolorValue ::=
sfcolorValue |
[ ] |
[ sfcolorValues ] ;
sfcolorValues ::=
sfcolorValue |
sfcolorValue sfcolorValues ;
mfcolorRGBAValue ::=
sfcolorRGBAValue |
[ ] |
[ sfcolorRGBAValues ] ;
sfcolorRGBAValues ::=
sfcolorRGBAValue |
sfcolorRGBAValue sfcolorRGBAValues ;
mfdoubleValue ::=
sfdoubleValue |
[ ] |
[ sfdoubleValues ] ;
sfdoubleValues ::=
sfdoubleValue |
sfdoubleValue sfdoubleValues ;
mffloatValue ::=
sffloatValue |
[ ] |
[ sffloatValues ] ;
sffloatValues ::=
sffloatValue |
sffloatValue sffloatValues ;
mfimageValue ::=
sfimageValue |
[ ] |
[ sfimageValues ] ;
sfimageValues ::=
sfimageValue |
sfimageValue sfimageValues ;
mfint32Value ::=
sfint32Value |
[ ] |
[ sfint32Values ] ;
sfint32Values ::=
sfint32Value |
sfint32Value sfint32Values ;
mfnodeValue ::=
nodeStatement |
[ ] |
[ nodeStatements ] ;
nodeStatements ::=
nodeStatement |
nodeStatement nodeStatements ;
mfrotationValue ::=
sfrotationValue |
[ ] |
[ sfrotationValues ] ;
sfrotationValues ::=
sfrotationValue |
sfrotationValue sfrotationValues ;
mfstringValue ::=
sfstringValue |
[ ] |
[ sfstringValues ] ;
sfstringValues ::=
sfstringValue |
sfstringValue sfstringValues ;
mftimeValue ::=
sftimeValue |
[ ] |
[ sftimeValues ] ;
sftimeValues ::=
sftimeValue |
sftimeValue sftimeValues ;
mfvec2dValue ::=
sfvec2dValue |
[ ] |
[ sfvec2dValues] ;
sfvec2dValues ::=
sfvec2dValue |
sfvec2dValue sfvec2dValues ;
mfvec3dValue ::=
sfvec3dValue |
[ ] |
[ sfvec3dValues ] ;
sfvec3dValues ::=
sfvec3dValue |
sfvec3dValue sfvec3dValues ;
mfvec2fValue ::=
sfvec2fValue |
[ ] |
[ sfvec2fValues] ;
sfvec2fValues ::=
sfvec2fValue |
sfvec2fValue sfvec2fValues ;
mfvec3fValue ::=
sfvec3fValue |
[ ] |
[ sfvec3fValues ] ;
sfvec3fValues ::=
sfvec3fValue |
sfvec3fValue sfvec3fValues ;

--- X3D separator bar ---