Implements variable usage, tweaks and fixes for variable assignment

This commit is contained in:
2019-05-30 15:23:48 +02:00
parent 257eb942c7
commit 6fad5a0a7d
17 changed files with 145 additions and 4 deletions

View File

@@ -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:

View File

@@ -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());