[antlr-interest] Antlr v3.0ea8 : @header not taken into accountin automatically generated lexer java code...

Arnulf Heller aheller at gmx.at
Wed May 3 10:56:22 PDT 2006


I would settle for a different approach: use one header section and 
include that stuff in the lexer *and* in the parser. Keeps things 
simple and I suppose that everyone can live with the slight 
performance penalty.

What does one want to include? Helper classes? Glue logic? One might 
want to include that in the parser and the lexer anyway.

That brings me to another point: usage of precompiled headers (for 
the C++ target). In v2, I used a small trick to get my precompiled 
headers working:

header "pre_include_hpp" {
         #ifndef PRECOMPILEDHEADERS
}

header "post_include_hpp" {
         #endif // PRECOMPILEDHEADERS
         #include "BaseParserTokenTypes.hpp"
}

header "pre_include_cpp" {
         #include "StdAfx.h"
         #ifndef PRECOMPILEDHEADERS
}

header "post_include_cpp" {
         #endif // PRECOMPILEDHEADERS
         #include "BaseParser.hpp"
}

Rather cumbersome, but it worked.

An option would be fine here ...

Arnulf

At 10:22 03.05.2006, you wrote:
>Just to clarify Ter's post here, @parser::header will work as well 
>as @lexer::grammar, but there are 3 situations:
>
>lexer grammar
>parser grammar
>combined lexer/parser grammar
>
>Hence in a combined grammar you need to be explicit about where you 
>want this header stuff to go. In a lexer or parser grammar you do 
>not need to be. If you do not explicitly say so in a combined 
>grammar, then the header stuff will go to the parser. I suppose 
>there is an argument that if not explicit in a combined grammar then 
>the information should go in both, but I suspect that once we have 
>some docs this will make a lot more sense. The grammar syntax in 
>ANTLR3 is a lot more orthogonal than it has ever been before and the 
>whole process is very much more 'obvious' once you get going.
>
>Jim
>
>________________________________
>
>From: antlr-interest-bounces at antlr.org on behalf of Terence Parr
>Sent: Tue 5/2/2006 10:45 PM
>To: ANTLR Interest
>Subject: Re: [antlr-interest] Antlr v3.0ea8 : @header not taken into 
>accountin automatically generated lexer java code...
>
>
>
>
>On May 2, 2006, at 1:09 PM, Prashant Deva wrote:
>
> > No, what i meant was this-
> > According to the parent post, it seems if we want to declare a
> > header for a parser, we just use-
> > @header{}
> >
> > But to declare a header for lexer, we gotta use-
> > @lexer::header{}
>
>That is *only* if you are combining lexer and parser :)
>
> > That is where it doesnt feel uniform.
>
>@header{} is used if it's in the lexer by itself I believe.
>
> > Dont you think it would be better if we used -
> > @parser::header{}
> > &
> > @lexer::header{}
> > for both the lexer & the parser.
>
>I believe parser::header works; just implied.
>
> > That way it would seem more uniform :)
>
>Yep
>Ter



More information about the antlr-interest mailing list