]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | #ifndef PBLACKBOX_H\r |
2 | #define PBLACKBOX_H\r | |
3 | \r | |
4 | /*\r | |
5 | * SOFTWARE RIGHTS\r | |
6 | *\r | |
7 | * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r | |
8 | * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r | |
9 | * company may do whatever they wish with source code distributed with\r | |
10 | * PCCTS or the code generated by PCCTS, including the incorporation of\r | |
11 | * PCCTS, or its output, into commerical software.\r | |
12 | *\r | |
13 | * We encourage users to develop software with PCCTS. However, we do ask\r | |
14 | * that credit is given to us for developing PCCTS. By "credit",\r | |
15 | * we mean that if you incorporate our source code into one of your\r | |
16 | * programs (commercial product, research project, or otherwise) that you\r | |
17 | * acknowledge this fact somewhere in the documentation, research report,\r | |
18 | * etc... If you like PCCTS and have developed a nice tool with the\r | |
19 | * output, please mention that you developed it using PCCTS. In\r | |
20 | * addition, we ask that this header remain intact in our source code.\r | |
21 | * As long as these guidelines are kept, we expect to continue enhancing\r | |
22 | * this system and expect to make other tools available as they are\r | |
23 | * completed.\r | |
24 | *\r | |
25 | * ANTLR 1.33\r | |
26 | * Terence Parr\r | |
27 | * Parr Research Corporation\r | |
28 | * with Purdue University and AHPCRC, University of Minnesota\r | |
29 | * 1989-2000\r | |
30 | */\r | |
31 | \r | |
32 | /* Completely rewritten by Chris Uzdavinis (chris@atdesk.com) for MR23 */\r | |
33 | \r | |
34 | #include "pcctscfg.h"\r | |
35 | \r | |
36 | #include "pccts_iostream.h"\r | |
37 | \r | |
38 | PCCTS_NAMESPACE_STD\r | |
39 | \r | |
40 | // MR20 Added #include for "DLexerBase.h"\r | |
41 | \r | |
42 | #include "DLexerBase.h"\r | |
43 | \r | |
44 | //\r | |
45 | // The default buffer size of the lexer is given by the\r | |
46 | // second argument of the lexer's ctor. It is optional\r | |
47 | // and defaults to 2000\r | |
48 | //\r | |
49 | \r | |
50 | template<class Lexer, class Parser, class Token>\r | |
51 | class DllExportPCCTS ParserBlackBox {\r | |
52 | private:\r | |
53 | // no copy construction allowed\r | |
54 | ParserBlackBox(ParserBlackBox const &);\r | |
55 | \r | |
56 | // no copy assignment allowed\r | |
57 | ParserBlackBox & operator=(ParserBlackBox const &);\r | |
58 | \r | |
59 | protected:\r | |
60 | DLGFileInput *in;\r | |
61 | Lexer *scan;\r | |
62 | _ANTLRTokenPtr tok;\r | |
63 | ANTLRTokenBuffer *pipe;\r | |
64 | Parser *_parser;\r | |
65 | FILE *file;\r | |
66 | int openByBlackBox; /* MR21 Don't close what we haven't opened */\r | |
67 | public:\r | |
68 | \r | |
69 | ParserBlackBox(FILE *f)\r | |
70 | : in(0)\r | |
71 | , scan(0)\r | |
72 | , tok(0)\r | |
73 | , pipe(0)\r | |
74 | , _parser(0)\r | |
75 | , file(0)\r | |
76 | , openByBlackBox(0)\r | |
77 | {\r | |
78 | if (f == NULL)\r | |
79 | {\r | |
80 | cerr << "invalid file pointer\n"; \r | |
81 | }\r | |
82 | else\r | |
83 | {\r | |
84 | openByBlackBox = 0; /* MR21a */\r | |
85 | file = f;\r | |
86 | in = new DLGFileInput(f);\r | |
87 | scan = new Lexer(in);\r | |
88 | pipe = new ANTLRTokenBuffer(scan);\r | |
89 | tok = new Token;\r | |
90 | scan->setToken(tok);\r | |
91 | _parser = new Parser(pipe);\r | |
92 | _parser->init();\r | |
93 | }\r | |
94 | }\r | |
95 | ParserBlackBox(char *fname)\r | |
96 | : in(0)\r | |
97 | , scan(0)\r | |
98 | , tok(0)\r | |
99 | , pipe(0)\r | |
100 | , _parser(0)\r | |
101 | , file(0)\r | |
102 | , openByBlackBox(0)\r | |
103 | {\r | |
104 | FILE *f = fopen(fname, "r");\r | |
105 | if ( f==NULL ) {\r | |
106 | openByBlackBox = 0;\r | |
107 | cerr << "cannot open " << fname << "\n"; return;\r | |
108 | }\r | |
109 | else {\r | |
110 | openByBlackBox = 1;\r | |
111 | file = f;\r | |
112 | in = new DLGFileInput(f);\r | |
113 | scan = new Lexer(in);\r | |
114 | pipe = new ANTLRTokenBuffer(scan);\r | |
115 | tok = new Token;\r | |
116 | scan->setToken(tok);\r | |
117 | _parser = new Parser(pipe);\r | |
118 | _parser->init();\r | |
119 | }\r | |
120 | }\r | |
121 | \r | |
122 | ~ParserBlackBox()\r | |
123 | {\r | |
124 | delete in; delete scan; delete pipe; delete _parser; delete tok;\r | |
125 | if (1 == openByBlackBox) {\r | |
126 | fclose(file);\r | |
127 | }\r | |
128 | }\r | |
129 | \r | |
130 | Parser *parser() { return _parser; }\r | |
131 | Lexer *getLexer() { return scan; }\r | |
132 | };\r | |
133 | \r | |
134 | #endif\r |