[antlr-interest] help me in modifying my grammar rule.

din_wins din_wins at yahoo.com
Sun Sep 5 23:55:41 PDT 2004


hi friends,

i am facing with these errors..

1) line 1:800: expecting "COMMA", found ')'
2) line 1:1065: expecting "WS", found ''

if anyone can help me in modifying my grammar please...

i am herewith my grammar file which is below..

======================================================================
options {
	language = "CSharp";
		
}

class VMDLexser extends Lexer ;

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

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

COMMA		:	','
			;

EQUAL		:	'='
			;

LPAREN		:	'('
			;

RPAREN		:	')'
			;


class VMDParser 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");	
			}
			(filename line) 
			{
					Console.WriteLine("End file");
	
					_parserHelper.End();
			}
			;

filename	:	{
				Console.WriteLine("Start FirstLine is 
FILE NAME");	
			}
			(a:IDENTIFIER b:IDENTIFIER)
			{
				Console.WriteLine("End FirstLine\t" + 
a.getText() + " " + b.getText());	
			}
			;


line		:	{
				Console.WriteLine("Start Line");
	
			}
			(lineexpr WS)+
			{
				Console.WriteLine("End Line");	
			}
			;

lineexpr	:	
			{
				Console.WriteLine("Start LineExpr");
	
			}
			(linegroupexpr)
			{
				Console.WriteLine("End LineExpr");
	
			}
			;


linegroupexpr	:	{
				Console.WriteLine("Start 
LineGroupExpr");	
			}
						
			a:IDENTIFIER (recordexpr)+
			{
				Console.WriteLine("End 
LineGroupExpr\t" + a.getText());	
			}
			;

recordexpr	:	
			{
				Console.WriteLine("Start RecordExpr");
	
			}
			a:IDENTIFIER (valuegroup)*
			{
				Console.WriteLine("End RecordExpr\t"+ 
a.getText());
			}
			;

valuegroup	:
			{
				Console.WriteLine("Start valuegroup");
			}
			(LPAREN (assign COMMA)+ RPAREN)
			{
				Console.WriteLine("End valuegroup");
			}
			;

assign		:
			{
				Console.WriteLine("Start Assign");
	
			}
			a:IDENTIFIER EQUAL value (value)*
			{
				Console.WriteLine("End Assign\t" + 
a.getText());	
			}
			;
		
value		:
			{
				Console.WriteLine("Start value");
			}
			b:IDENTIFIER
			{
				Console.WriteLine("End value\t" + 
b.getText());
			}
			;

======================================================================

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