summaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorHombreLaser <buran@silosneeded.com>2024-07-15 22:52:10 -0600
committerHombreLaser <buran@silosneeded.com>2024-07-15 22:52:10 -0600
commitee906c84b866cd175b31b6d90778b3d8c19212c8 (patch)
treead80d5ba1acf88538f0a78a9c15b83c506443c5e /src/parser.cpp
parent404826e78a56e15e20d3938aed80945295921745 (diff)
Add parserHEADmaster
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
new file mode 100644
index 0000000..68c2297
--- /dev/null
+++ b/src/parser.cpp
@@ -0,0 +1,63 @@
+#include <string>
+#include "include/tokenizer.hpp"
+#include "include/syntax_tree.hpp"
+#include "include/parser.hpp"
+
+const SyntaxTree *Parser::parse(const std::string &input) {
+ tokens = tokenizer.tokenize(input);
+ current_token = tokens[0];
+
+ return nullptr;
+}
+
+void Parser::parseExpression() {
+ parseTerm();
+ parsePrimeExpression();
+}
+
+void Parser::parsePrimeExpression() {
+ if(current_token->type == nil)
+ return;
+
+ if(current_token->type == sum || current_token->type == substraction) {
+ ++current_token;
+ parseExpression();
+ }
+}
+
+void Parser::parseTerm() {
+ parseFactor();
+ parsePrimeTerm();
+}
+
+void Parser::parsePrimeTerm() {
+ if(current_token->type == nil)
+ return;
+
+ if(current_token->type == multiplication ||
+ current_token->value == division) {
+ ++current_token;
+ parseTerm();
+ }
+}
+
+void Parser::parseFactor() {
+ switch(current_token->type) {
+ case substraction:
+ ++current_token;
+ parseExpression();
+ break;
+ case left_parens:
+ ++current_token;
+ parseExpression();
+ if(current_token->type != right_parens)
+ return;
+ ++current_token;
+ break;
+ case operand:
+ ++current_token;
+ break;
+ default:
+ return;
+ }
+}