initial code

This commit is contained in:
Karma Riuk
2025-06-28 17:59:08 +02:00
parent 8acce0f6a6
commit 9a13de97e1
3 changed files with 79 additions and 0 deletions

9
src/main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "token/type.hpp"
#include <iostream>
int main() {
auto eof = TokenType::ILLEGAL;
std::cout << eof << std::endl;
return 0;
}

10
src/token/token.hpp Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include "type.hpp"
#include <string>
struct Token {
TokenType type;
std::string literal;
};

60
src/token/type.hpp Normal file
View File

@ -0,0 +1,60 @@
#pragma once
#include <ostream>
enum class TokenType {
ILLEGAL,
EOF_,
IDENT,
INT,
ASSIGN,
PLUS,
COMMA,
SEMICOLON,
LPAREN,
RPAREN,
LBRACE,
RBRACE,
FUNCTION,
LET
};
inline std::ostream& operator<<(std::ostream& os, TokenType tt) {
switch (tt) {
case TokenType::ILLEGAL:
return os << "ILLEGAL";
case TokenType::EOF_:
return os << "EOF";
case TokenType::IDENT:
return os << "IDENT";
case TokenType::INT:
return os << "INT";
case TokenType::ASSIGN:
return os << "=";
case TokenType::PLUS:
return os << "+";
case TokenType::COMMA:
return os << ",";
case TokenType::SEMICOLON:
return os << ";";
case TokenType::LPAREN:
return os << "(";
case TokenType::RPAREN:
return os << ")";
case TokenType::LBRACE:
return os << "{";
case TokenType::RBRACE:
return os << "}";
case TokenType::FUNCTION:
return os << "FUNCTION";
case TokenType::LET:
return os << "LET";
default:
return os << "Unknown";
}
}