Implements variable usage, tweaks and fixes for variable assignment
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "../Token.hpp"
|
||||
#include "../UnaryOperatorKind.hpp"
|
||||
#include "../BinaryOperatorKind.hpp"
|
||||
#include "../../Utilities/HashedString.hpp"
|
||||
|
||||
enum class ParsedExpressionKind{
|
||||
Bad,
|
||||
@@ -13,6 +14,7 @@ enum class ParsedExpressionKind{
|
||||
LiteralFloat,
|
||||
LiteralString,
|
||||
LiteralBool,
|
||||
Variable,
|
||||
|
||||
Unary,
|
||||
Binary,
|
||||
@@ -113,6 +115,23 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class VariableExpression : public ParsedExpression{
|
||||
HashedString _value;
|
||||
public:
|
||||
ParsedExpressionKind GetKind() final{
|
||||
return ParsedExpressionKind::Variable;
|
||||
}
|
||||
explicit VariableExpression(IdentifierToken* token) : ParsedExpression(token -> GetStartPosition(), token -> GetLength())
|
||||
, _value(HashedString(token -> Value))
|
||||
{
|
||||
}
|
||||
|
||||
HashedString GetValue(){
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ParenthesizedExpression : public ParsedExpression{
|
||||
ParsedExpression* _expression;
|
||||
public:
|
||||
|
||||
@@ -151,6 +151,7 @@ ParsedExpression *Parser::ParsePrimaryExpression(IToken *current) {
|
||||
case TokenKind ::String: return new LiteralStringExpression((StringToken*)current);
|
||||
case TokenKind ::TrueKeyword: return new LiteralBoolExpression(current);
|
||||
case TokenKind ::FalseKeyword: return new LiteralBoolExpression(current);
|
||||
case TokenKind ::Identifier: return new VariableExpression((IdentifierToken*)current);
|
||||
case TokenKind ::OpenParenthesis: return this -> ParseParenthesizedExpression(current);
|
||||
// If we find a bad token here, we should have already logged it in the lexer, so don't log another error.
|
||||
case TokenKind ::BadToken: return new BadExpression(current->GetStartPosition(), current->GetLength());
|
||||
|
||||
Reference in New Issue
Block a user