diff options
| author | Cori Barker <coribarker2@gmail.com> | 2026-01-19 09:35:45 +0000 |
|---|---|---|
| committer | Cori Barker <coribarker2@gmail.com> | 2026-01-19 09:35:45 +0000 |
| commit | e34338219036acf103d161dfbd36fa67597d23e7 (patch) | |
| tree | 00b4b09fd7fcb47502aee4b5be0e939fd771aab1 /include/lexer | |
lexer
Diffstat (limited to 'include/lexer')
| -rw-r--r-- | include/lexer/lexer.h | 27 | ||||
| -rw-r--r-- | include/lexer/token.h | 17 | ||||
| -rw-r--r-- | include/lexer/token_type.h | 25 |
3 files changed, 69 insertions, 0 deletions
diff --git a/include/lexer/lexer.h b/include/lexer/lexer.h new file mode 100644 index 0000000..f24e92e --- /dev/null +++ b/include/lexer/lexer.h @@ -0,0 +1,27 @@ +#ifndef LEXER_H +#define LEXER_H + +#include "token.h" + +#include <vector> +#include <string> + +class Lexer { +public: + explicit Lexer (const std::string& src); + + std::vector<Token> tokenise(); + +private: + int line; + int column; + int position; + std::string src; + std::vector<Token> tokens; + + char advance(); + void skipWhitespace(); + void skipComment(); +}; + +#endif diff --git a/include/lexer/token.h b/include/lexer/token.h new file mode 100644 index 0000000..54ac116 --- /dev/null +++ b/include/lexer/token.h @@ -0,0 +1,17 @@ +#ifndef TOKEN_H +#define TOKEN_H + +#include "token_type.h" + +#include <string> + +struct Token { + TokenType type; + std::string value; + int line; + int column; + + Token(TokenType t, const std::string& val, int line, int col) : type{t}, value{val}, line{line}, column{col} {}; +}; + +#endif diff --git a/include/lexer/token_type.h b/include/lexer/token_type.h new file mode 100644 index 0000000..f83c6d6 --- /dev/null +++ b/include/lexer/token_type.h @@ -0,0 +1,25 @@ +#ifndef TOKEN_TYPE_H +#define TOKEN_TYPE_H + +enum class TokenType { + INT, + STRING, + + NUMBER, + IDENTIFIER, + + PLUS, + MINUS, + MULTIPLY, + DIVIDE, + + ASSIGN, + + SEMICOLON, + + END_OF_FILE, + INVALID + +}; + +#endif |
