Add var read expression

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-29 21:40:54 +02:00
committed by CHatingPython
parent 1fa9e50b57
commit 8d162f926a
5 changed files with 47 additions and 4 deletions
+10
View File
@@ -34,6 +34,16 @@ bool expression_node::equal(const node& rhs) const {
return expression_type() == reinterpret_cast<const expression_node&>(rhs).expression_type();
}
std::ostream& var_read_expression_node::print(std::ostream& os) const {
if (m_name.present()) return os << *m_name;
return os << m_name.error();
}
bool var_read_expression_node::equal(const node& rhsNode) const {
const auto& rhs = reinterpret_cast<const var_read_expression_node&>(rhsNode);
return expression_node::equal(rhsNode) && m_name == rhs.m_name;
}
std::ostream& operator<<(std::ostream& os, unaryop_expression_node_t type) {
switch (type) {
case unaryop_expression_node_t::Positive: return os << "+";
+6
View File
@@ -146,6 +146,12 @@ ast::literal_node_h parser::parse_literal() {
ast::expression_node_h parser::parse_expression_primary() {
const auto& tok = peek_token();
switch (tok->type) {
case token_t::Identifier: {
auto tok = next_token();
return ast::var_read_expression_node_h{ tok.location(),
m_arena,
handle<std::string_view>{ tok.location(), (*tok)->string } };
}
case token_t::Lparen: {
auto tok = next_token();
auto node = parse_expression();
+1 -1
View File
@@ -5,7 +5,7 @@
#include <iostream>
int main(void) {
furc::front::parser parser("<TEMP>", "func main() {\n return (6 - -7) * 9++;\n}");
furc::front::parser parser("<TEMP>", "func main() {\n return (x - -y) * z++;\n}");
std::cout << parser.parse() << '\n';
return 0;