[antlr-interest] Re: C directive as a comment
m_barreteau
m_barreteau at yahoo.co.uk
Fri Oct 8 09:38:28 PDT 2004
--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...>
wrote:
> Sure, you can build something with ANTLR to do that. A good
starting
> place would be my C grammar, see the link below. You would have to
> change the lexer to pass the comment into the parser and from
there, in
I changed it into:
KEYWORD : "_KEYWORD";
MY_DIRECTIVE
}
: "/*" KEYWORD
(~( '*'| '\r' | '\n' ))+
{ _ttype = MyParms; }
// Is it the way to pass the content of the comment (I mean without
prefix "/* _KEYWORD" and suffix "*/") back to the parser? I don't
think so.
"*/"
;
protected
MyParms:;
Comment
: "/*"
( { LA(2) != '/' }? '*'
| { LA(2) != 'K' && LA(3) != 'E'}? '_'
// Is there another way to consider a keyword whose length > k (k=3
in your file)? Such comments (without the keyword) have to be ignored
as usual.
| "\r\n" { deferredNewline(); }
| ( '\r' | '\n' ) { deferredNewline(); }
| ~( '*'| '\r' | '\n' )
)*
"*/" { _ttype = Token.SKIP;
}
;
I also have some troubles about spaces even if using 'ignore' in the
options part to parse for instance "/* _KEYWORD A [2:4] [1:5] */".
How can I manage with that at the lexer level?
> an action, send the contents of the comment to another lexer/parser
to
I suppose that this action is something like:
{ ## = #( #[NKeyword], ##); } but has the related rule to be
detailed? (see next question)
> grab what you need.
Is this other lexer/parser in charge of detailing the content of the
directive? (e.g. ID (LBRACKET e1:primaryExpr COLON e2:primaryExpr
RBRACKET)+)
Many thanks.
> Monty Zukowski
>
> ANTLR & Java Consultant -- http://www.codetransform.com
> ANSI C/GCC transformation toolkit --
> http://www.codetransform.com/gcc.html
> Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
>
>
> On Sep 13, 2004, at 8:54 AM, m_barreteau wrote:
>
> >
> > Hi!
> >
> > I would like to recognise a directive (I mean an instruction that
> > can be ignored by a C compiler if a given identifier is not set)
that
> > would be hidden inside a C comment. For instance:
> >
> > /* KEYWORD [parm1:parm2] */
> >
> > Does ANTLR 2.7.2 is able to collect these parameters ?
> >
> > Thanks.
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list