3 * https://github.com/vrmiguel/minirepl
5 * Copyright (c) 2020 VinÃcius R. Miguel <vinicius.miguel at unifesp.br>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "Headers/token.h"
28 std::ostream
& operator<<(std::ostream
&strm
, const Token
&tok
)
46 vartype
= "SPACE"; // TODO: SPACE is not getting printed
47 return strm
<< "Token(" << vartype
<< ", " << "\' \'" << ")";
71 vartype
= "UNKNOWN"; // Control really shouldn't reach this point
74 return strm
<< "Token(" << vartype
<< ", " << tok
.var_value
<< ")";
77 bool operator==(const Token t1
, const Token t2
)
79 return t1
.var_type
== t2
.var_type
&& t1
.var_value
== t2
.var_value
;
82 bool contains(vector
<Token
> tokens
, Token t
)
84 return std::count(tokens
.begin(), tokens
.end(), t
);
87 inline bool is_valid(int var_type
)
89 return (var_type
> -1) && (var_type
< TOKEN_TYPE_COUNT
);
92 Token::Token(int var_type
, string var_value
)
94 if (is_valid(var_type
))
96 this->var_type
= var_type
;
97 this->var_value
= var_value
;
99 cerr
<< "The type" << var_type
<< "is not valid.";
104 Token::Token(int var_type
, char var_value
)
106 if (is_valid(var_type
))
108 this->var_type
= var_type
;
109 this->var_value
= string(1, var_value
);
112 cerr
<< "The type" << var_type
<< "is not valid.";