Last active
April 5, 2018 22:03
-
-
Save aolo2/784b99acc3dd415ee804825a445336e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#define internal static | |
typedef int8_t int8; | |
typedef int16_t int16; | |
typedef int32_t int32; | |
typedef int64_t int64; | |
typedef uint8_t uint8; | |
typedef uint16_t uint16; | |
typedef uint32_t uint32; | |
typedef uint64_t uint64; | |
enum DOMAIN | |
{ | |
WORD, | |
LABEL, | |
COMMENT, | |
EOP, | |
OTHER | |
}; | |
struct position | |
{ | |
uint32 line; | |
uint32 pos; | |
uint32 index; | |
uint32 len; | |
char *text; | |
}; | |
struct fragment | |
{ | |
position starting; | |
position following; | |
}; | |
struct token | |
{ | |
DOMAIN tag; | |
fragment coords; | |
}; | |
struct scanner | |
{ | |
char *program; | |
uint32 len; | |
position cur; | |
fragment *comments; | |
}; | |
internal position | |
init_position(char *text, uint32 len) | |
{ | |
position p = {}; | |
p.text = text; | |
p.len = len; | |
p.line = 1; | |
p.pos = 1; | |
p.index = 0; | |
return(p); | |
} | |
internal fragment | |
init_fragment(position starting, position following) | |
{ | |
fragment f = {}; | |
f.starting = starting; | |
f.following = following; | |
return(f); | |
} | |
internal token | |
init_token(DOMAIN tag, fragment coords) | |
{ | |
token t = {}; | |
t.tag = tag; | |
t.coords = coords; | |
return(t); | |
} | |
internal scanner | |
init_scanner(char *program, uint32 len) | |
{ | |
scanner sc = {}; | |
sc.program = program; | |
sc.len = len; | |
sc.cur = init_position(program, len); | |
return(sc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment