-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenize.c
78 lines (68 loc) · 1.27 KB
/
tokenize.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
An interface which handles LEX tokens.
*/
#include "tokenize.h"
static YYSTYPE _curr_token;
static int _la_exists;
static int _curr_token_type;
/* Initialises the tokens */
int tokenize_init()
{
_la_exists = FALSE;
return XSM_SUCCESS;
}
/* Returns next token */
int tokenize_next_token(YYSTYPE *token_info)
{
int token_type;
if (_la_exists)
{
*token_info = _curr_token;
_la_exists = FALSE;
return _curr_token_type;
}
else
{
token_type = yylex();
*token_info = yylval;
return token_type;
}
}
/* Peeks the next token */
int tokenize_peek(YYSTYPE *token_info)
{
if (_la_exists)
{
*token_info = _curr_token;
return _curr_token_type;
}
else
{
_curr_token_type = yylex();
_curr_token = yylval;
*token_info = _curr_token;
_la_exists = TRUE;
return _curr_token_type;
}
}
/* Skips the next token */
int tokenize_skip_token()
{
YYSTYPE token_info;
return tokenize_next_token(&token_info);
}
/* Closes the tokens */
int tokenize_close()
{
return XSM_SUCCESS;
}
/* Resets the tokens */
void tokenize_reset()
{
_la_exists = FALSE;
}
/* Clears the token stream */
void tokenize_clear_stream()
{
lexer_buffer_reset();
}