1/*
2 * Copyright © 2016-2018 Sören Tempel
3 *
4 * This program is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU Affero General Public
6 * License as published by the Free Software Foundation, either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef TMSIM_TOKEN_H
20#define TMSIM_TOKEN_H
21
22/**
23 * Error codes used as token value when the value of the token type field is
24 * equal to TOK_ERROR.
25 */
26typedef enum {
27 ERR_OVERFLOW = 1, /**< strtol(3) detected an integer overflow. */
28 ERR_UNDERFLOW = 2, /**< strtol(3) detected an integer underflow. */
29 ERR_UNKOWN = 3, /**< Lexer encountered an unknown character. */
30 ERR_UNEXPECTED = 4, /**< Lexer encountered an unexpected character. */
31} errorcode;
32
33/**
34 * Valid values for the type field of the token struct.
35 */
36typedef enum {
37 TOK_EOF, /**< End of file. */
38 TOK_ERROR, /**< Error occured (see errorcode above). */
39
40 TOK_START, /**< Token specifies initial TM state. */
41 TOK_ACCEPT, /**< Token specifies accepting TM states. */
42 TOK_NEXT, /**< Token specifies next state in a transition. */
43
44 TOK_SYMBOL, /**< TM tape alphabet symbol. */
45 TOK_STATE, /**< TM state name, should match: 'q[0-9]+'. */
46
47 TOK_COMMA, /**< The ASCII ',' symbol. */
48 TOK_SEMICOLON, /**< The ASCII ';' symbol. */
49 TOK_SMALLER, /**< The ASCII '<' symbol. */
50 TOK_GREATER, /**< The ASCII '>' symbol. */
51 TOK_LBRACKET, /**< The ASCII '{' symbol */
52 TOK_RBRACKET, /**< The ASCII '}' symbol */
53 TOK_PIPE, /**< The ASCII '|' symbol. */
54} toktype;
55
56/**
57 * Token data type used for successfully scanned input tokens.
58 */
59typedef struct _token token;
60
61struct _token {
62 toktype type; /**< Type of this token (see above). */
63 int value; /**< Value of this token. */
64
65 unsigned int line; /**< Line of token in input file. */
66 unsigned int column; /**< Column of token in input file. */
67};
68
69void freetoken(token *);
70
71#endif