]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/PBlackBox.h
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / 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-1998
30 */
31
32 #include "pcctscfg.h"
33
34 #include "pccts_iostream.h"
35
36 PCCTS_NAMESPACE_STD
37
38 // MR20 Added #include for "DLexerBase.h"
39
40 #include "DLexerBase.h"
41
42 //
43 // The default buffer size of the lexer is given by the
44 // second argument of the lexer's ctor. It is optional
45 // and defaults to 2000
46 //
47
48 template<class Lexer, class Parser, class Token>
49 class DllExportPCCTS ParserBlackBox {
50 protected:
51 DLGFileInput *in;
52 Lexer *scan;
53 _ANTLRTokenPtr tok;
54 ANTLRTokenBuffer *pipe;
55 Parser *_parser;
56 FILE *file;
57 int openByBlackBox; /* MR21 Don't close what we haven't opened */
58 public:
59
60 ParserBlackBox(FILE *f)
61 {
62 openByBlackBox = 0; /* MR21a */
63 file = f;
64 in = new DLGFileInput(f);
65 scan = new Lexer(in);
66 pipe = new ANTLRTokenBuffer(scan);
67 tok = new Token;
68 scan->setToken(tok);
69 _parser = new Parser(pipe);
70 _parser->init();
71 }
72 ParserBlackBox(char *fname)
73 {
74 FILE *f = fopen(fname, "r");
75 if ( f==NULL ) {
76 openByBlackBox = 0;
77 cerr << "cannot open " << fname << "\n"; return;
78 }
79 else {
80 openByBlackBox = 1;
81 file = f;
82 in = new DLGFileInput(f);
83 scan = new Lexer(in);
84 pipe = new ANTLRTokenBuffer(scan);
85 tok = new Token;
86 scan->setToken(tok);
87 _parser = new Parser(pipe);
88 _parser->init();
89 }
90 }
91
92 ~ParserBlackBox()
93 {
94 delete in; delete scan; delete pipe; delete _parser; delete tok;
95 if (1 == openByBlackBox) {
96 fclose(file);
97 }
98 }
99
100 Parser *parser() { return _parser; }
101 Lexer *getLexer() { return scan; }
102 };
103
104 #endif