summaryrefslogtreecommitdiff
path: root/lex.h
blob: 389a5d7ecad82d5643b90637046ebb3ec02d12b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef LEX_H
#define LEX_H

#include <stdio.h>

enum TOKEN_TYPE {
	TOKEN_COMMA = 1,
	TOKEN_DOT, /* starts an assembler directive */
	TOKEN_LABEL, /* label declaration */
	TOKEN_IDENT, /* identifier (not label decl) or instruction */
	TOKEN_KEYWORD, /* keyword used to tell the assembler special information */
	TOKEN_STRING, /* string literal */
	TOKEN_NUMERIC, /* numeric literal, incl literal chars */
	TOKEN_REGISTER, /* $0, $H, $1 */
	TOKEN_EOL, /* end of line */
	TOKEN_EOF, /* end of file */
};

struct token {
	enum TOKEN_TYPE type;
	/* line and column of the source file this token occurs at. 1-based. */
	size_t line;
	size_t column;
	size_t span;
	char *s_val;
	int i_val;
};

struct token* lex(const char *filename_local, FILE *fin, size_t *len);
void lex_free(struct token *ts, size_t t_count);

#endif /* LEX_H */