GME
13
|
00001 #ifndef PBLACKBOX_H 00002 #define PBLACKBOX_H 00003 00004 /* 00005 * SOFTWARE RIGHTS 00006 * 00007 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool 00008 * Set (PCCTS) -- PCCTS is in the public domain. An individual or 00009 * company may do whatever they wish with source code distributed with 00010 * PCCTS or the code generated by PCCTS, including the incorporation of 00011 * PCCTS, or its output, into commerical software. 00012 * 00013 * We encourage users to develop software with PCCTS. However, we do ask 00014 * that credit is given to us for developing PCCTS. By "credit", 00015 * we mean that if you incorporate our source code into one of your 00016 * programs (commercial product, research project, or otherwise) that you 00017 * acknowledge this fact somewhere in the documentation, research report, 00018 * etc... If you like PCCTS and have developed a nice tool with the 00019 * output, please mention that you developed it using PCCTS. In 00020 * addition, we ask that this header remain intact in our source code. 00021 * As long as these guidelines are kept, we expect to continue enhancing 00022 * this system and expect to make other tools available as they are 00023 * completed. 00024 * 00025 * ANTLR 1.33 00026 * Terence Parr 00027 * Parr Research Corporation 00028 * with Purdue University and AHPCRC, University of Minnesota 00029 * 1989-1998 00030 */ 00031 00032 #include <iostream.h> 00033 00034 //hack 00035 #include "ATokenBuffer.h" 00036 00037 template<class Lexer, class Parser, class Token> 00038 class ParserBlackBox { 00039 protected: 00040 DLGFileInput *in; 00041 Lexer *scan; 00042 _ANTLRTokenPtr tok; 00043 ANTLRTokenBuffer *pipe; 00044 Parser *_parser; 00045 FILE *file; 00046 public: 00047 00048 ParserBlackBox(FILE *f) 00049 { 00050 file = f; 00051 in = new DLGFileInput(f); 00052 scan = new Lexer(in); 00053 pipe = new ANTLRTokenBuffer(scan); 00054 tok = new Token; 00055 scan->setToken(tok); 00056 _parser = new Parser(pipe); 00057 _parser->init(); 00058 } 00059 ParserBlackBox(char *fname) 00060 { 00061 FILE *f = fopen(fname, "r"); 00062 if ( f==NULL ) {cerr << "cannot open " << fname << "\n"; return;} 00063 else { 00064 file = f; 00065 in = new DLGFileInput(f); 00066 scan = new Lexer(in); 00067 pipe = new ANTLRTokenBuffer(scan); 00068 tok = new Token; 00069 scan->setToken(tok); 00070 _parser = new Parser(pipe); 00071 _parser->init(); 00072 } 00073 } 00074 ~ParserBlackBox() 00075 { 00076 delete in; delete scan; delete pipe; delete _parser; delete tok; 00077 fclose(file); 00078 } 00079 00080 Parser *parser() { return _parser; } 00081 Lexer *getLexer() { return scan; } 00082 }; 00083 00084 #endif