[antlr-interest] ANTLR and GCC

Ric Klaren klaren at cs.utwente.nl
Tue Aug 19 06:13:45 PDT 2003


On Tue, Aug 19, 2003 at 09:52:33AM -0000, goughroger wrote:
> I am new to ANTLR and I wish to use it with GCC. I have modified the
> backend of GCC compiler to recognise a new architecure which I am
> modelling. I am trying to use ANTLR as a front-end. Is this possible?

Correct me if I'm wrong, but you're trying to make a new frontend to gcc
for a new language and want to use antlr to generate the frontends parser?
If so then technically yes this should be possible. You may have to use a
handmade AST (in plain C datastructures) in stead of the ANTLR supplied
ones, since antlr's support code is all C++. (Or do you want to use gcj to
compile the antlr generated java and use that inside the gcc frontend ??
Would probably also need some wrapper code and some patches to antlr)

> I have written a basic grammar file containing a lexer and parser. I
> am able to compile this with the commands
> java antlr.Tool myGrammarFile.g
> javac *.java
> main    //main is the class name
> The last command does not work, i.e no output is produced. (The
> classpath options are set correctly)

Can't say what's happening here too little info.

> Should the output be an AST?

AFAIK gcc uses some internal intermediate format, you probably need to make
some treewalkers that generate that from the parse tree (AST) generated by

> Am i right in thinking that the antlr can output C functions and if so,
> how?

Antlr generates Java or C# or C++. See the manual as to how (www.antlr.org)

> Can ANTLR output assembly language?

ANTLR itself has no support for writing assembly. But you can make
treeparsers that do. But if you want to interface to gcc you should
probably use their codegenerator tools.


    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
     Innovation makes enemies of all those who prospered under the old
   regime, and only lukewarm support is forthcoming from those who would
               prosper under the new. --- Niccolò Machiavelli


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list