wip
This commit is contained in:
14
README.md
Normal file
14
README.md
Normal file
@@ -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 ")"
|
||||||
@@ -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";
|
||||||
|
}*/
|
||||||
@@ -1,8 +1,25 @@
|
|||||||
#ifndef EXPRESSION_H
|
#ifndef EXPRESSION_H
|
||||||
#define EXPRESSION_H
|
#define EXPRESSION_H
|
||||||
|
|
||||||
|
#include "Token.h"
|
||||||
|
|
||||||
|
class ExpressionInvalid;
|
||||||
|
|
||||||
class Expression {
|
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
|
#endif
|
||||||
@@ -1,5 +1,24 @@
|
|||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
|
||||||
std::vector Parser::getExpressions() {
|
Parser::Parser(std::vector<Token> 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;
|
||||||
}
|
}
|
||||||
15
src/Parser.h
15
src/Parser.h
@@ -2,13 +2,22 @@
|
|||||||
#define PARSER_H
|
#define PARSER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <Token.h>
|
#include "Token.h"
|
||||||
#include <Expression.h>
|
#include "Expression.h"
|
||||||
|
|
||||||
class Parser {
|
class Parser {
|
||||||
|
private:
|
||||||
|
std::vector<Token> tokens;
|
||||||
|
int currentIndex = 0;
|
||||||
|
|
||||||
|
//Expression term();
|
||||||
|
//Expression primary();
|
||||||
|
|
||||||
|
Expression matchInteger();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Parser(std::vector<Token> tokens);
|
Parser(std::vector<Token> tokens);
|
||||||
std::vector<Expression> getExpressions();
|
//Expression getExpression();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user