Skip to content

Instantly share code, notes, and snippets.

@aolo2
Last active April 5, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aolo2/784b99acc3dd415ee804825a445336e3 to your computer and use it in GitHub Desktop.
Save aolo2/784b99acc3dd415ee804825a445336e3 to your computer and use it in GitHub Desktop.
#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