Files
BlitzNext/compiler/lib/toker.hpp
T

113 lines
1.2 KiB
C++
Raw Normal View History

2014-01-31 08:23:00 +13:00
/*
The Toker converts an inout stream into tokens for use by the parser.
*/
2019-01-19 18:28:07 +01:00
#pragma once
#include <istream>
#include <map>
#include <string>
#include <vector>
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
enum {
DIM = 0x8000,
GOTO,
GOSUB,
EXIT,
RETURN,
IF,
THEN,
ELSE,
ENDIF,
ELSEIF,
WHILE,
WEND,
FOR,
TO,
STEP,
NEXT,
FUNCTION,
ENDFUNCTION,
TYPE,
ENDTYPE,
EACH,
GLOBAL,
LOCAL,
FIELD,
BBCONST,
SELECT,
CASE,
DEFAULT,
ENDSELECT,
REPEAT,
UNTIL,
FOREVER,
DATA,
READ,
RESTORE,
ABS,
SGN,
MOD,
PI,
BBTRUE,
BBFALSE,
BBINT,
BBFLOAT,
BBSTR,
2014-01-31 08:23:00 +13:00
INCLUDE,
2019-01-18 17:04:57 +01:00
BBNEW,
BBDELETE,
FIRST,
LAST,
INSERT,
BEFORE,
AFTER,
BBNULL,
OBJECT,
BBHANDLE,
AND,
OR,
XOR,
NOT,
SHL,
SHR,
SAR,
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
LE,
GE,
NE,
IDENT,
INTCONST,
BINCONST,
HEXCONST,
FLOATCONST,
STRINGCONST
2014-01-31 08:23:00 +13:00
};
2019-01-18 17:04:57 +01:00
class Toker {
public:
2019-01-19 18:28:07 +01:00
Toker(std::istream& in);
2014-01-31 08:23:00 +13:00
2019-01-19 18:28:07 +01:00
int pos();
int curr();
int next();
std::string text();
int lookAhead(int n);
2014-01-31 08:23:00 +13:00
static int chars_toked;
2019-01-19 18:28:07 +01:00
static std::map<std::string, int>& getKeywords();
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
private:
struct Toke {
int n, from, to;
Toke(int n, int f, int t) : n(n), from(f), to(t) {}
2014-01-31 08:23:00 +13:00
};
2019-01-19 18:28:07 +01:00
std::istream& in;
std::string line;
std::vector<Toke> tokes;
void nextline();
int curr_row, curr_toke;
2014-01-31 08:23:00 +13:00
};