-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrontEnd.h
56 lines (46 loc) · 1.81 KB
/
FrontEnd.h
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
55
56
#pragma once
#include "ASTProgram.h"
#include "antlr4-runtime.h"
#include <fstream>
#include <iostream>
//! \brief Lexer error listener for redirecting ANTLR4 errors to ParseError.
class LexerErrorListener : public antlr4::BaseErrorListener {
public:
LexerErrorListener() = default;
virtual void syntaxError(antlr4::Recognizer *recognizer,
antlr4::Token *offendingSymbol, size_t line,
size_t charPositionInLine, const std::string &msg,
std::exception_ptr e) override;
};
//! \brief Parse error listener for redirecting ANTLR4 errors to ParseError.
class ParserErrorListener : public antlr4::BaseErrorListener {
public:
ParserErrorListener() = default;
virtual void syntaxError(antlr4::Recognizer *recognizer,
antlr4::Token *offendingSymbol, size_t line,
size_t charPositionInLine, const std::string &msg,
std::exception_ptr e) override;
};
/*! \class FrontEnd
* \brief A collection of routines implementing the compiler front end.
*/
class FrontEnd {
public:
/*! \fn parse
* \brief Parse an input stream and return an AST.
*
* Parsing can detect errors, which are reported via throw of a ParseError
* exception. In the absence of errors, ownership of the generated AST is
* transfered to the caller.
* \param stream the input stream holding the program text.
* \return the generated AST.
*/
static std::shared_ptr<ASTProgram> parse(std::istream &stream);
/*! \fn print
* \brief Print program in a standard form to cout.
*
* \param program the root of an AST for a TIP program.
*/
static void prettyprint(ASTProgram *program, std::ostream &os);
static void astVisualize(std::shared_ptr<ASTNode> node, std::ostream &os);
};