-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparse.cc
113 lines (98 loc) · 2.48 KB
/
parse.cc
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
/**********************************************************************
This file is part of the Quantum Computation Language QCL.
(c) Copyright by Bernhard Oemer <[email protected]>, 1998
This program comes without any warranty; without even the implied
warranty of merchantability or fitness for any particular purpose.
This program is free software under the terms of the
GNU General Public Licence (GPL) version 2 or higher
************************************************************************/
#include "syntax.h"
#include "symbols.h"
#include "error.h"
#include "parse.h"
#include "options.h"
objlist *yyObjList;
int yyTest;
FILE* yyToplevelFile;
int yyStringBufferActive;
string yyFilenames[YYMAXINCLUDE];
FILE* yyFilePointers[YYMAXINCLUDE];
int yyLineNos[YYMAXINCLUDE];
int yyIncludeStackPt = 0;
string yyFilename="<input>";
extern char *yytext;
extern int yylineno;
string safestring(const char *s) {
string t;
while(*s) {
if(isprint(*s))
t+=*s;
else
t+=sdec(*s,"\\0%lo");
s++;
}
return t;
}
int yyerror(char* s) {
string t;
if(!yyStringBufferActive) {
t+="in "+yyFilename+", line "+sdec(yylineno)+", ";
};
t+="near \""+safestring(yytext)+"\"";
qclerror(t);
qclerror(s);
return 1;
}
FILE* openqclfile(string fname) {
string s;
FILE *f;
s=fname;
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
s=fname+".qcl";
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
if(optUserPath!="") {
s=optUserPath+"/"+fname;
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
s=optUserPath+"/"+fname+".qcl";
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
}
if(optIncludePath!="") {
s=optIncludePath+"/"+fname;
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
s=optIncludePath+"/"+fname+".qcl";
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
}
s="lib/"+fname;
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
s="lib/"+fname+".qcl";
if(( f=fopen(s.c_str(),"r") )) { yyFilename=s; return f; };
return 0;
}
int chksyntax(string s) {
int r;
yyTest=1;
yyObjList=0;
yyScanString(s);
r=yyparse();
yyCleanUp();
yyTest=0;
return r;
}
int chksyntax(FILE* f) {
int r;
yyTest=1;
yyObjList=0;
yyScanFile(f);
r=yyparse();
yyCleanUp();
yyTest=0;
return r;
}
objlist* parseobj() {
yyTest=0;
yyObjList=0;
int r;
r=yyparse();
if(r || !yyObjList) qclabort("parsing failed");
return yyObjList;
}