Files
BlitzNext/compiler/toker.hpp
T

114 lines
1.1 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.
*/
#ifndef TOKER_H
#define TOKER_H
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:
Toker(istream& in);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
int pos();
int curr();
int next();
2014-01-31 08:23:00 +13:00
string text();
2019-01-18 17:04:57 +01:00
int lookAhead(int n);
2014-01-31 08:23:00 +13:00
static int chars_toked;
2019-01-18 17:04:57 +01:00
static map<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-18 17:04:57 +01:00
istream& in;
string line;
2014-01-31 08:23:00 +13:00
vector<Toke> tokes;
2019-01-18 17:04:57 +01:00
void nextline();
int curr_row, curr_toke;
2014-01-31 08:23:00 +13:00
};
#endif