[antlr-interest] C-Runtime in C++ prog

Jim Idle jimi at temporal-wave.com
Sat Feb 16 11:04:01 PST 2008


> -----Original Message-----
> From: Oliver Kowalke [mailto:oliver.kowalke at gmx.de]
> > just make it call an external API that has extern "C" linkage.
> 
> I refered to actions - as I can remeber correctly ANTLR ignores the
> content of
> actions. It seams I was wrong.

ANTLR does, but the C/C++ compiler doesn't. The generated code is only C 
compatible right now.

> > You
> > should keep the code in your grammar files to an absolute minimum,
> just
> > for maintenance reasons really.
> 
> I'm sorry I don't understand this. If I implement an interpreter I 
have
> to put
> in code inside the actions - right?

Yes, but all it need do is call an external function. You dont have to 
embed 500 lines of C++ code in the action. The external funcitno call 
can have C linkage and then it all works fine.

> > Not sure what you mean by errors as return values. When a syntax
> error
> > occurs, it fires a series of function calls that culminate in a call
> to
> > displayRecognitionError. However, you can override these functions
> > (usually you only need to override the displayRecognitionError) and
> make
> > them do whatever you like.
> 
> I mean in C++ you throw exceptions (2.x version of ANTLR) in the case
> of
> errors. But exceptions are not part of C.

Hence it is a sequence of function calls and then drops out of the rule 
function properly because it detects that error state. You don't need to 
do anything but decide what to do when you are asked to print an error.

JiIm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Jim Idle.vcf
Type: text/x-vcard
Size: 1863 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080216/40725a75/attachment.vcf 


More information about the antlr-interest mailing list