[antlr-interest] how to solve exactly one assignment in an assignmentgroup

din_wins din_wins at yahoo.com
Mon Aug 30 21:37:52 PDT 2004


hi friends,

need help in modifying my grammar file. my problem is If there is 
exactly one assignment in an assignmentgroup the parser is failing. 
how i need to go about in solving this problem.

below is my grammar file.
=================
options {
	language = "CSharp";
	namespace = "Worksoft.Parsers";
}

class BMSLexer extends Lexer;

options 
{
	k = 2;
}
IDENTIFIER	
			:
			(	'a'..'z'
			|'A'..'Z'
			|'0'..'9'
			|'.'|'/'
			|'~'|'`'|'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'-
'|'_'|'+'
			|'['|']'|'{'|'}'|'\\'|'|'
			)+
			;

STRING		: '\'' (~'\'')* '\'' 
			;
			
COMMA		: ','
			;

EQUAL		: '='
			;			


LPAREN		: '('
			;	

RPAREN		: ')'
			;	
	
WS			:	( ' '
			|	'\t'
			|   '\r' '\n'
			|   '\n')
			{ $setType(Token.SKIP); }
			;

class BMSParser extends Parser;

options
{
	k = 3;
}
{
	private ParserHelper _parserHelper = new ParserHelper();
	public string Parse()
	{
		return main();
	}
}
main returns [string xml = string.Empty]
			:	
			(
			file
  			)
  			{
  				xml = _parserHelper.ToString();
  			}
			;
	
	
file		:
			{
					_parserHelper.Start();
					Console.WriteLine("Start 
file");	
			}
			(head body footer)
			{
					Console.WriteLine("End file");
	
					_parserHelper.End();
			}
			;
		
head		:
			{
				Console.WriteLine("start head ");
	
			}
			/*
			(a:IDENTIFIER b:IDENTIFIER assigngroup)
			*/
			parent
			{
				//Console.WriteLine("End head - " + 
a.getText() + " - " + b.getText());	
			}
			;
							
body		:
			{
				Console.WriteLine("Start body");
	
			}
			(parent)+
			{
				Console.WriteLine("End body");	
			}
			;
				
assigngroup	:
			{
				Console.WriteLine("Start 
assigngroup");
			}
			(assign (COMMA a:IDENTIFIER assign)*)+
			{
				Console.WriteLine("End assigngroup 
= " + a.getText());
			}
			;		
			
assign		:
			{
				Console.WriteLine("Start assign");
			}
			a:IDENTIFIER EQUAL value
			{
				Console.WriteLine("End assign - " + 
a.getText());
			}
			|
			
			b:IDENTIFIER EQUAL valuegroup
			{
				Console.WriteLine("End assign - " + 
b.getText());
			}
			;
								
						
valuegroup	:
			{
				Console.WriteLine("Start valuegroup");
			}
			(LPAREN value (COMMA value)+ RPAREN)+
			{
				Console.WriteLine("End valuegroup");
			}
			;
			
value		:
			{
				Console.WriteLine("Start value");
			}
			a:IDENTIFIER
			{
				Console.WriteLine("End value A = " + 
a.getText());
			}
			|
			c:STRING 
			{
				Console.WriteLine("End value C = " + 
c.getText());
			}
			;

parent		:
			{
				Console.WriteLine("Start parent");
			}
			a:IDENTIFIER (obj)+
			{
				Console.WriteLine("End parent - " + 
a.getText());
			}
			;					
	
			
obj			:
			{
				Console.WriteLine("Start obj");
			}
			a:IDENTIFIER assigngroup
			{
				Console.WriteLine("End obj - " + 
a.getText());
			}
			;	

footer		:
			{
				Console.WriteLine("Start footer");
			}
			a: "**-|"  IDENTIFIER assign IDENTIFIER
			{
				Console.WriteLine("End footer - " + 
a.getText());
			}
			;	




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list