1typedef enum {
2 TOK_EOF, /* End of file */
3
4 TOK_VAR, /* A variable name */
5 TOK_DIG, /* A natural number */
6 TOK_ERROR, /* Lexer error of some sort */
7
8 TOK_ASSIGN, /* := */
9 TOK_QUESTION, /* ? */
10 TOK_SEMICOLON, /* ; */
11 TOK_EXCLAMATION, /* ! */
12
13 TOK_LBRACKET, /* ( */
14 TOK_RBRACKET, /* ) */
15
16 TOK_DIVIDE, /* % */
17 TOK_MULTI, /* * */
18 TOK_MINUS, /* - */
19 TOK_PLUS, /* + */
20} tok_t;
21
22typedef struct token token;
23
24struct token {
25 TAILQ_ENTRY(token) toks;
26 tok_t type;
27 char *text;
28 int line;
29};
30
31TAILQ_HEAD(tqueue, token);
32
33typedef struct scanner scanner;
34
35struct scanner {
36 sem_t *fullsem, *emptysem;
37 pthread_t *thread;
38 size_t pos, start, inlen;
39 struct tqueue qhead;
40 pthread_mutex_t *qmutex;
41 char *input;
42 int line, eof;
43};
44
45void freescr(scanner *scr);
46scanner *scanstr(char *str);
47token *nxttok(scanner *scr);