[antlr-interest] Parser within a parser?
Nicholas Yue
yue.nicholas at gmail.com
Wed Sep 17 04:49:09 PDT 2008
Hi,
I am new to ANTLR but have written grammar previously for bison/flex
(a long time ago)
I am trying to familiarize myself with the terminology in ANTLR.
I am trying to parse the following content to build an object
representing the information.
This is the output from a compiled RenderMan shader
8<------8<------8<------8<------8<------8<------8<------8<------
light "distantlight"
"intensity" "parameter uniform float"
Default value: 1
"lightcolor" "parameter uniform color"
Default value: "rgb" [1 1 1]
"from" "parameter uniform point"
Default value: "shader" [0 0 0]
"to" "parameter uniform point"
Default value: "shader" [0 0 1]
"__nondiffuse" "parameter uniform float"
Default value: 0
"__nonspecular" "parameter uniform float"
Default value: 0
8<------8<------8<------8<------8<------8<------8<------8<------
I have trying out the following grammar.
I am able to identify keywords like light and name like "distantlight"
As you can see, the default value line is different depending on the
content **inside** the "parameter ...." string.
Does it mean that I have to write two different grammar? i.e. Parser
within a parser? If I do, how do I communicate that information back out
to the outer parser to continue?
8<------8<------8<------8<------8<------8<------8<------8<------
class CSILexer extends Lexer;
options { k=1; filter=true; }
LIGHT : ("light")
{System.out.println("Found light shader: "+getText());}
;
SURFACE : ("surface")
{System.out.println("Found surface shader: "+getText());}
;
QUOTEDALPHANUM : '"' ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')* '"'
{System.out.println("Found quoted alphanumeric: "+getText());}
;
NUMERIC : ('0'..'9')+
{ System.out.println("Found numeric: "+getText()); }
;
EXIT : '.' { System.exit(0); } ;
8<------8<------8<------8<------8<------8<------8<------8<------
Regards
More information about the antlr-interest
mailing list