Added a skeleton for the lexer
This commit is contained in:
36
src/include/lex.hpp
Normal file
36
src/include/lex.hpp
Normal 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
16
src/lex.cpp
Normal 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};
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <lex.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
cout << "hi" << endl;
|
||||
cout << "hi " << endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user