[antlr-interest] How to handle python-like indented code blocks

Eric Bell eric at ericjbell.com
Thu Nov 26 12:27:49 PST 2009


Jim--

Thanks for the quick reply!

I think the approach you suggest may be too limited for my application ... I
don't want to have to define different LEVELn's and have a maximum number of
levels ... I would have to place an arbitrary limit on the depth of my trees
and my grammar would get hideously large if I wanted to support a reasonable
maximum depth like several hundred.

The good news is that I found the Python grammar you mentioned and I see
some something that looks promising:

tokens
{
	INDENT;
	DEDENT;
}
.
.
.
suite		: simple_stmt
		| NEWLINE INDENT ( stmt )+ DEDENT
		; 

I am going to focus my attention on that approach and see where it leads.

Thanks again!

--eric



More information about the antlr-interest mailing list