[antlr-interest] newbie: how to use parse rule and nested curly

Ramon V. del Rosario wincrt at yahoo.com
Mon Jun 13 00:37:03 PDT 2005


Hi, am trying to parse bind config file but is
struggling to understand how antlr parse rule work.
right now i'm just using antlr to tokenise the
file....
using a counter to parse nested { {}; }; sort of
structure but has been reading the ref manual and it 
seen the parse rule should be able to parse such a
thing easily. but can't find much notes on how to
create
the parser except the calculator.

can we create a our own object when a parse rule is
confirm? eg when acl block is found then i can

ACL a = new ACL($getText());
while ($hasNext()
	a.addElement($getText());

thanks for reading

----- sample bind config ------
acl xyz-slaves {
160.9.201.3;
};

options {
directory "/etc";
allow-transfer { xyz-slaves; localhost; };
};

--------- t.g ------------
class P extends Parser;

// how do we use the parse rule ???
document : (acl | WORDSTRING) + EOF;

acl : ACL named_block ;
opt : OPT named_block ;

named_block : WORDSTRING LPAREN (named_block |
WORDSTRING)* RPAREN SEMICOLON ;
	
class L extends Lexer;

options {
caseSensitive=false;
caseSensitiveLiterals=false;
k=7;
}

LPAREN : '{' ;

RPAREN : '}' ;

SEMICOLON : ';' ;

ACL : "acl";

OPT : "options";

WORDSTRING : (WORD | STRING)+ ;
						
protected	
STRING : '"'! (~'"')+ '"'! 	
		| '\''! (~'\'')+ '\''! ;
		
protected
WORD : ( ALPHA | INT | SYM )+ ;

protected
ALPHA : ('a'..'z')+ ;

protected
INT : ('0'..'9')+;

protected
SYM : ('.' | '!' | '=' | '_' | '/')+;

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


		
__________________________________ 
Discover Yahoo! 
Find restaurants, movies, travel and more fun for the weekend. Check it out! 
http://discover.yahoo.com/weekend.html 



More information about the antlr-interest mailing list