[antlr-interest] newbie: building AST

Donal Murtagh donalmurtagh at yahoo.co.uk
Thu Dec 1 10:47:20 PST 2005


Hi,

I'm new to ANTLR, so go easy on me....
I'm building an AST for this chunk of text - the leaf tokens are DCAT*,
Sunday, Monday, etc.

DayCategoriser
{
  Weekdays
  {
    Sunday    = DCAT2
    Monday    = DCAT0
    Tuesday   = DCAT0
    Wednesday = DCAT0
    Thursday  = DCAT0
    Friday    = DCAT0
    Saturday  = DCAT1
  }
}

I'm currently using the following rules, which work fine, but I suspect
they're a bit more verbose than they need to be:

dayCategoriser
	:	DAY_CATEGORISER^		
		LBRACE!
			weekdayBlock
		RBRACE!
	;

weekdayBlock
	:	"Weekdays"^
		LBRACE!
			(weekdayCategory)*
		RBRACE!
	;

// leaf (terminal) rule
weekdayCategory[DayCategoriser dc]
	:	(day:ID ASSIGN^ dcat:DCAT_ID)				
	;

Is there any way that I can combine the rules weekdayBlock and
weekdayCategory to produce something like:

weekdayBlock[DayCategoriser dc]
	:	"Weekdays"^
		LBRACE
			(day:ID ASSIGN^ dcat:DCAT_ID)*				
		RBRACE
	;


I suspect this ought to be possible, but I can't seem to find the right
syntax?

Thanks in advance,
Don


		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com


More information about the antlr-interest mailing list