#include "gsc/error.hpp"
#include "gsc/interpreter.hpp"
#include "gsc/parser.hpp"
#include "gsc/scanner.hpp"
#include "gsc/token.hpp"
#include <fstream>
#include <iostream>
#include <vector>
Go to the source code of this file.
|
void | runFile (std::string_view filename) |
|
void | runPrompt () |
|
int | main (int argc, char *argv[]) |
|
std::string | readFile (std::string_view filename) |
|
void | run (std::string_view program) |
|
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 15 of file main.cpp.
15 {
16 if (argc > 2) {
17 std::cerr << "Usage: " << argv[0] << " [file.gsc]" << std::endl;
18 std::exit(EXIT_FAILURE);
19 } else if (argc == 2) {
21 } else {
23 }
24}
void runFile(std::string_view filename)
◆ readFile()
std::string readFile |
( |
std::string_view |
filename | ) |
|
Definition at line 26 of file main.cpp.
26 {
27 std::ifstream file(filename.data());
28
29 if (!file) {
30 std::cerr << "Could not open file: " << filename << std::endl;
31 std::exit(EXIT_FAILURE);
32 } else {
33 std::string content{std::istreambuf_iterator<char>(file),
34 std::istreambuf_iterator<char>()};
35 return content;
36 }
37}
◆ run()
void run |
( |
std::string_view |
program | ) |
|
Definition at line 39 of file main.cpp.
39 {
42 std::vector<Token> tokens = scanner.getTokens();
44 std::vector<std::shared_ptr<Stmt>> statements = parser.
parse();
45
47 std::cerr << "Error while parsing the program." << std::endl;
48 } else {
50 }
51}
void interpret(const std::vector< std::shared_ptr< Stmt > > &statements)
Interpret the given statement list and execute them.
Parser module for the GSC programming language.
std::vector< std::shared_ptr< Stmt > > parse()
Parses the tokens and returns a vector of statements.
Lexical analyzer for the GSC programming language.
void scanTokens()
Scans the entire source code and generates a list of tokens.
◆ runFile()
void runFile |
( |
std::string_view |
filename | ) |
|
Definition at line 53 of file main.cpp.
53 {
54 std::string program =
readFile(filename);
56
58 std::cerr << "Error while running file: " << filename << std::endl;
59 std::exit(EXIT_FAILURE);
61 std::cerr << "Runtime error occurred while running file: " << filename
62 << std::endl;
63 std::exit(EXIT_FAILURE);
64 }
65}
void run(std::string_view program)
std::string readFile(std::string_view filename)
◆ runPrompt()
Definition at line 67 of file main.cpp.
67 {
68 while (true) {
69 std::cout << ">> ";
70 std::string line;
71 if (!std::getline(std::cin, line)) {
72 std::cout << std::endl;
73 break;
74 } else {
77 }
78 }
79}
◆ interpreter