-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project architecture adjustment. It does not affect normal operation.
- Loading branch information
Showing
8 changed files
with
100 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,61 @@ | ||
#include "compiler/compiler.h" | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#include "compiler/compiler.h" | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
#include "debugger/debugger.h" | ||
#include "compiler/lexer/lexer.h" | ||
#include "compiler/lexer/token.h" | ||
|
||
namespace Aq { | ||
Compiler::Compiler() = default; | ||
Compiler::~Compiler() = default; | ||
|
||
int Compiler::CompileFile(const char* filename) { | ||
// TODO: Waiting for improvements. | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
std::ifstream file; | ||
file.open(filename); | ||
if (!file.is_open()) { | ||
Aq::Debugger error_info(Aq::Debugger::Level::ERROR, "Aq::Main", | ||
"Main_ReadFileError", "Can't open file.", nullptr); | ||
return -1; | ||
} | ||
|
||
std::vector<char> code; | ||
char ch; | ||
while (file.get(ch)) { | ||
code.push_back(ch); | ||
} | ||
code.push_back('\0'); | ||
file.close(); | ||
Lexer lexer(code.data(), code.size() - 1); | ||
Token token; | ||
while (true) { | ||
int return_value = lexer.LexToken(token); | ||
if (token.length == 0) { | ||
std::cout << "END OF THE CODE."; | ||
} else { | ||
std::cout << std::string(token.location, token.length) << std::endl; | ||
} | ||
if (lexer.IsReadEnd()) { | ||
break; | ||
} | ||
} | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
auto duration_in_milliseconds = | ||
std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | ||
double duration_in_seconds = | ||
static_cast<double>(duration_in_milliseconds.count()) / 1000.0; | ||
std::cout << "Execution time: " << duration_in_seconds << " seconds.\n"; | ||
return 0; | ||
} | ||
} // namespace Aq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#ifndef AQ_COMPILE_COMPILE_H_ | ||
#define AQ_COMPILE_COMPILE_H_ | ||
|
||
namespace Aq { | ||
namespace Compiler { | ||
extern int CompileFile(const char* filename); | ||
} | ||
class Compiler { | ||
public: | ||
Compiler(); | ||
~Compiler(); | ||
|
||
int CompileFile(const char* filename); | ||
|
||
private: | ||
class Lexer; | ||
struct Token; | ||
template <typename T> | ||
class LexMap; | ||
class TokenMap; | ||
class Parser; | ||
}; | ||
} // namespace Aq | ||
|
||
#endif // AQ_COMPILE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters