summaryrefslogtreecommitdiff
path: root/minic/scan.h
blob: 04d09455e0056e591ffc3b3a3d5d07203f749a32 (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
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "const.h"

typedef enum scanner_Sym {
	S_undef,
	S_eof,
	S_DIV,
	S_INT,
	S_VOID,
	S_RETURN,
	S_IDENT,
	S_INT_CONST,
	S_SEMICOLON,
	S_LPARENT,
	S_RPARENT,
	S_LCURL,
	S_RCURL
} scanner_Sym;

typedef struct scanner_Symbol {
	scanner_Sym sym;
	union {
		char s[MAX_IDENT_LEN];
		int i;
	} data;
	int tag;
} scanner_Symbol;

typedef struct Scanner {
	int peek;
	int row;
	int col;
	char *src;
	char *pos;
	int debug;
} Scanner;

void scanner_init( Scanner *s, char *src );
void scanner_reset( Scanner *s );
void scanner_done( Scanner *s );
scanner_Symbol scanner_scan( Scanner *s );
void scanner_debug( Scanner *s, int enable );