[antlr-interest] (no subject)

John Stovin j.stovin at zoo-tech.com
Tue Oct 10 08:42:45 PDT 2006


Hi,

I'm a bit of an ANTLR newbie, and I'm trying to put together a parser for my
Domain Specific Language. 

I'm not sure if this is a bug in ANTLR 3b4. I'm using language=CSharp.

Here's a snippet of my grammar file:

	scope_block [SymbolTable s] :
		id = IDENTIFIER block[s, $id.Text] |
		block[s, ""]
		;
	
	block [SymbolTable s, string name] :
		'{' { s.PushScope(name); } 
		element[s]* 
		'}' { s.PopScope(); } 
		;

A scope block is series of elements surrounded by curly braces. It can
optionally be preceded by an identifier. I want the parser to call
PushScope() with a name argument on the SymbolTable object when it finds an
open brace, and PopScope() when it finds a closing brace.

However, the C# code emitted looks like this. It does the right thing for
the empty string case, but it mangles the reference to $id.Text. Any
suggestions about what I might be doing wrong here, or any workarounds.
	

            switch (alt2) 
            {
                case 1 :
                    // DVD_DSL.g:22:2: id= IDENTIFIER block[s, $id.Text]
                    {
                    	root_0 = (object)adaptor.GetNilNode();
                    
                    	id = (Token)input.LT(1);
 
Match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_scope_block87); 
                    	id_tree = (object)adaptor.Create(id);
                    	adaptor.AddChild(root_0, id_tree);

                    	PushFollow(FOLLOW_block_in_scope_block89);
----------------------->block3 = block(s,  , id, .Text);
                    	followingStackPointer_--;
                    	
                    	adaptor.AddChild(root_0, block3.Tree);
                    
                    }
                    break;
                case 2 :
                    // DVD_DSL.g:23:2: block[s, \"\"]
                    {
                    	root_0 = (object)adaptor.GetNilNode();
                    
                    	PushFollow(FOLLOW_block_in_scope_block95);
----------------------->block4 = block(s,  "");
                    	followingStackPointer_--;
                    	
                    	adaptor.AddChild(root_0, block4.Tree);
                    
                    }
                    break;
            
            }

Thanks in advance.

______________________
John Stovin
Senior Software Engineer

mailto:j.stovin at zoo-tech.com   http://www.zoo-tech.com
t: +44 (0)114 274 3660                  f: +44 (0)114 274 3699	

ZOOtech Ltd., 20 Furnival Street, Sheffield, S1 4QT, United Kingdom. 
Company Registration Number: 4197951

NOTE: This email is private and confidential to the named recipients. Any
information provided is given in good faith. However, unless specifically
stated to the contrary, ZOOtech Ltd. accepts no liability for the content of
this email, or for the consequences of any actions taken on the basis of the
information provided, unless that information is subsequently confirmed in
writing.
© 2006 ZOOtech Ltd.




More information about the antlr-interest mailing list