[antlr-interest] Question: ANTLR and LLVM ... + Clang

Kevin J. Cummings cummings at kjchome.homeip.net
Sat Jun 18 19:35:28 PDT 2011


On 06/18/2011 05:19 AM, Ruslan Zasukhin wrote:
> On 6/17/11 8:22 PM, "Kevin J. Cummings"<cummings at kjchome.homeip.net>  wrote:
>
> Hi Kevin,
>
> Well, don't know why you think they cannot be compared.

You want to compare a parser generator (ANTLR) against a hand-made 
parser (Clang).

Seems silly to me.  You could compare the output parser from an ANTLR 
grammar, but you have yet to specify what grammar, against Clang which 
is already a C/C++/ObjC parser.  Do you have a C/C++/ObjC grammar that 
you could run through ANTLR to compare to Clang?

> ANTLR - is Parser ->  AST  ->TreeParser

No, Grammar-> [ANTLR] -> lexer/parser/tree parser

When you run the resulting parser, you see:

	source code -> LEXER -> parser -> AST -> TreeParser(s)

> Clang
>      contains also parser -- own, seems to be hand-made,
>      then they have more logic phases.

And from your "blackbox" description of Clang:

	source code -> Clang -> more logic phases

> On this page very good explained how C++ FrontEnd is bigger
> of parser
>
>     http://www.semanticdesigns.com/Products/FrontEnds/CppFrontEnd.html
>
>
> So again, if we have task to proceed C++ sources, we may choose between:
>
> 1)  ANTLR and develop or use some C++ grammar,
>       then spend time on (all/some) features describe on above page

If you are planning to write a C++ compiler, yes.  But why write one, 
when a number of freely available ones already exist?  Clang, GCC, etc.

I believe Ter has at least 1 C grammar file already written for ANTLR, 
but I'm not sure if he has a complete C++ grammar, and even if he does, 
I'm sure it doesn't contain everything else you need, which is a symbol 
table, and a designated output format from your parse.  I have also 
noticed (from real life experience) that example language grammars often 
come up short on either include facilities, or macro language support. 
That is more work you'd have to do.

Now, if you are writing a compiler that does not already have freely 
available versions, that is another story.  Using a tool like ANTLR will 
greatly simplify your development.  But, you'll still have to do 
development.

> 2) take in hands complete C++ Frontend and ...DONE?
>      For now I see two strong enough such frontends.
>      Clang and SemanticDesign (which I cannot test it seems as demo).

Clang is already interfaced to LLVM.  No development necessary.  Seems 
like a no brainer decision to me.  I can't speak for SemanticDesign.

> =============
>> ANTLR is a tool which can help you build compiler front-ends.  If you
>> were industrious enough, you could re-write CLang using ANTLR.
>>
>> ANTLR is primarily a JAVA tool (you at least need JAVA to run the tool
>> to compile your grammar), but can be used to produce other targeted
>> languages (C/C++, Python, etc) for your actual front-end.  While the C++
>> support is minimal in version 3 (better in version 2.7, but lacking in
>> some of the ST support) resulting in much use of C code which can be
>> compiled using C++, you could use it to interface directly to the LLVM
>> IR API if you wanted to.  But, I think Ter's example is probably the way
>> to go, at least until Version 4 starts to grow and we see what kind of
>> C++ runtime support will exist for ANTLR v4.
>>
>>> When one should prefer Clang vs ANTLR or reverse?
>>> Your opinions?
>>
>> I think you are asking the wrong question here.  Please compare apples
>> to apples, and not to cucumbers.
>

-- 
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list