[antlr-interest] Understanding C++ parser, CPP_parser.g
David Wigg
wiggjd at lsbu.ac.uk
Mon Mar 21 06:15:09 PST 2005
As the latest author of this parser I can help Keith Pincombe
off-list.
Can I assume Keith you are using version 3.00 of July 2004?
The only types of symbols actually saved (in CPPSymbol.hpp) are
those required for parsing. However, other fundamental types are
available in "id_expression" where a call to (for example)
myCode_id_expression could be inserted to pick up variable names
and their types (from "_ts").
I agree it would be nice to save the types of variables in
CPPSymbol.hpp as well. One day?
I look forward to hearing how you get on with your problem Keith.
David.
Message: 6
Date: Sun, 20 Mar 2005 14:11:48 +0000
From: Keith Pincombe <pincombe at gmail.com>
Subject: [antlr-interest] understanding CPP_PARSER.g
To: antlr-interest at antlr.org
Message-ID: <a86d1c40050320061111944030 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
If anyone has used CPP_PARSER.g i would love to ask you some
questions as i am really struggling to use it, my main problem
is working out how to access the information that the parser has
discovered, more specifically what type of variable has been
discovered.
I think this is covered in the grammar below but the more i look
at it the more i don't think its in the right place, the more i
look into this the more confused i am getting if someone could
help i would be very grateful.
simple_type_specifier returns [CPPParser::TypeSpecifier ts]
{char *s;
ts = tsInvalid;}
: ( {qualifiedItemIsOneOf(qiType|qiCtor)}?
s = qualified_type {ts=tsTYPEID;}
|
( "char" {ts |= tsCHAR;}
| "wchar_t" {ts |= tsWCHAR_T;}
| "bool" {ts |= tsBOOL;}
| "short" {ts |= tsSHORT;}
| "int" {ts |= tsINT;}
| ("_int64"|"__int64") {ts |= tsLONG;}
| "__w64" {ts |= tsLONG;}
| "long" {ts |= tsLONG;}
| "signed" {ts |= tsSIGNED;}
| "unsigned" {ts |= tsUNSIGNED;}
| "float" {ts |= tsFLOAT;}
| "double" {ts |= tsDOUBLE;}
| "void" {ts |= tsVOID;}
| ("_declspec"|"__declspec") LPAREN ID RPAREN
)+
|
// Fix towards allowing us to parse *.cpp files directly
(qualified_type qualified_id)=> s = qualified_type {ts=tsTYPEID;}
{printf("simple_type_specifier third option entered\n");}
)
;
More information about the antlr-interest
mailing list