c-repl/src/include/parser.h

99 lines
2.0 KiB
C
Raw Normal View History

2023-10-27 17:07:58 +02:00
#ifndef DEF_PARSER_H
#define DEF_PARSER_H
2023-10-27 17:16:41 +02:00
#include <vector>
2023-11-10 13:42:53 +01:00
#include <variant>
#include <optional>
2023-11-11 09:11:35 +01:00
#include <stdexcept>
2023-10-27 17:07:58 +02:00
#include "tokenize.h"
2023-12-15 14:57:07 +01:00
#include "errors.h"
2023-10-27 17:07:58 +02:00
using namespace std;
2023-11-10 16:56:50 +01:00
/**
* Utilisé pour revenir en arrière quand quelque chose n'est pas reconnu
*/
2023-12-15 14:11:44 +01:00
class ParseException : public InternalError {
public:
explicit ParseException(CodePosition pos = {})
: InternalError(pos) {}
2023-11-11 09:05:49 +01:00
};
2023-11-10 16:56:50 +01:00
/**
* Parse a list of tokens and return the associated AST
*/
Node parse(vector<Token> tokens);
2023-11-16 14:09:32 +01:00
/**
* Parse something derivated from Prog
*/
ParseReturn parse_prog(vector<Token> tokens);
2023-11-10 16:56:50 +01:00
/**
* Parse something derivated from Instruction
*/
ParseReturn parse_instruction(vector<Token> tokens);
/**
* Parse something derivated from Statement
*/
ParseReturn parse_statement(vector<Token> tokens);
/**
* Parse something derivated from ExprStatement
*/
ParseReturn parse_expr_statement(vector<Token> tokens);
/**
* Parse something derivated from Expr
*/
ParseReturn parse_expr(vector<Token> tokens);
/**
2023-11-23 11:37:03 +01:00
* Parse something derivated from Comp
2023-11-10 16:56:50 +01:00
*/
2023-11-23 11:37:03 +01:00
ParseReturn parse_comp(vector<Token> tokens);
2023-11-10 16:56:50 +01:00
/**
2023-11-23 11:37:03 +01:00
* Parse something derivated from Sum
2023-11-10 16:56:50 +01:00
*/
2023-11-23 11:37:03 +01:00
ParseReturn parse_sum(vector<Token> tokens);
2023-11-10 16:56:50 +01:00
/**
2023-11-23 11:37:03 +01:00
* Parse something derivated from Term
2023-11-10 16:56:50 +01:00
*/
2023-11-23 11:37:03 +01:00
ParseReturn parse_term(vector<Token> tokens);
/**
* Parse something derivated from Unary
*/
ParseReturn parse_unary(vector<Token> tokens);
/**
* Parse something derivated from Val
*/
ParseReturn parse_val(vector<Token> tokens);
2023-11-10 16:56:50 +01:00
/**
* Parse Arguments of a function call
*/
ParseReturn parse_args_values(vector<Token> tokens);
/**
* Parse something derivated from ParIdentifier
* (An identifier with 0+ parentheses around it)
*/
ParseReturn parse_par_identifier(vector<Token> tokens);
2023-12-27 18:43:56 +01:00
/**
* Parse the arguments of a function
* Type1 Identifier1, Type2 Identifier2
* and returns it as a node with Declaration as children
*/
tuple<ParseReturn, optional<CodePosition>> parse_args(vector<Token> tokens);
2023-12-27 18:43:56 +01:00
2023-11-10 19:04:24 +01:00
/**
* Prints a tree for debugging it
*/
void _debug_print_tree(const Node& node, int depth = 0, const string& prefix = "");
2023-11-10 19:04:24 +01:00
2023-10-27 17:07:58 +02:00
#endif