GSC Interpreter
A Turing-complete interpreter developed for a compiler course
Loading...
Searching...
No Matches
error.cpp
Go to the documentation of this file.
1#include "gsc/error.hpp"
2#include <iostream>
3
4void report(const int &line, const std::string &where,
5 const std::string &message) {
6 std::cerr << "[line " << line << "] Error " << where << ": " << message
7 << "\n";
8
9 hadError = true;
10}
11
12void error(const int &line, const std::string &message) {
13 report(line, "", message);
14}
15
16void error(const Token &token, const std::string &message) {
17 if (token.getType() == TokenType::END_OF_FILE) {
18 report(token.getLine(), "at end", message);
19 } else {
20 report(token.getLine(), "at '" + token.getLexeme() + "'", message);
21 }
22}
23
24void runtimeError(const RuntimeError &error) {
25 std::cerr << error.getMessage() << "\n[line " << error.getToken()->getLine()
26 << "]" << std::endl;
27 hadRuntimeError = true;
28}
void error(const int &line, const std::string &message)
Report an error in the given line.
Definition error.cpp:12
void runtimeError(const RuntimeError &error)
Report a runtime error given a RuntimeError object.
Definition error.cpp:24
void report(const int &line, const std::string &where, const std::string &message)
Report an error in the given line and location.
Definition error.cpp:4