]> pd.if.org Git - pccts/blob - h/PBlackBox.h
auto commit for import
[pccts] / h / PBlackBox.h
1 #ifndef PBLACKBOX_H
2 #define PBLACKBOX_H
3
4 /*
5  * SOFTWARE RIGHTS
6  *
7  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
8  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
9  * company may do whatever they wish with source code distributed with
10  * PCCTS or the code generated by PCCTS, including the incorporation of
11  * PCCTS, or its output, into commerical software.
12  * 
13  * We encourage users to develop software with PCCTS.  However, we do ask
14  * that credit is given to us for developing PCCTS.  By "credit",
15  * we mean that if you incorporate our source code into one of your
16  * programs (commercial product, research project, or otherwise) that you
17  * acknowledge this fact somewhere in the documentation, research report,
18  * etc...  If you like PCCTS and have developed a nice tool with the
19  * output, please mention that you developed it using PCCTS.  In
20  * addition, we ask that this header remain intact in our source code.
21  * As long as these guidelines are kept, we expect to continue enhancing
22  * this system and expect to make other tools available as they are
23  * completed.
24  *
25  * ANTLR 1.33
26  * Terence Parr
27  * Parr Research Corporation
28  * with Purdue University and AHPCRC, University of Minnesota
29  * 1989-1995
30  */
31
32 #include <iostream.h>
33
34 template<class Lexer, class Parser, class Token>
35 class ParserBlackBox {
36 protected:
37         DLGFileInput *in;
38         Lexer *scan;
39         _ANTLRTokenPtr tok;
40         ANTLRTokenBuffer *pipe;
41         Parser *_parser;
42         FILE *file;
43 public:
44         
45         ParserBlackBox(FILE *f)
46                 {
47                         file = f;
48                         in = new DLGFileInput(f);
49                         scan = new Lexer(in);
50                         pipe = new ANTLRTokenBuffer(scan);
51                         tok = new Token;
52                         scan->setToken(tok);
53                         _parser = new Parser(pipe);
54                         _parser->init();
55                 }
56         ParserBlackBox(char *fname)
57                 {
58                         FILE *f = fopen(fname, "r");
59                         if ( f==NULL ) {cerr << "cannot open " << fname << "\n"; return;}
60                         else {
61                                 file = f;
62                                 in = new DLGFileInput(f);
63                                 scan = new Lexer(in);
64                                 pipe = new ANTLRTokenBuffer(scan);
65                                 tok = new Token;
66                                 scan->setToken(tok);
67                                 _parser = new Parser(pipe);
68                                 _parser->init();
69                         }
70                 }
71         ~ParserBlackBox()
72                 {
73                         delete in; delete scan; delete pipe; delete _parser; delete tok;
74                         fclose(file);
75                 }
76
77         Parser *parser()        { return _parser; }
78 };
79
80 #endif