[antlr-interest] File extensions for ANTLR 3
Terence Parr
parrt at cs.usfca.edu
Thu Nov 30 14:18:52 PST 2006
On Nov 30, 2006, at 2:03 PM, Prashant Deva wrote:
> The current file extensions for antlr 3 (its .g or .g3, i guess) does
> not indicate in any way whether the grammar file contains a parser or
> lexer. Also the file name itself doesnt indicate the name of the
> parser/lexer.
>
> I propose to let the extension of grammar files be something like
> .gl,.gp & .glp which indicates instantly whether the file contains a
> lexer, parser or both. Also like java the name of the file should be
> the same as the name of the lexer inside.
In general I support this proposal. The most common case is plain .g
for a combined parser and lexer so nothing will change. I like the
idea that, from the extension, a build tool or IDE knows the Java
class that will come out.
T.gl -> TLexer.java
T.gp -> TParser.java
T.gtp -> TTreeParser.java
T.g -> TLexer.java, TParser.java
Kunle also has a proposal that tree parsers are different enough
that we should translate literally
T.gtp -> T.java
His rationale is that normal grammars are named for the language and,
hence, adding Lexer or Parser suffix makes sense, but tree parsers
are usually named properly and adding the TreeParser suffix does
not. I noticed this a number of times myself. For example,
DefineVariables.g -> DefineVariablesTreeParser.java (or .gtp?)
SemanticAnalyzer.g -> SemanticAnalyzerTreeParser.java
weird, right? Because tree grammars are named for their functions, we
should probably leave that alone. With the addition of Prashant's
proposal (a similar proposed by others) then we will know precisely
what Java file will come out given the extension.
So, the proposal is that ANTLR specifically
enforce .g, .gl, .gp, .gtp as well as the name of the file being the
name of the grammar inside. Further, ANTLR would deviate from
regular grammars for tree grammars so that no suffix is added to the
generated code.
How will this fly in other target languages?
Ter
More information about the antlr-interest
mailing list