Added a skeleton for the lexer

This commit is contained in:
2025-09-30 16:50:33 +03:00
committed by Emin Arslan
parent 43e05597ac
commit 19b0eb48bb
7 changed files with 104 additions and 3 deletions

36
src/include/lex.hpp Normal file
View File

@@ -0,0 +1,36 @@
#pragma once
#include <sstream>
#include <vector>
#include <stdint.h>
#include <variant>
enum TokenType {
OpenParen,
CloseParen,
Symbol,
String,
Int,
End
};
// Plain Old Data
struct Token {
enum TokenType type;
std::variant<int, std::string> value;
};
class Lexer {
private:
// we use a stringstream for lexing purposes
std::stringstream ss;
public:
Lexer(std::string);
Lexer();
void feed(std::string);
Token next();
std::vector<Token> collect();
};

16
src/lex.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include <lex.hpp>
#include <string>
Lexer::Lexer(std::string s) : ss(s) {}
Lexer::Lexer() : ss("") {}
void Lexer::feed(std::string s) {
ss << s;
}
Token Lexer::next() {
return {TokenType::CloseParen};
}

View File

@@ -1,8 +1,10 @@
#include <iostream>
#include <lex.hpp>
#include <sstream>
using namespace std;
int main() {
cout << "hi" << endl;
cout << "hi " << endl;
return 0;
}