forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
54 lines (41 loc) · 1.25 KB
/
parser.h
File metadata and controls
54 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef LFORTRAN_PARSER_PARSER_H
#define LFORTRAN_PARSER_PARSER_H
#include <fstream>
#include <algorithm>
#include <memory>
#include <libasr/containers.h>
#include <libasr/diagnostics.h>
#include <lpython/parser/tokenizer.h>
namespace LFortran
{
class Parser
{
public:
std::string inp;
public:
diag::Diagnostics &diag;
Allocator &m_a;
Tokenizer m_tokenizer;
Vec<AST::ast_t*> result;
Parser(Allocator &al, diag::Diagnostics &diagnostics)
: diag{diagnostics}, m_a{al} {
result.reserve(al, 32);
}
void parse(const std::string &input);
void handle_yyerror(const Location &loc, const std::string &msg);
};
// Parses Fortran code to AST
Result<AST::TranslationUnit_t*> parse(Allocator &al,
const std::string &s,
diag::Diagnostics &diagnostics);
// Tokenizes the `input` and return a list of tokens
Result<std::vector<int>> tokens(Allocator &al, const std::string &input,
diag::Diagnostics &diagnostics,
std::vector<YYSTYPE> *stypes=nullptr,
std::vector<Location> *locations=nullptr);
// Converts token number to text
std::string token2text(const int token);
std::string fix_continuation(const std::string &s, LocationManager &lm,
bool fixed_form);
} // namespace LFortran
#endif