-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQPMain.cpp
174 lines (140 loc) · 4.95 KB
/
QPMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*------------------------------------------------------------------------------+
| |
| QP - QSDL Parser |
| |
| (C) 1994-98 Marc Diefenbruch |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+-------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+-------+
| QPMain | QPMain.cpp | 9. Aug 1994 | QP | |
+------------------------------------------------------------------------------*/
/* Lineal
000000000011111111112222222222333333333344444444445555555555666666666677777777778
012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
/****************************************************************************
* Modul: QPMain
*
* Aufgabe: Dies ist der Hauptmodul des Parsers.
* Funktionen: yywarning(): Funktion zum Ausgeben der Parser-Warnungen
* yyerror(): Funktion zum Ausgeben der Parser-Fehlermeldungen
* ParseSpecification(): Eigentliche Parse-Funktion
****************************************************************************/
#ifdef USE_PRAGMA
#pragma interface
#endif
/****************************************************************************
* Includes
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "QPLexYacc.h"
#include <DS/DSSystem.h>
#include <DS/DSString.h>
#include "QPBasicTypes.h"
#include "QPObjects.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
/****************************************************************************
* Externe Variablen
****************************************************************************/
extern int line_count;
extern FILE *yyin;
extern int err_recover;
extern int error_counter;
extern int warning_counter;
/****************************************************************************
* Globale Variablen
****************************************************************************/
int warnings;
DSSystem *p_system = NULL;
DSStream *qp_cout;
DSObjectRefStack p_stack;
extern "C" {
extern int yyparse(void);
extern void yyrestart(FILE *);
}
/****************************************************************************
* Funktionen
****************************************************************************/
QPResult ParseSpecification(DSSystem **system,
DSString *filename,
DSStream &myCout,
DSBoolean verbose,
DSBoolean print_warnings)
{
int ret;
DSString path;
error_counter = 0;
warning_counter = 0;
line_count = 1;
p_system = NULL;
qp_cout = &myCout;
warnings = (int)print_warnings;
if (filename == NULL) // wird von stdin gelesen?
{
if (verbose) *qp_cout << "\nParsing stdin...\n";
ret = yyparse();
if (!ret)
{
if (verbose)
{
*qp_cout << std::endl << "Syntax check complete." << std::endl;
*qp_cout << line_count << " lines processed." << std::endl;
*qp_cout << error_counter << " errors." << std::endl;
if (warnings)
*qp_cout << warning_counter << " warnings." << std::endl;
}
}
}
else
{
yyin = fopen(filename->GetString(), "r");
if(!yyin)
{
if (getenv("QUEST_SPEC_DIR") != NULL)
{
path = getenv("QUEST_SPEC_DIR");
if (path[path.Length() - 1] != CG_PATH_SEPARATOR_CHAR)
{
path += CG_PATH_SEPARATOR_STRING;
}
path += *filename;
}
else
{
*qp_cout << "Warning: environment variable 'QUEST_SPEC_DIR' not set." << std::endl;
path = *filename;
}
yyin = fopen(path.GetString(), "r");
}
if(!yyin)
{
*qp_cout << "Can't open file " << path << "!" << std::endl;
return QP_ERROR;
}
if (verbose)
*qp_cout << "Parsing file " << filename << "..." << std::endl;
yyrestart(yyin);
ret = yyparse();
fclose(yyin);
if (!ret)
{
if (verbose)
{
*qp_cout << std::endl << "Syntax check complete." << std::endl;
*qp_cout << line_count << " lines of file " << filename << " processed." << std::endl;
*qp_cout << error_counter << " errors." << std::endl;
if (warnings)
*qp_cout << warning_counter << " warnings." << std::endl;
}
}
}
*system = p_system;
if (ret || error_counter > 0) return QP_SYNTAX_ERROR;
return QP_OK;
}