diff --git a/parser.y b/parser.y index c4f1630..fe4b923 100644 --- a/parser.y +++ b/parser.y @@ -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; } ; diff --git a/tree.cpp b/tree.cpp index ad7da2a..0f8cb5e 100644 --- a/tree.cpp +++ b/tree.cpp @@ -16,6 +16,11 @@ std::string label(const char* v) { return v; } +template <> +std::string label(bool v) { + return v ? "TRUE" : "FALSE"; +} + template <> std::string label(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) { diff --git a/tree.hpp b/tree.hpp index e1c4eec..4f22b12 100644 --- a/tree.hpp +++ b/tree.hpp @@ -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;