Added expression unary
This commit is contained in:
@@ -50,10 +50,10 @@ i u32 <- 0, rep text[i] != 0:
|
|||||||
|
|
||||||
main fun -> u32
|
main fun -> u32
|
||||||
num1 u8 <- 42
|
num1 u8 <- 42
|
||||||
num2 s8 <- 15
|
num2 s8 <- -15
|
||||||
num3 u32 <- 1234123
|
num3 u32 <- 1234123
|
||||||
num4 s32 <- 345345
|
num4 s32 <- -345345
|
||||||
num5 r32 <- 42.58
|
num5 r32 <- -42.58
|
||||||
|
|
||||||
ret 0
|
ret 0
|
||||||
;
|
;
|
||||||
@@ -12,6 +12,7 @@ enum class ExpressionKind {
|
|||||||
LITERAL,
|
LITERAL,
|
||||||
ARRAY_LITERAL,
|
ARRAY_LITERAL,
|
||||||
GROUPING,
|
GROUPING,
|
||||||
|
UNARY,
|
||||||
BINARY,
|
BINARY,
|
||||||
IF_ELSE,
|
IF_ELSE,
|
||||||
VAR,
|
VAR,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#include "Parser/Expression/Expression.h"
|
#ifndef EXPRESSION_BINARY_H
|
||||||
|
#define EXPRESSION_BINARY_H
|
||||||
|
|
||||||
|
#include "Expression.h"
|
||||||
|
|
||||||
enum class ExpressionBinaryOperation {
|
enum class ExpressionBinaryOperation {
|
||||||
EQUAL,
|
EQUAL,
|
||||||
@@ -27,3 +30,5 @@ public:
|
|||||||
shared_ptr<Expression> getLeft();
|
shared_ptr<Expression> getLeft();
|
||||||
shared_ptr<Expression> getRight();
|
shared_ptr<Expression> getRight();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
26
src/Parser/Expression/ExpressionUnary.cpp
Normal file
26
src/Parser/Expression/ExpressionUnary.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "ExpressionUnary.h"
|
||||||
|
|
||||||
|
#include "Lexer/Token.h"
|
||||||
|
|
||||||
|
ExpressionUnary::ExpressionUnary(shared_ptr<Token> token, shared_ptr<Expression> expression):
|
||||||
|
Expression(ExpressionKind::UNARY, nullptr), expression(expression) {
|
||||||
|
switch (token->getKind()) {
|
||||||
|
case TokenKind::PLUS:
|
||||||
|
operation = ExpressionUnaryOperation::PLUS;
|
||||||
|
break;
|
||||||
|
case TokenKind::MINUS:
|
||||||
|
operation = ExpressionUnaryOperation::MINUS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
operation = ExpressionUnaryOperation::INVALID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionUnaryOperation ExpressionUnary::getOperation() {
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<Expression> ExpressionUnary::getExpression() {
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
23
src/Parser/Expression/ExpressionUnary.h
Normal file
23
src/Parser/Expression/ExpressionUnary.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef EXPRESSION_UNARY_H
|
||||||
|
#define EXPRESSION_UNARY_H
|
||||||
|
|
||||||
|
#include "Expression.h"
|
||||||
|
|
||||||
|
enum class ExpressionUnaryOperation {
|
||||||
|
PLUS,
|
||||||
|
MINUS,
|
||||||
|
INVALID
|
||||||
|
};
|
||||||
|
|
||||||
|
class ExpressionUnary: public Expression {
|
||||||
|
private:
|
||||||
|
ExpressionUnaryOperation operation;
|
||||||
|
shared_ptr<Expression> expression;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExpressionUnary(shared_ptr<Token> token, shared_ptr<Expression> expression);
|
||||||
|
ExpressionUnaryOperation getOperation();
|
||||||
|
shared_ptr<Expression> getExpression();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user