[antlr-interest] need to help in resolving bms file grammar rule

din_wins din_wins at yahoo.com
Fri Sep 3 03:48:29 PDT 2004


hi friends,

i am having the following .bms file 

CHCM001  DFHMDI MAPATTS=(COLOR,PS,HILIGHT,VALIDN)

and it the only line which i have in the file. and can any one help 
me in modifying my grammar file in such a way that i can process 
above one. I have taken care in my grammar file but still giving me 
error with

line 1:50: unexpected token: ["",<1>,line=1,col=50]

below is my grammar file.
======================================================================

options {
	language = "CSharp";
	namespace = "Worksoft.BMSParser";
}

class BMSLexer extends Lexer;

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

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

EQUAL		: '='
			;			


LPAREN		: '('
			;	

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

class WSParser extends Parser;

options
{
	k = 3;
}
{
	private System.IO.FileStream _fs = null;
	private Worksoft.Parsers.ParserHelper _parserHelper = new 
Worksoft.Parsers.ParserHelper();
	private bool _isHeader = false;
	private string _currentParent = null;
	private string _currentObject = null;
	
	public WSParser(string fileName): base(3)
	{
		string inputFile = fileName;
		
			
		_fs = new System.IO.FileStream(inputFile, 
System.IO.FileMode.Open);

		BMSLexer lexer = new BMSLexer(_fs);	
		TokenBuffer tokenBuf = new TokenBuffer(lexer);
		this.setTokenBuffer(tokenBuf);
	}
	~WSParser()
	{
		if(_fs != null)
		{
			_fs.Close();
		}	
	}
	
	public string Parse()
	{
		string xmlReturn = string.Empty;

		xmlReturn = main();

		if(_fs != null)
		{
			_fs.Close();
		}

		return xmlReturn;
	}
}
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		:
			{
				_isHeader = true;
				Console.WriteLine("start head ");
	
			}
			/*
			(a:IDENTIFIER b:IDENTIFIER assigngroup)
			*/
			parent
			{
				_isHeader = false;
				//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 endchar assign)*)+
			{
				Console.WriteLine("End assigngroup");
			}
			;		
			
assign		:
			{
				Console.WriteLine("Start assign");
			}
			a:IDENTIFIER EQUAL c: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());
			}
			|
			b:STRING 
			{
				Console.WriteLine("End value B = " + 
b.getText());
			}
			
			;

parent		:
			{
				Console.WriteLine("Start parent");
			}
			a:IDENTIFIER (obj)+
			{
				if(!_isHeader)
				{
					if(_currentParent == null)
					{
						_currentParent = 
a.getText();
					}
					else
					if(_currentParent != a.getText
())
					{
						Console.WriteLine
("WriteParent");
					}
				}
				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 
Srini");
			}
			a: "**-|"  IDENTIFIER assign IDENTIFIER
			{
				Console.WriteLine("End footer Srini -
 " + a.getText());
			}
			;
endchar		:
			(UPPERX | LOWERX | WS)
			;	

class BMSTreeWalker extends TreeParser;

endchar returns [string x]
			{
			Console.WriteLine("End footer - " + a.getText
() + " - " + b.getText() + " - " + c.getText());
			}
	:	#(UPPERX a=endchar)	{x = a;}
	|	#(LOWERX a=endchar)	{x = a;}
	|	#(WS a=endchar)		{x = a;}
			;	


regards,
srinivasa dinesh.



 
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