|
Packit |
bf707c |
#ifndef PBLACKBOX_H
|
|
Packit |
bf707c |
#define PBLACKBOX_H
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
/*
|
|
Packit |
bf707c |
* SOFTWARE RIGHTS
|
|
Packit |
bf707c |
*
|
|
Packit |
bf707c |
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
|
|
Packit |
bf707c |
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
|
|
Packit |
bf707c |
* company may do whatever they wish with source code distributed with
|
|
Packit |
bf707c |
* PCCTS or the code generated by PCCTS, including the incorporation of
|
|
Packit |
bf707c |
* PCCTS, or its output, into commerical software.
|
|
Packit |
bf707c |
*
|
|
Packit |
bf707c |
* We encourage users to develop software with PCCTS. However, we do ask
|
|
Packit |
bf707c |
* that credit is given to us for developing PCCTS. By "credit",
|
|
Packit |
bf707c |
* we mean that if you incorporate our source code into one of your
|
|
Packit |
bf707c |
* programs (commercial product, research project, or otherwise) that you
|
|
Packit |
bf707c |
* acknowledge this fact somewhere in the documentation, research report,
|
|
Packit |
bf707c |
* etc... If you like PCCTS and have developed a nice tool with the
|
|
Packit |
bf707c |
* output, please mention that you developed it using PCCTS. In
|
|
Packit |
bf707c |
* addition, we ask that this header remain intact in our source code.
|
|
Packit |
bf707c |
* As long as these guidelines are kept, we expect to continue enhancing
|
|
Packit |
bf707c |
* this system and expect to make other tools available as they are
|
|
Packit |
bf707c |
* completed.
|
|
Packit |
bf707c |
*
|
|
Packit |
bf707c |
* ANTLR 1.33
|
|
Packit |
bf707c |
* Terence Parr
|
|
Packit |
bf707c |
* Parr Research Corporation
|
|
Packit |
bf707c |
* with Purdue University and AHPCRC, University of Minnesota
|
|
Packit |
bf707c |
* 1989-2000
|
|
Packit |
bf707c |
*/
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
/* Completely rewritten by Chris Uzdavinis (chris@atdesk.com) for MR23 */
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
#include "pcctscfg.h"
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
#include "pccts_iostream.h"
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
PCCTS_NAMESPACE_STD
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
// MR20 Added #include for "DLexerBase.h"
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
#include "DLexerBase.h"
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
//
|
|
Packit |
bf707c |
// The default buffer size of the lexer is given by the
|
|
Packit |
bf707c |
// second argument of the lexer's ctor. It is optional
|
|
Packit |
bf707c |
// and defaults to 2000
|
|
Packit |
bf707c |
//
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
template<class Lexer, class Parser, class Token>
|
|
Packit |
bf707c |
class DllExportPCCTS ParserBlackBox {
|
|
Packit |
bf707c |
private:
|
|
Packit |
bf707c |
// no copy construction allowed
|
|
Packit |
bf707c |
ParserBlackBox(ParserBlackBox const &);
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
// no copy assignment allowed
|
|
Packit |
bf707c |
ParserBlackBox & operator=(ParserBlackBox const &);
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
protected:
|
|
Packit |
bf707c |
DLGFileInput *in;
|
|
Packit |
bf707c |
Lexer *scan;
|
|
Packit |
bf707c |
_ANTLRTokenPtr tok;
|
|
Packit |
bf707c |
ANTLRTokenBuffer *pipe;
|
|
Packit |
bf707c |
Parser *_parser;
|
|
Packit |
bf707c |
FILE *file;
|
|
Packit |
bf707c |
int openByBlackBox; /* MR21 Don't close what we haven't opened */
|
|
Packit |
bf707c |
public:
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
ParserBlackBox(FILE *f)
|
|
Packit |
bf707c |
: in(0)
|
|
Packit |
bf707c |
, scan(0)
|
|
Packit |
bf707c |
, tok(0)
|
|
Packit |
bf707c |
, pipe(0)
|
|
Packit |
bf707c |
, _parser(0)
|
|
Packit |
bf707c |
, file(0)
|
|
Packit |
bf707c |
, openByBlackBox(0)
|
|
Packit |
bf707c |
{
|
|
Packit |
bf707c |
if (f == NULL)
|
|
Packit |
bf707c |
{
|
|
Packit |
bf707c |
cerr << "invalid file pointer\n";
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
else
|
|
Packit |
bf707c |
{
|
|
Packit |
bf707c |
openByBlackBox = 0; /* MR21a */
|
|
Packit |
bf707c |
file = f;
|
|
Packit |
bf707c |
in = new DLGFileInput(f);
|
|
Packit |
bf707c |
scan = new Lexer(in);
|
|
Packit |
bf707c |
pipe = new ANTLRTokenBuffer(scan);
|
|
Packit |
bf707c |
tok = new Token;
|
|
Packit |
bf707c |
scan->setToken(tok);
|
|
Packit |
bf707c |
_parser = new Parser(pipe);
|
|
Packit |
bf707c |
_parser->init();
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
ParserBlackBox(char *fname)
|
|
Packit |
bf707c |
: in(0)
|
|
Packit |
bf707c |
, scan(0)
|
|
Packit |
bf707c |
, tok(0)
|
|
Packit |
bf707c |
, pipe(0)
|
|
Packit |
bf707c |
, _parser(0)
|
|
Packit |
bf707c |
, file(0)
|
|
Packit |
bf707c |
, openByBlackBox(0)
|
|
Packit |
bf707c |
{
|
|
Packit |
bf707c |
FILE *f = fopen(fname, "r");
|
|
Packit |
bf707c |
if ( f==NULL ) {
|
|
Packit |
bf707c |
openByBlackBox = 0;
|
|
Packit |
bf707c |
cerr << "cannot open " << fname << "\n"; return;
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
else {
|
|
Packit |
bf707c |
openByBlackBox = 1;
|
|
Packit |
bf707c |
file = f;
|
|
Packit |
bf707c |
in = new DLGFileInput(f);
|
|
Packit |
bf707c |
scan = new Lexer(in);
|
|
Packit |
bf707c |
pipe = new ANTLRTokenBuffer(scan);
|
|
Packit |
bf707c |
tok = new Token;
|
|
Packit |
bf707c |
scan->setToken(tok);
|
|
Packit |
bf707c |
_parser = new Parser(pipe);
|
|
Packit |
bf707c |
_parser->init();
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
~ParserBlackBox()
|
|
Packit |
bf707c |
{
|
|
Packit |
bf707c |
delete in; delete scan; delete pipe; delete _parser; delete tok;
|
|
Packit |
bf707c |
if (1 == openByBlackBox) {
|
|
Packit |
bf707c |
fclose(file);
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
}
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
Parser *parser() { return _parser; }
|
|
Packit |
bf707c |
Lexer *getLexer() { return scan; }
|
|
Packit |
bf707c |
};
|
|
Packit |
bf707c |
|
|
Packit |
bf707c |
#endif
|