[antlr-interest] Names of generated files and classes

Johannes Luber jaluber at gmx.de
Mon Aug 6 06:18:52 PDT 2007


Thomas Brandon wrote:
> As combined grammars will still need to append Lexer and Parser this
> will complicate a mapping from .g file names to generated file names
> that tools may need. They would need to analyse the grammars to
> determine the files they generate.
> An alternate solution is to name your files MyGrammar.g3l,
> MyGrammar.g3p and MyGrammar.g3t for lexer, parser and tree parser.
> 
> Tom.

Adding a different suffix isn't scalable. Suppose you got two tree
grammars - a likely case for modern languages. How should they be named?
MyGrammar.g3t1 and MyGrammar.g3t2? Really cryptic.

As suggested in the other email, I've looked for the depend option and
found this email:
<http://www.antlr.org/pipermail/antlr-interest/2007-February/019344.html>.
Unfortunately is the output format not top notch. One has to parse the
lines for the generated class files and look for known endings and that
wouldn't work even with simple exclusion of .g and .tokens, as new file
endings may be generated later. I suggest to output this in XML, along
with an attribute to denote the kind of files.

TParser.java : T.g
T.tokens : T.g
T__.g : T.g
U.g: T.tokens
U.java : U.g
U.tokens : U.g

That would become:

<MappingList>
	<Mapping>
		<Dependee kind="Source">TParser.java</Dependee>
		<Dependor kind="Grammar">T.g</Dependor>
	</Mapping>
	<Mapping>
		<Dependee kind="Tokens">T.tokens</Dependee>
		<Dependor kind="Grammar">T.g</Dependor>
	</Mapping>
	<Mapping>
		<Dependee kind="Grammar">T__.g</Dependee>
		<Dependor kind="Grammar">T.g</Dependor>
	</Mapping>
	<Mapping>
		<Dependee kind="Grammar">U.g</Dependee>
		<Dependor kind="Tokens">T.tokens</Dependor>
	</Mapping>
	<Mapping>
		<Dependee kind="Source">U.java</Dependee>
		<Dependor kind="Grammar">U.g</Dependor>
	</Mapping>
	<Mapping>
		<Dependee kind="Tokens">U.tokens</Dependee>
		<Dependor kind="Grammar">U.g</Dependor>
	</Mapping>
</Mappings>

And no escaping for spaces is necessary. (Are '\' also escaped?) I know
that Ter doesn't like XML that much, but as it is meant for programs
anyway, I think it is the best and simplest way.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list