1/*2 * Copyright © 2016-2018 Sören Tempel3 *4 * This program is free software: you can redistribute it and/or5 * modify it under the terms of the GNU Affero General Public6 * License as published by the Free Software Foundation, either7 * 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 of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12 * Affero General Public License for more details.13 *14 * You should have received a copy of the GNU Affero General Public15 * License along with this program. If not, see16 * <http://www.gnu.org/licenses/>.17 */1819#ifndef TMSIM_TOKEN_H20#define TMSIM_TOKEN_H2122/**23 * Error codes used as token value when the value of the token type field is24 * 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;3233/**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). */3940 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. */4344 TOK_SYMBOL, /**< TM tape alphabet symbol. */45 TOK_STATE, /**< TM state name, should match: 'q[0-9]+'. */4647 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;5556/**57 * Token data type used for successfully scanned input tokens.58 */59typedef struct _token token;6061struct _token {62 toktype type; /**< Type of this token (see above). */63 int value; /**< Value of this token. */6465 unsigned int line; /**< Line of token in input file. */66 unsigned int column; /**< Column of token in input file. */67};6869void freetoken(token *);7071#endif