CppParser
所属分类:编译器/解释器
开发工具:Visual C++
文件大小:210KB
下载次数:36
上传日期:2011-01-08 16:22:52
上 传 者:
maverick2830
说明: CPP parser/compiler code
文件列表:
CppParser (0, 2009-03-22)
CppParser\CPPDictionary.hpp (2939, 2005-10-31)
CppParser\CPPLexer.cpp (80944, 2007-04-18)
CppParser\CPPLexer.hpp (5740, 2007-04-18)
CppParser\CPPParser.cpp (366842, 2007-04-18)
CppParser\CPPParser.hpp (28400, 2007-04-18)
CppParser\CPPSymbol.hpp (3034, 2005-10-06)
CppParser\cpp_parser (0, 2009-03-22)
CppParser\cpp_parser\cpp_parser (0, 2009-03-22)
CppParser\cpp_parser\cpp_parser\cpp_parser.vcproj (4876, 2007-04-18)
CppParser\cpp_parser\cpp_parser.sln (895, 2007-04-18)
CppParser\cpp_parser\cpp_parser.suo (9728, 2007-04-18)
CppParser\CPP_parser.g (71598, 2005-11-04)
CppParser\DictEntry.hpp (3161, 2005-10-06)
CppParser\Dictionary.cpp (12676, 2005-10-31)
CppParser\Dictionary.hpp (3416, 2005-10-06)
CppParser\Grammar.txt (32794, 2005-04-18)
CppParser\HowToBuildStaticLibrary.txt (1660, 2005-10-31)
CppParser\LLkParser.cpp (2004, 2007-04-18)
CppParser\LLkParser.hpp (2070, 2005-10-06)
CppParser\Main.cpp (7218, 2005-11-04)
CppParser\MyCode.cpp (6709, 2005-11-02)
CppParser\MyCode.hpp (2691, 2005-10-06)
CppParser\NotesScopes.txt (2165, 2005-10-31)
CppParser\Parser.cpp (4278, 2007-04-18)
CppParser\Quadratic.cpp (1323, 2004-07-09)
CppParser\Quadratic.trace (376196, 2005-11-07)
CppParser\QuadraticA.trace (376196, 2005-11-02)
CppParser\STDCTokenTypes.hpp (4060, 2007-04-18)
CppParser\STDCTokenTypes.txt (3723, 2007-04-18)
CppParser\Support.cpp (28669, 2007-04-18)
CppParser\TestIfiles (0, 2009-03-22)
CppParser\TestIfiles\Quadratic.dat (353, 2005-11-02)
CppParser\TestIfiles\Quadratic.i (215616, 2005-03-09)
CppParser\TestIfiles\Quadratic.lis (87, 2005-11-02)
CppParser\TestIfiles\Quadratic.log (87, 2005-11-02)
CppParser\TestIfiles\QuadraticA.dat (353, 2005-11-04)
CppParser\TestIfiles\QuadraticA.lis (87, 2005-10-06)
CppParser\TestIfiles\QuadraticA.log (87, 2005-10-06)
... ...
MyReadMe3.1.txt
Version 3.1 November 2005
Notes for C++ grammar file to generate ANTLR parser (in C++)
Contents
1. Past
2. Present
If you experience any problems with running these programs please read these
notes first.
3. Future
1. Past
This C++ grammar file was originally written and published in 1994 by,
Authors: Sumana Srinivasan, NeXT Inc.; sumana_srinivasan@next.com
Terence Parr, Parr Research Corporation; parrt@parr-research.com
Russell Quong, Purdue University; quong@ecn.purdue.edu
as VERSION 1.2 for use with PCCTS (The original C version of ANTLR).
In 1997-1999 it was adapted for use in a project to analyse data flow
in C programs by Lasitha Leelasena, Sue Black (blackse@lsbu.ac.uk) and
David Wigg (wiggjd@bcs.org.uk). The generated parser was in C++ and
all of our included statement code was in C.
In 2000, in view of the fact that ANTLR had then been re-written in Java
and any further development of PCCTS had been suspended, it was decided
that we should convert our version of the C grammar for PCCTS into
use with ANTLR. As all our included application code was in C it was
decided to use the option to produce the generated parser in C++ to
avoid the need to rewrite this application code as well.
During 2001-2002 we were fortunate enough to have the services of a
visiting tutor, Jiangu Zuo, from Jianghan University,Wuhan,*** who
carried out most of this work. However, this conversion was quite a
lot more difficult than we had hoped and took us about a year to
complete. We have tried to make a record of problems encountered and
to give some solutions. If you would like further information please
contact wiggjd@bcs.org.uk or blackse@lsbu.ac.uk
The most difficult problem concerned the lack of 'hoisting' in ANTLR
which we were only able to overcome in the time available by copying
the generated hoisting code from the PCCTS version into our new
grammar file, hence some of the mysterious C++ statements at the
beginning of a number of productions. I think Zuo also had some
problems in using predicates.
In August 2002 I reported that this grammar file would be published
'soon' when remaining problems had been cleared up and the grammar was
fit to be published. In the event, for a variety of reasons, this was
not achieved.
So, in view of the number of requests being made for access to this
grammar I agreed in February 2003 to it being published on the
www.antlr.org website for general use under the usual terms, in the
hope that interested users would let me know how it could be improved.
Unfortunately, though it could handle C code and some C++ it was
unable to handle namespaces and a lot of templates so left a lot to be
desired.
In September 2003 I supplied a much improved version which I called
V2.0. This version was picked up by some users. A few problems were
raised which have since been solved.
Since then I have been concentrating on tidying up what had become a
rather confusing system and trying to produce a cleaner, tidier and
easier to understand system and also one easier to use in your
application. No doubt I have not entirely succeeded yet, but I hope
it is better than it was.
I have introduced the idea of subclassing a user's application code.
I hope this clear separation of code will lead to a greater clarity
of code between the application and the parser which will also enable
users to install CPP_parser updates much more easily.
If you feel the need to change the parser in any way I would be
grateful if you could let me know.
In July 2004 I published version 3.0 on the Antlr website (antlr.org).
Since then I have been dealing with users' queries, extending the
range of programs tested and clarifying the grammar file (CPP_parser.g)
to match the language definition enclosed (grammar.txt) with the
package more closely.
2. Present, November 2005.
I have called this latest version Version 3.1 published November 2005
I am using MSVC 6.0 under Windows ME and NT.
I created a static source library for the ANTLR code (2.7.3) with
some modifications as discussed below. I assume it will run with
with any later version of Antlr 2.7.? . I hope to be able to produce a
version using Antlr 3.? next year (2006).
Please note that this version continues to be used to parse pre-compiled
*.i files (with or without embedded #line directives (obtained by using
the /P command in compilation when using MSVC) ).
I include a small demonstration program, quadratic.i, which you
could use to test the set up of your system.
Although I cannot say it has been thoroughly tested (since a I have
not yet found a comprehensive test package for C++) it appears to
parse a wide variety of programs of mine and of many other peoples'
all of which contain a considerable quantity of included files
containing a great deal of complex code.
It should be noted that this version still handles scoping in a
relatively simplistic manner but this does not appear to be a
problem. To do this properly would entail a lot of work to update
the antlr supporting code in dictionary.cpp etc.
Briefly, all template parameter names and all type names are held in
level 1. All variable names are held in lower levels (higher numbers)
but continue to be deleted when they go out of scope (See
NotesScopes.txt).
Each run should end with the following two statements,
Support exitExternalScope scope now 0 as required
Parse ended
showing that the scope level had been returned to zero correctly.
I have included a C++ syntax definition (grammar.txt) which appears
to be up to date. If not, please let me know.
Please address any problems you have with this version to me,
preferably with a cut down version of the problem code.
Notes about running this version.
* I am currently using antlr 2.7.3 but it should work with any later
version of antlr 2.7.?. If not, please let me know.
* Note that the latest version of ANTLR for MSVC users may be on Ric
Klaren's new website at http://pts14043.pts.nl/antlr
* The following type of warning produced during compilation of
CPPLexer.cpp and CPPParser.cpp can be ignored,
CPPParser.cpp(163) : warning C4101: 'pe' : unreferenced local variable
* I have introduced a "statementTrace" feature in CPP_parser.g during
testing which I have found useful. See CPP_parser.g . This can be
set on (or off) by altering "statementTrace" in CPPParser.cpp and
recompiling and linking only (To avoid regenerating lexer and parser
from CPP_parser.g as well).
With statementTrace set to 1 you get a list of statement types as
they are detected from external_declaration and/or member_declaration
in CPP_parser.g.
With statementTrace set to 2 you also get a record of each symbol
declared showing its name, scope level, and type (See list in
CPPSymbol.hpp).
The trace output will display but you should be able to place trace
output in a trace file like this in a DOS window,
...\CPP_parser3.1>debug\CPP_parser TestIfiles\program.i > program.trace
I have found this feature useful for providing the ability to check
the output from one run to another after making any modifications
to the parser. Just keep your "standard" or "correct" version of the
trace output in a separate "archive" file and use this to compare
with the output of any new updated version.
You can do a file compare like this in a DOS window,
...\CPP_parser3.1>fc /n programA.trace program.trace
* I have also implemented a dynamic trace facility to use the excellent
trace facility in Antlr by including some extra code in
LLkParser.hpp and LLkParser.cpp called antlrTrace() before
generating the static antlr library.
To use this facility you have to use my modified version of
LLkParser.hpp and LLkParser.cpp included in this package to replace
the versions supplied in the ANTLR library (...\lib\cpp\antlr and
...\lib\cpp\src respectively).
If you don't want to use this facility please comment out all 7
references to "antlrTrace(false/true);" in CPP_parser.g.
The advantage of this facility is that, by always generating with
antlr tracing initially (using -traceParser etc.), antlr tracing
can be switched on or off completely by changing the
antlrTrace(false) statement in init() in CPPParser.cpp
appropriately and recompiling and linking without also having to
regenerate from the grammar file each time.
To use this facility selectively, particularly when debugging a
problem statement in a large program, I have included the following
statements in the grammar file which respectively turn Antlr trace
on and then off,
"antlrTrace_on" and "antlrTrace_off"
To use this facility you then have to include "antlrTrace_on"
in the source code just before the statement you want to debug and
"antlrTrace_off" just after the statement you want to debug.
* I have also supplied a slightly modified version of parser.cpp in
the ANTLR package which could be used to produce extra error messages
to cerr (as well as cout) so that these messages would not be missed
if and when the standard output was piped to a file for debugging
purposes.
* I still include MyCode.cpp (with MyCode.hpp) to demonstrate how your
application code can be subclassed in CPPParser. You can, of course,
take over, delete, include and amend any of these functions to suit
your application following the same pattern.
I recommend using this feature with this grammar as I think it will
make it easier both for me to issue updated versions of the CPP_parser
grammar from time to time and for you to accept and use them since
the code for the parser and your application can then be kept strictly
apart.
* I would be grateful if you could let me know if you need to correct
anything in CPP_parser.g, support.cpp etc.
* End of notes.
3. Future
I would be grateful if any user of this grammar would advise me and/or
the e-mail group (antlr-interest@antlr.org) of any improvement they
have been able to make to this grammar, for the benefit of other users.
In the meantime I will continue to update the master files as arranged
with Terence from time to time. I may be able to produce a version using
ANTLR 3.0 next year.
Thankyou,
David Wigg
Research Fellow
Centre for Systems and Software Engineering
London South Bank University
London, UK.
wiggjd@bcs.org.uk
blackse@lsbu.ac.uk
1 November 2005
近期下载者:
相关文件:
收藏者: