Add booleans
This commit is contained in:
parent
626fd1629b
commit
ede35fe3ba
2
parser.y
2
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; }
|
||||
;
|
||||
|
||||
|
|
13
tree.cpp
13
tree.cpp
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user