forked from FreeFem/FreeFem-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex.hpp
176 lines (139 loc) · 5.06 KB
/
lex.hpp
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
175
176
/// \file
// -*- Mode : c++ -*-
//
// SUMMARY :
// USAGE :
// ORG :
// AUTHOR : Frederic Hecht
// E-MAIL : [email protected]
//
/*
This file is part of Freefem++
Freefem++ is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
Freefem++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Freefem++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MY_LEX_HPP_
#define MY_LEX_HPP_
// with New version of macro expansion more simple and more stable
// FH jan 2005
#include <stack>
#include "environment.hpp"
extern bool lexdebug;
extern long mpisize,mpirank;
/// <<mylex>>
class mylex : public CodeAlloc {
public:
typedef const char * Key;
typedef pair<int,aType> Value;
struct MacroData{ deque<string> d; int l; string f;};// f is not a pointeur (pb of delete)
// Warning f not a pointeur because
//
struct Keyless : binary_function<Key,Key, bool>
{ bool operator()(const Key& x, const Key& y) const{ return strcmp(x,y)<0;} };
typedef map<const char *,Value,Keyless> MapMotClef;
typedef map<const char *,MacroData ,Keyless > MapMacroDef;
typedef map<string, string > MapMacroParam;
typedef MapMotClef::const_iterator const_iterator;
typedef MapMotClef::iterator iterator;
public:
int linenumber,charnumber;
list<string> ffincludedir; // <<ffincludedir>>
typedef list<string>::iterator Iffincludedir;
typedef list<string>::const_iterator ICffincludedir;
private:
bool firsttime;
int level;
char buf[1024];
int typetoken;
bool echo;
stack<char *> strdata;
struct xxxx {
int l;
istream * f;
const string * filename; // <<filename>>
int macroarg;
istream * nf;
xxxx() : l(0), f(0) , filename(0),macroarg(0),nf(0) {}
void open(mylex *lexx,const char * ff) ;
void readin(mylex *lexx,const string & s,const string *name=0,int macroargg=0);
void close() ;
};
friend struct mylex::xxxx;
xxxx pilesource[100];
istream & source() const {return * pilesource[level].f;}
const string file() const { return pilesource[level].filename? *pilesource[level].filename : string("") ;}
ostream & cout ;
// <<MotClef>>
MapMotClef MotClef;
list<MapMacroDef> *listMacroDef;
list<MapMacroParam> *listMacroParam;
public:
mylex(ostream & out,bool eecho=true,const KN<String> *pargs=0 );
string token() const;
void print(ostream &f) const;
/// This is the main [[file:../lglib/lg.ypp::yylex]] entry point from the grammar. Implemented in
/// [[file:lex.cpp::mylex_scan]]
int scan(int lvl=0);
int lineno(){return linenumber;}
char * YYText() { return buf;}
void dump(ostream & f ) ;
void erreur(const char * s) {
cerr << " Error line number" <<linenumber << ": " << s << endl;
throw(ErrorCompile("lex:",linenumber)); }
bool InMotClef (aType & t, int & r) const ;
// ALH - 5/4/15 - <<InMotClef_string>> [[file:lex.cpp::mylex_input_string]]
bool InMotClef(const char *b,aType &t,int &r)const;
void Add(Key k,int r,aType t);
void Check(bool b,Key k,const char * s) {
if(b) {cout <<"Add " << s << " null: " << k << endl;
CompileError();}}
void Add(Key k,int i) ;// {Check(!i,k,"mot clef");Add(k,i,0); }
void Add(Key k,aType t);// {Check(!t,k,"type");Add(k,TYPE,t); }
void AddF(Key k,aType t);// {Check(!t,k,"type");Add(k,FUNCTION,t); }
void AddSpace(Key k,aType t);// {Check(!t,k,"type");Add(k,FUNCTION,t); }
const char * filename() const {
if ( level >=0 )
return pilesource[level].filename ? pilesource[level].filename->c_str() : " -- in macro -- ";
return "-- unkown --";}
void input(const char * filename) ;
void input(const string &str,const string *name=0,int lg=0);
bool close() ;
char * newcopy(const char * s)
{
char *r(new char [strlen(s)+1]);
strcpy(r, s);
strdata.push(r);
return r;
}
ostream & ShowStack(ostream & f);
~mylex();
private:
int basescan();
int basescanprint(int lvl=0); // with print if lvl =0
int EatCommentAndSpace(string *data=0);
int scan1();
bool SetMacro(int &ret);
bool CallMacro(int &ret);
bool IFMacro(int &ret);
bool AddMacro(string m,string def) ;
char * match(int i);
void ErrorScan(const char * s) {
cerr << "\n" ;
ShowStack(cerr);
throw(ErrorCompile(s,lineno(),YYText() ) );}
} ;
mylex * Newlex( ostream & out,bool =true,KN<String> * args=0);
void Destroylex(mylex * m);
/// <<zzzfff>> This pointer is allocated in [[file:global.cpp::zzzfff]] and initialized in
/// [[file:../lglib/lg.ypp::zzzfff]]
extern mylex *zzzfff;
#endif