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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*************************************************************************
* Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> *
* *
* This file is part of Dimension. *
* *
* Dimension is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 3 of the License, or (at *
* your option) any later version. *
* *
* Dimension is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
#include "../libdimension/dimension.h"
typedef enum {
/* Punctuation */
DMNSN_T_LBRACE, /* { */
DMNSN_T_RBRACE, /* } */
DMNSN_T_LPAREN, /* ( */
DMNSN_T_RPAREN, /* ) */
DMNSN_T_LBRACKET, /* [ */
DMNSN_T_RBRACKET, /* ] */
DMNSN_T_LT, /* < */
DMNSN_T_GT, /* > */
DMNSN_T_PLUS, /* + */
DMNSN_T_MINUS, /* - */
DMNSN_T_STAR, /* * */
DMNSN_T_SLASH, /* / */
DMNSN_T_COMMA, /* , */
DMNSN_T_EQUALS, /* = */
DMNSN_T_SEMICOLON, /* ; */
DMNSN_T_QUESTION, /* ? */
DMNSN_T_COLON, /* : */
DMNSN_T_AND, /* & */
DMNSN_T_BANG, /* ! */
DMNSN_T_DOT, /* . */
DMNSN_T_PIPE, /* | */
/* Numeric values */
DMNSN_T_INT,
DMNSN_T_FLOAT,
/* Keywords */
DMNSN_T_CAMERA,
DMNSN_T_COLOR,
DMNSN_T_SPHERE,
DMNSN_T_BOX,
/* Directives (#declare, etc.) */
DMNSN_T_BREAK,
DMNSN_T_CASE,
DMNSN_T_DEBUG,
DMNSN_T_DECLARE,
DMNSN_T_DEFAULT,
DMNSN_T_ELSE,
DMNSN_T_END,
DMNSN_T_ERROR,
DMNSN_T_FCLOSE,
DMNSN_T_FOPEN,
DMNSN_T_IF,
DMNSN_T_IFDEF,
DMNSN_T_IFNDEF,
DMNSN_T_INCLUDE,
DMNSN_T_LOCAL,
DMNSN_T_MACRO,
DMNSN_T_RANGE,
DMNSN_T_READ,
DMNSN_T_RENDER,
DMNSN_T_STATISTICS,
DMNSN_T_SWITCH,
DMNSN_T_UNDEF,
DMNSN_T_VERSION,
DMNSN_T_WARNING,
DMNSN_T_WHILE,
DMNSN_T_WRITE,
/* Identifiers */
DMNSN_T_IDENTIFIER,
/* Strings */
DMNSN_T_STRING,
} dmnsn_token_type;
typedef struct dmnsn_token dmnsn_token;
struct dmnsn_token {
dmnsn_token_type type;
char *value;
/* File name, and line and column numbers from source code */
char *filename;
unsigned int line, col;
};
/* The workhorse */
dmnsn_array *dmnsn_tokenize(const char *filename, FILE *file);
/* Free an array of tokens - use this rather than dmnsn_delete_array() */
void dmnsn_delete_tokens(dmnsn_array *tokens);
/* Print an S-expression of a list of tokens to `file' */
void dmnsn_print_token_sexpr(FILE *file, const dmnsn_array *tokens);
/* Returns a readable name for a token type (ex. DMNSN_T_FLOAT -> float) */
const char *dmnsn_token_name(dmnsn_token_type token_type);
|