Finally, some real progress on the AST!!
This commit is contained in:
parent
73f3f20a71
commit
98b14e6bf5
@ -7,4 +7,39 @@ class NumberNode : public ExprNode
|
||||
public:
|
||||
NumberNode();
|
||||
~NumberNode();
|
||||
|
||||
virtual bool is_floating()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool is_integral()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> class BasicNumberNode : public NumberNode
|
||||
{
|
||||
T value;
|
||||
|
||||
public:
|
||||
BasicNumberNode(T value) : value(value)
|
||||
{
|
||||
}
|
||||
~BasicNumberNode()
|
||||
{
|
||||
}
|
||||
|
||||
constexpr bool is_floating() override
|
||||
{
|
||||
return std::is_floating_point<T>::value;
|
||||
}
|
||||
|
||||
constexpr bool is_integral() override
|
||||
{
|
||||
return std::is_integral<T>::value;
|
||||
}
|
||||
};
|
||||
|
||||
using IntegerNode = BasicNumberNode<int>;
|
||||
using FloatNode = BasicNumberNode<float>;
|
@ -34,7 +34,19 @@ Parser::ErrorOr<ExprNode> Parser::walk_expr()
|
||||
|
||||
Parser::ErrorOr<NumberNode> Parser::walk_number()
|
||||
{
|
||||
return ErrorOr<NumberNode>(new NumberNode());
|
||||
Token& current_token = tokens[m_index++];
|
||||
if (current_token.tk_type == TT_Number)
|
||||
{
|
||||
return ErrorOr<NumberNode>(new IntegerNode(current_token.int_value));
|
||||
}
|
||||
else if (current_token.tk_type == TT_Float)
|
||||
{
|
||||
return ErrorOr<NumberNode>(new FloatNode(current_token.float_value));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorOr<NumberNode>("expected a number", current_token);
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::save_current_position()
|
||||
|
Loading…
Reference in New Issue
Block a user