VapourSynth-llvmexpr
Loading...
Searching...
No Matches
Parser.hpp
Go to the documentation of this file.
1
19
20#ifndef LLVMEXPR_FRONTEND_INFIX2POSTFIX_PARSER_HPP
21#define LLVMEXPR_FRONTEND_INFIX2POSTFIX_PARSER_HPP
22
23#include "AST.hpp"
24
25#include <set>
26#include <vector>
27
28namespace infix2postfix {
29
30struct ErrorInfo {
31 std::string message;
33};
34
36 std::unique_ptr<Program> ast;
37 std::vector<ErrorInfo> errors;
38};
39
40class Parser {
41 public:
42 explicit Parser(const std::vector<Token>& tokens);
44
45 private:
46 std::unique_ptr<Stmt> parseDeclaration();
47 std::unique_ptr<Stmt> parseStatement();
48 std::unique_ptr<Stmt> parseIfStatement();
49 std::unique_ptr<Stmt> parseWhileStatement();
50 std::unique_ptr<Stmt> parseGotoStatement();
51 std::unique_ptr<Stmt> parseLabelStatement();
52 std::unique_ptr<Stmt> parseReturnStatement();
53 std::unique_ptr<BlockStmt> parseBlock();
54 std::unique_ptr<Stmt> parseExprStatement();
55 std::unique_ptr<FunctionDef> parseFunctionDef();
56 std::unique_ptr<GlobalDecl> parseGlobalDecl();
57
58 std::unique_ptr<Expr> parseTernary();
59
60 template <typename NextLevel, typename... TokenTypes>
61 std::unique_ptr<Expr> parseBinary(NextLevel next_level,
62 TokenTypes... token_types);
63
64 std::unique_ptr<Expr> parseLogicalOr();
65 std::unique_ptr<Expr> parseLogicalAnd();
66 std::unique_ptr<Expr> parseBitwiseOr();
67 std::unique_ptr<Expr> parseBitwiseXor();
68 std::unique_ptr<Expr> parseBitwiseAnd();
69 std::unique_ptr<Expr> parseEquality();
70 std::unique_ptr<Expr> parseComparison();
71 std::unique_ptr<Expr> parseTerm();
72 std::unique_ptr<Expr> parseFactor();
73 std::unique_ptr<Expr> parseExponent();
74 std::unique_ptr<Expr> parseUnary();
75 std::unique_ptr<Expr> parsePostfix();
76 std::unique_ptr<Expr> parsePrimary();
77 std::unique_ptr<Expr> finishCall(std::unique_ptr<Expr> callee);
78
79 bool match(const std::vector<TokenType>& types);
80 Token consume(TokenType type, const std::string& message);
81 Token advance();
82 [[nodiscard]] Token peek() const;
83 [[nodiscard]] Token peek(int offset) const;
84 [[nodiscard]] Token previous() const;
85 [[nodiscard]] bool isAtEnd() const;
86 void error(const Token& token, const std::string& message);
87 void synchronize();
88 void reportError(const Token& token, const std::string& message);
89
90 std::vector<Token> tokens;
91 int current = 0;
92 std::set<std::string> defined_functions;
93 std::vector<ErrorInfo> errors;
94 bool panic_mode = false;
95};
96
97} // namespace infix2postfix
98
99#endif // LLVMEXPR_FRONTEND_INFIX2POSTFIX_PARSER_HPP
Parser(const std::vector< Token > &tokens)
Definition Parser.cpp:30
ParseResult parse()
Definition Parser.cpp:32
std::vector< ErrorInfo > errors
Definition Parser.hpp:37
std::unique_ptr< Program > ast
Definition Parser.hpp:36