[x3d-public] Thinking of writing ANTLR4 lexer and parser for ClassicVRML
John Carlson
yottzumm at gmail.com
Mon Oct 23 09:55:55 PDT 2023
Here is the beginning of fieldTypes (I will probably rewrite the SF field
types to match something more ANTLR-like. There's issues with SFBool (it's
not VRML).
SFBool : \s*(true|false)\s*;
MFBool : '[' (SFBool)* ']'
SFColor :
\s*(([+]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s+){2}([+]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s*;
MFColor : '[' (SFColor)* ']'
SFColorRGBA :
\s*(([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s+){3}([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s*;
MFColorRGBA : '[' (SFColorRGBA)* ']'
SFDouble :
\s*([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFDouble : '[' (SFDouble)* ']'
SFFloat :
\s*([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFFloat : '[' (SFFloat)* ']'
SFImage :
\s*([+]?(0|[1-9][0-9]*)([Ee][+]?[0-9]+)?\s+){2}[+]?[0-4](\s+(0x[0-9a-fA-F]{1,16}|[+]?(0|[1-9][0-9]*)([Ee][+]?[0-9]+)?))*\s*;
MFImage : '[' (SFImage)* ']'
SFInt32 : \s*[+-]?(0|[1-9][0-9]*)([Ee][+-]?[0-9]+)?\s*;
MFInt32 : '[' (SFInt32)* ']'
SFMatrix3d :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){8}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFMatrix3d : '[' (SFMatrix3d)* ']'
SFMatrix3f :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){8}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFMatrix3f : '[' (SFMatrix3f)* ']'
SFMatrix4d :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){15}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFMatrix4d : '[' (SFMatrix4d)* ']'
SFMatrix4f :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){15}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFMatrix4f : '[' (SFMatrix4f)* ']'
MFNode : '[' (SFNode)* ']'
SFRotation :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){3}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFRotation : '[' (SFRotation)* ']'
SFString : (\s|\S)*;
MFString : '[' (SFString)* ']'
SFTime :
\s*([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFTime : '[' (SFTime)* ']'
SFVec2d :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){1}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec2d : '[' (SFVec2d)* ']'
SFVec2f :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){1}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec2f : '[' (SFVec2f)* ']'
SFVec3d :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){2}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec3d : '[' (SFVec3d)* ']'
SFVec3f :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){2}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec3f : '[' (SFVec3f)* ']'
SFVec4d :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){3}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec4d : '[' (SFVec4d)* ']'
SFVec4f :
\s*(([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s+){3}([+-]?((0|[1-9][0-9]*)(\.[0-9]*)?|\.[0-9]+)([Ee][+-]?[0-9]+)?)\s*;
MFVec4f : '[' (SFVec4f)* ']'
On Mon, Oct 23, 2023 at 10:51 AM John Carlson <yottzumm at gmail.com> wrote:
> Here's the beginning of an HAnimHumanoid, for example:
>
> ('DEF' xs:ID)? 'HAnimHumanoid' '{'
> (
> 'bboxCenter' SFVec3f
> | 'bboxDisplay' SFBool
> | 'bboxSize' bboxSizeType
> | 'center' SFVec3f
> | 'description' SFString
> | 'info' MFString
> | 'IS' (IS)
> | 'jointBindingPositions' MFVec3f
> | 'jointBindingRotations' MFRotation
> | 'jointBindingScales' MFVec3f
> | 'joints' (HAnimJoint)*
> | 'loa' loaType
> | 'metadata' (X3DMetadataObject)
> | 'motions' (HAnimMotion)*
> | 'motionsEnabled' MFBool
> | 'name' xs:NMTOKEN
> | 'rotation' SFRotation
> | 'scale' SFVec3f
> | 'scaleOrientation' SFRotation
> | 'segments' (HAnimSegment)*
> | 'sites' (HAnimSite)*
> | 'skeletalConfiguration' SFString
> | 'skeleton' (HAnimJoint|HAnimSite)*
> | 'skin' (Group|Transform|Shape|IndexedFaceSet)*
> | 'skinBindingCoords' (Coordinate|CoordinateDouble)
> | 'skinBindingNormals' (X3DNormalNode)
> | 'skinCoord' (Coordinate|CoordinateDouble)
> | 'skinNormal' (X3DNormalNode)
> | 'translation' SFVec3f
> | 'version' xs:NMTOKEN
> | 'viewpoints' (HAnimSite)*
> | 'visible' SFBool
> | 'class' xs:NMTOKENS
> | 'id' xs:NMTOKEN
> | 'style' SFString
> )*
> '}'
> | 'USE' xs:IDREF;
>
> On Mon, Oct 23, 2023 at 10:43 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> Hmm. Looks good. I am riffing off of:
>>
>> https://github.com/ingowald/antlr-vrml/blob/master/vrml.g4
>>
>> I don't know if X3DUOM supports ordering, which probably has
>> combinatorial explosion if employed, so I'll probably go for something
>> simpler in the long run.
>>
>> This is interesting, I'm not only targeting Java or Python:
>> https://github.com/antlr/antlr4/blob/master/doc/targets.md
>>
>> Hmm!
>>
>> John
>>
>> On Mon, Oct 23, 2023 at 9:19 AM GPU Group <gpugroup at gmail.com> wrote:
>>
>>> tangentially related, may relate to importer for x3d.py:
>>>
>>> vrml input
>>>
>>> https://sourceforge.net/projects/pyvrml97/
>>>
>>> which uses:
>>>
>>> from simpleparse.parser import Parser
>>>
>>> https://pypi.org/project/SimpleParse/
>>>
>>> - EBNF single pass for largely deterministic grammars
>>>
>>> parser.py snippet:
>>>
>>> grammar = r'''
>>>
>>> header :=
>>> headerStatement,profileStatement,componentStatement*,metaStatement*
>>>
>>> headerStatement :=
>>> ('#X3D',ts,SFNumber,ts,'utf8',ts,headerComment?,newLine)/('#',headerComment?,newLine)
>>>
>>> headerComment := -newLine+
>>>
>>> profileStatement := 'PROFILE', ts, profileName,newLine
>>>
>>> profileName := name
>>>
>>> <newLine> := ('\r\n'/'\r'/'\n')
>>> ...
>>>
>>>
>>>
>>> On Mon, Oct 23, 2023 at 7:47 AM John Carlson <yottzumm at gmail.com> wrote:
>>>
>>>> Hmm.
>>>>
>>>> I'm thinking about generating a Classic VRML grammar from X3DUOM using
>>>> Python, and then using ANTLR4 to generate Java code for inclusion in
>>>> various experiments with GraalVM's Polyglot, Truffle, etc.
>>>>
>>>> Hmm.
>>>>
>>>> Hmm.
>>>>
>>>> Hmm.
>>>>
>>>> Maybe in another life.
>>>>
>>>> John
>>>> _______________________________________________
>>>> x3d-public mailing list
>>>> x3d-public at web3d.org
>>>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231023/668ed82d/attachment-0001.html>
More information about the x3d-public
mailing list