working AST
This commit is contained in:
parent
7c6379c62d
commit
9e9039af05
13 changed files with 962 additions and 36 deletions
55
simulator_SIC_XE/include/lexer.h
Normal file
55
simulator_SIC_XE/include/lexer.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cstddef>
|
||||
|
||||
class SyntaxError : public std::runtime_error {
|
||||
public:
|
||||
int row;
|
||||
int col;
|
||||
|
||||
SyntaxError(const std::string& msg, int row_, int col_)
|
||||
: std::runtime_error(msg), row(row_), col(col_) {}
|
||||
};
|
||||
|
||||
|
||||
class Lexer {
|
||||
public:
|
||||
int row;
|
||||
int col;
|
||||
|
||||
explicit Lexer(std::string input);
|
||||
|
||||
Lexer& mark();
|
||||
|
||||
std::string extract(int ofs);
|
||||
std::string extract();
|
||||
|
||||
char peek(int ahead) const;
|
||||
char peek() const;
|
||||
|
||||
char advance();
|
||||
|
||||
bool advanceIf(char ch);
|
||||
void advance(char ch);
|
||||
|
||||
|
||||
bool skipWhitespace();
|
||||
|
||||
std::string readTo(char delimiter);
|
||||
|
||||
std::string readAlphanumeric();
|
||||
|
||||
std::string readDigits(int radix);
|
||||
|
||||
private:
|
||||
std::string input_;
|
||||
std::size_t pos_;
|
||||
std::size_t start_;
|
||||
|
||||
static int digitValue(char c, int radix);
|
||||
};
|
||||
|
||||
#endif // LEXER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue