Add booleans

This commit is contained in:
Danila Fedorin 2019-05-27 21:57:41 -07:00
parent 626fd1629b
commit ede35fe3ba
3 changed files with 20 additions and 3 deletions

View File

@ -96,7 +96,7 @@ primary_expression
: IDENTIFIER { $$ = new expr_id(*$1); delete $1; }
| FLOAT { $$ = new expr_float(std::stod(*$1)); delete $1; }
| INTEGER { $$ = new expr_int(std::stoi(*$1)); delete $1; }
| BOOLEAN { $$ = new expr_int(*$1 == "True"); delete $1; }
| BOOLEAN { $$ = new expr_bool(*$1 == "True"); delete $1; }
| LPAREN expression RPAREN { $$ = $2; }
;

View File

@ -16,6 +16,11 @@ std::string label<const char*>(const char* v) {
return v;
}
template <>
std::string label<bool>(bool v) {
return v ? "TRUE" : "FALSE";
}
template <>
std::string label<binop>(binop op) {
switch(op) {
@ -67,12 +72,16 @@ void expr_id::print_dot(dot& into, std::string prefix) {
into.push_back(prefix + wrap_label(std::string("identifier: ") + id, true));
}
void expr_bool::print_dot(dot& into, std::string prefix) {
into.push_back(prefix + wrap_label(std::string("Boolean: ") + label(val), true));
}
void expr_int::print_dot(dot& into, std::string prefix) {
into.push_back(prefix + wrap_label(std::string("integer: ") + label(val), true));
into.push_back(prefix + wrap_label(std::string("Integer: ") + label(val), true));
}
void expr_float::print_dot(dot& into, std::string prefix) {
into.push_back(prefix + wrap_label(std::string("float: ") + label(val), true));
into.push_back(prefix + wrap_label(std::string("Float: ") + label(val), true));
}
void expr_binop::print_dot(dot& into, std::string prefix) {

View File

@ -41,6 +41,14 @@ struct expr_id : expr {
virtual void print_dot(dot& into, std::string prefix);
};
struct expr_bool : expr {
bool val;
expr_bool(bool v) : val(v) {}
virtual void print_dot(dot& into, std::string prefix);
};
struct expr_int : expr {
int val;