mirror of
https://github.com/bigsketti/ProfaneC.git
synced 2024-12-25 15:10:27 +00:00
Compare commits
3 commits
e956c0e3a5
...
61951d7034
Author | SHA1 | Date | |
---|---|---|---|
|
61951d7034 | ||
|
cab30fe7e3 | ||
|
838c59cfed |
5 changed files with 46 additions and 21 deletions
|
@ -4,33 +4,35 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//list of keywords
|
//list of keywords
|
||||||
|
|
||||||
|
//types denoted by the index within the enum class
|
||||||
|
//this is so its easy to pass this info to the parser
|
||||||
enum class Keywords {
|
enum class Keywords {
|
||||||
identifier,
|
identifier, //type 0
|
||||||
integer,
|
integer, //type 1
|
||||||
floatpnt,
|
floatpnt, //type 2
|
||||||
string,
|
string, //type 3
|
||||||
character,
|
character, //type 4
|
||||||
boolean,
|
boolean, //type 5
|
||||||
plus,
|
plus, //type 6
|
||||||
minus,
|
minus, //type 7
|
||||||
multiply,
|
multiply, //type 8
|
||||||
divide,
|
divide, //type 9
|
||||||
l_Paren,
|
l_Paren, //type 10
|
||||||
r_Paren,
|
r_Paren, //type 11
|
||||||
l_Brace,
|
l_Brace, //type 12
|
||||||
r_Brace,
|
r_Brace, //type 13
|
||||||
l_Brack,
|
l_Brack, //type 14
|
||||||
r_Brack,
|
r_Brack, //type 15
|
||||||
semicolon,
|
semicolon, //type 16
|
||||||
end_of_file,
|
end_of_file, //type 17
|
||||||
unknown
|
unknown //type 18
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Token {
|
struct Token {
|
||||||
Keywords type;
|
Keywords type;
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
|
|
||||||
Token(Keywords type, std::string value) : type(type), value(value) {}
|
Token(Keywords type, std::string value) : type(type), value(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
9
lexerOutput.txt
Normal file
9
lexerOutput.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Type: 0, Value: int
|
||||||
|
Type: 0, Value: main
|
||||||
|
Type: 10, Value: (
|
||||||
|
Type: 11, Value: )
|
||||||
|
Type: 12, Value: {
|
||||||
|
Type: 0, Value: return
|
||||||
|
Type: 1, Value: 0
|
||||||
|
Type: 16, Value: ;
|
||||||
|
Type: 13, Value: }
|
BIN
profaneCompiler
BIN
profaneCompiler
Binary file not shown.
|
@ -49,7 +49,7 @@ Lexer::Lexer(const std::string &input) {
|
||||||
|
|
||||||
Token Lexer::getNextToken() {
|
Token Lexer::getNextToken() {
|
||||||
while (currentChar != '\0') {
|
while (currentChar != '\0') {
|
||||||
std::cout << currentChar << std::endl;
|
//std::cout << currentChar << std::endl;
|
||||||
|
|
||||||
if (std::isspace(currentChar)) {
|
if (std::isspace(currentChar)) {
|
||||||
skipWhiteSpace();
|
skipWhiteSpace();
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
#include "/home/mason/code-shit/ProfaneC/headers/lexer.h"
|
#include "/home/mason/code-shit/ProfaneC/headers/lexer.h"
|
||||||
|
|
||||||
|
//overloads the << operator to output token type as an integer
|
||||||
|
//followed by the token value
|
||||||
|
//the integers corrispond to the order defined in the Keywords enum class
|
||||||
|
//reference lexer.h for map of token types to indecies
|
||||||
std::ostream& operator<<(std::ostream& os, const Token& token) {
|
std::ostream& operator<<(std::ostream& os, const Token& token) {
|
||||||
os << "Type: " << static_cast<int>(token.type) << ", Value: " << token.value;
|
os << "Type: " << static_cast<int>(token.type) << ", Value: " << token.value;
|
||||||
return os;
|
return os;
|
||||||
|
@ -44,5 +48,15 @@ int main() {
|
||||||
std::cout << tokenVec.at(i) << std::endl;
|
std::cout << tokenVec.at(i) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ofstream file_out("/home/mason/code-shit/ProfaneC/lexerOutput.txt");
|
||||||
|
|
||||||
|
if (file_out.is_open()) {
|
||||||
|
for (int i = 0; i < tokenVec.size(); i++) {
|
||||||
|
file_out << tokenVec.at(i) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_out.close();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue