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