From d5d21aa422d407fb3af0153c6d4dcc7a6f7d75b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Grodzi=C5=84ski?= Date: Thu, 29 May 2025 22:02:44 +0900 Subject: [PATCH] wip --- README.md | 14 ++++++++++++++ src/Expression.cpp | 14 ++++++++++++++ src/Expression.h | 17 +++++++++++++++++ src/Parser.cpp | 21 ++++++++++++++++++++- src/Parser.h | 15 ++++++++++++--- 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8edeb1b --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +expression := literal | binary | grouping + +literal := INTEGER + +grouping := "(" expression ")" + +binary := expression operator expression + +operator := "+" | "-" | "*" | "/" | "%" + +expression +term factor "+" | "-" factor +factor primary "*" | "/" primary +primary INTEGER | "(" expression ")" \ No newline at end of file diff --git a/src/Expression.cpp b/src/Expression.cpp index e69de29..e8c35f3 100644 --- a/src/Expression.cpp +++ b/src/Expression.cpp @@ -0,0 +1,14 @@ +#include "Expression.h" + +ExpressionInvalid Expression::Invalid = ExpressionInvalid(); + +std::string ExpressionInvalid::toString() { + return "Invalid"; +} + +/*ExpressionInteger::ExpressionInteger(Token token) { +} + +std::string ExpressionInteger::toString() { + return "INTEGER"; +}*/ \ No newline at end of file diff --git a/src/Expression.h b/src/Expression.h index 3795f01..5adc04b 100644 --- a/src/Expression.h +++ b/src/Expression.h @@ -1,8 +1,25 @@ #ifndef EXPRESSION_H #define EXPRESSION_H +#include "Token.h" + +class ExpressionInvalid; + class Expression { +public: + static ExpressionInvalid Invalid; + + virtual std::string toString() = 0; +}; + +class ExpressionInvalid { }; +/*class ExpressionInteger: Expression { +public: + ExpressionInteger(Token token); + std::string toString() override; +};*/ + #endif \ No newline at end of file diff --git a/src/Parser.cpp b/src/Parser.cpp index ff13031..f4403be 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -1,5 +1,24 @@ #include "Parser.h" -std::vector Parser::getExpressions() { +Parser::Parser(std::vector tokens) : tokens(tokens) { +} +/*Expression Parser::getExpression() { + return term(); +}*/ + +/*Expression Parser::term() { + +}*/ + +/*Expression Parser::primary() { + +}*/ + +Expression Parser::matchInteger() { + //Token token = tokens.at(currentIndex); + //if (token.getKind() == Token::Kind::INTEGER) + // ExpressionInteger(token); + + return Expression::Invalid; } \ No newline at end of file diff --git a/src/Parser.h b/src/Parser.h index c2b9cfb..8ad227c 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -2,13 +2,22 @@ #define PARSER_H #include -#include -#include +#include "Token.h" +#include "Expression.h" class Parser { +private: + std::vector tokens; + int currentIndex = 0; + + //Expression term(); + //Expression primary(); + + Expression matchInteger(); + public: Parser(std::vector tokens); - std::vector getExpressions(); + //Expression getExpression(); }; #endif \ No newline at end of file