Purple  0.1
Standard Language Specification
scan.h
Go to the documentation of this file.
1
8#ifndef SCAN_H
9#define SCAN_H
10
11#include <stdbool.h>
12
13#include "types/identifier.h"
14#include "types/number.h"
15
19typedef enum
20{
22 // Arithmetic Operators
28 // Comparison Operators
35 // Logical Operators
42 // Literals
50 // Types
58 // Assignment
60 // Keywords
67 // Miscellaneous
78} TokenType;
79
80#define NUMBER_LITERAL_BASE_PREFIX '0'
81#define NUMBER_LITERAL_BIN_PREFIX 'b'
82#define NUMBER_LITERAL_OCT_PREFIX 'o'
83#define NUMBER_LITERAL_HEX_PREFIX 'x'
84#define NUMBER_LITERAL_LONG_SUFFIX 'L'
85
86#define NUMBER_LITERAL_SPACING_SEPARATOR '\''
87#define NUMBER_LITERAL_BASE_SEPARATOR '#'
88
92static char* tokenStrings[] = {"EOF",
93 "+",
94 "-",
95 "*",
96 "/",
97 "**",
98 "==",
99 "!=",
100 "<",
101 ">",
102 "<=",
103 ">=",
104 "and",
105 "or",
106 "xor",
107 "nand",
108 "nor",
109 "xnor",
110 "true",
111 "false",
112 "byte literal",
113 "character literal",
114 "short literal",
115 "integer literal",
116 "long literal",
117 "void",
118 "bool",
119 "byte",
120 "char",
121 "short",
122 "int",
123 "long",
124 "=",
125 "print",
126 "if",
127 "else",
128 "while",
129 "for",
130 "return",
131 ";",
132 "(",
133 ")",
134 "{",
135 "}",
136 "identifier",
137 "lvalue identifier",
138 "ast glue",
139 "function",
140 "function call"};
141
145#define TOKENTYPE_IS_BINARY_ARITHMETIC(type) (type >= T_PLUS && type <= T_EXPONENT)
146
150#define TOKENTYPE_IS_TYPE(type) (type >= T_VOID && type <= T_LONG)
151
155#define TOKENTYPE_IS_NUMBER_TYPE(tt) \
156 ((tt >= T_BOOL && tt <= T_LONG) || (T_TRUE <= tt && tt <= T_LONG_LITERAL))
157
161#define TOKENTYPE_IS_LITERAL(type) (type >= T_TRUE && type <= T_LONG_LITERAL)
162
166#define TOKENTYPE_IS_BOOL_LITERAL(type) (type >= T_TRUE && type <= T_FALSE)
167
171#define TOKENTYPE_IS_IDENTIFIER(type) (type >= T_IDENTIFIER && type <= T_LVALUE_IDENTIFIER)
172
176#define TOKENTYPE_IS_COMPARATOR(type) (type >= T_EQ && type <= T_GE)
177
182#define TOKENTYPE_IS_LOGICAL_OPERATOR(type) (type >= T_AND && type <= T_XNOR)
183
187#define number_literal_type long long int
188
192#define MAX_NUMBER_LITERAL_DIGITS 19
193
197typedef struct position {
199 char filename[256];
205
209typedef struct Token {
215 union {
222
223char next(void);
224void put_back_into_stream(char c);
225bool scan(Token* t);
226
227#endif /* SCAN_H */
Definitions for identifiers.
#define MAX_IDENTIFIER_LENGTH
Definition: identifier.h:12
Definitions and function headers for the internal "Number" type.
char next(void)
Get the next valid character from the current input file.
Definition: scan.c:20
static char * tokenStrings[]
Token string equivalents.
Definition: scan.h:92
TokenType
Types of scannable tokens.
Definition: scan.h:20
@ T_FOR
Definition: scan.h:65
@ T_AND
Definition: scan.h:36
@ T_RIGHT_BRACE
Definition: scan.h:72
@ T_IDENTIFIER
Definition: scan.h:73
@ T_INTEGER_LITERAL
Definition: scan.h:48
@ T_LONG
Definition: scan.h:57
@ T_NAND
Definition: scan.h:39
@ T_XOR
Definition: scan.h:38
@ T_SEMICOLON
Definition: scan.h:68
@ T_RIGHT_PAREN
Definition: scan.h:70
@ T_SHORT_LITERAL
Definition: scan.h:47
@ T_VOID
Definition: scan.h:51
@ T_WHILE
Definition: scan.h:64
@ T_NOR
Definition: scan.h:40
@ T_BYTE
Definition: scan.h:53
@ T_TRUE
Definition: scan.h:43
@ T_GE
Definition: scan.h:34
@ T_STAR
Definition: scan.h:25
@ T_BYTE_LITERAL
Definition: scan.h:45
@ T_BOOL
Definition: scan.h:52
@ T_LONG_LITERAL
Definition: scan.h:49
@ T_EOF
Definition: scan.h:21
@ T_LT
Definition: scan.h:31
@ T_CHAR_LITERAL
Definition: scan.h:46
@ T_LE
Definition: scan.h:33
@ T_INT
Definition: scan.h:56
@ T_ELSE
Definition: scan.h:63
@ T_PRINT
Definition: scan.h:61
@ T_SLASH
Definition: scan.h:26
@ T_XNOR
Definition: scan.h:41
@ T_AST_GLUE
Definition: scan.h:75
@ T_FUNCTION_CALL
Definition: scan.h:77
@ T_EQ
Definition: scan.h:29
@ T_ASSIGN
Definition: scan.h:59
@ T_GT
Definition: scan.h:32
@ T_FALSE
Definition: scan.h:44
@ T_LEFT_PAREN
Definition: scan.h:69
@ T_PLUS
Definition: scan.h:23
@ T_FUNCTION_DECLARATION
Definition: scan.h:76
@ T_IF
Definition: scan.h:62
@ T_MINUS
Definition: scan.h:24
@ T_OR
Definition: scan.h:37
@ T_RETURN
Definition: scan.h:66
@ T_SHORT
Definition: scan.h:55
@ T_LVALUE_IDENTIFIER
Definition: scan.h:74
@ T_NEQ
Definition: scan.h:30
@ T_LEFT_BRACE
Definition: scan.h:71
@ T_EXPONENT
Definition: scan.h:27
@ T_CHAR
Definition: scan.h:54
bool scan(Token *t)
Scan tokens into the Token struct.
Definition: scan.c:441
void put_back_into_stream(char c)
Put a character back into the input stream.
Definition: scan.c:51
struct Token Token
Structure containing information about individual scannable tokens.
struct position position
Structure containing information about a Token's position in the input.
Container for various kinds of number data.
Definition: number.h:51
Structure containing information about individual scannable tokens.
Definition: scan.h:209
position pos
Definition: scan.h:213
TokenType type
Definition: scan.h:211
union Token::@0 value
char symbol_name[MAX_IDENTIFIER_LENGTH]
Definition: scan.h:219
Number number_value
Definition: scan.h:217
Structure containing information about a Token's position in the input.
Definition: scan.h:197
int line_number
Definition: scan.h:201
int char_number
Definition: scan.h:203
char filename[256]
Definition: scan.h:199