-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.h
37 lines (27 loc) · 1.05 KB
/
token.h
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
/*
* token.h
*/
#define MAX_TOKEN_LENGTH 250
#include <stdio.h>
typedef enum { DEFUN, IDENT, RETURN,
PLUS, MINUS, MUL, DIV, MOD,
AND, OR, NOT,
LT, LE, EQ, GE, GT,
IF, ELSE, ENDIF,
DROP, DUP, SWAP, ROT,
ARG,
LITERAL,
BAD_TOKEN } token_type;
typedef struct {
token_type type;
int literal_value; // this field used to store the value of literal tokens
int arg_no; // this field used to store the index of argument literals argN
char str[MAX_TOKEN_LENGTH]; // This character array stores the token string
} token;
// line_number : You can use this to keep track of the current line number which can be useful in reporting syntax errors.
// Be sure to include a line that says 'int line_number;' in token.c outside of any functions if you would like to make use of this.
extern int line_number;
int read_token (token *theToken, FILE *theFile);
// Extra functions which you may wish to define and use , or not
void print_token (token *theToken);
int is_ident (char string[]);