forked from CS429-S2022/CI-Lab-Student
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.h
More file actions
57 lines (54 loc) · 1.95 KB
/
Copy pathtoken.h
File metadata and controls
57 lines (54 loc) · 1.95 KB
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
/**************************************************************************
* C S 429 EEL interpreter
*
* token.h - This file contains the enum of possible token types, as well as
* the lexeme struct used by the lexer.
*
* Copyright (c) 2021. S. Chatterjee, X. Shen, T. Byrd. All rights reserved.
* May not be used, modified, or copied without permission.
**************************************************************************/
#define MAX_LINE_CHARS 82
/* This enum contains all possible types a token may have. */
typedef enum {
TOK_ID, // identifier
// literals
TOK_NUM, // 0-9
TOK_TRUE, // true
TOK_FALSE, // false
TOK_STR, // "..."
// delimiters
TOK_LPAREN, // (
TOK_RPAREN, // )
// ternary operator
TOK_QUESTION, // ?
TOK_COLON, // :
// binary operators
TOK_PLUS, // +
TOK_BMINUS, // -
TOK_TIMES, // *
TOK_DIV, // /
TOK_MOD, // %
TOK_AND, // &
TOK_OR, // |
TOK_LT, // <
TOK_GT, // >
TOK_EQ, // ~
//unary operators
TOK_UMINUS, // _
TOK_NOT, // !
// other stuff
TOK_SEP, // format separator
TOK_EOL, // end of line
TOK_ASSIGN, // =
TOK_IDENTITY, // do nothing
TOK_FMT_SPEC, // format specifier: needs to be disambiguated from
// identifier or Boolean literals by parser
TOK_INVALID = -1 // sentinel
} token_t;
/* This struct is used by the lexer to provide information about the tokens
* within an input string. */
typedef struct lexeme {
token_t ttype; // the type of the token
int startpos; // the position of the token in the input
char repr[MAX_LINE_CHARS]; // the representation of the token
} lexeme_t, *lptr_t;