1 /* $OpenBSD: fgen.h,v 1.3 2020/03/24 07:00:40 otto Exp $ */ 2 /* $NetBSD: fgen.h,v 1.9 2010/02/08 20:14:55 eeh Exp $ */ 3 /* 4 * fgen.h -- stuff for the fcode tokenizer. 5 * 6 * Copyright (c) 1998 Eduardo Horvath. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* Type of a Cell */ 31 typedef int64_t Cell; 32 33 /* Token from the scanner. */ 34 struct tok { 35 int type; 36 char *text; 37 }; 38 39 #define TOKEN struct tok 40 #define YY_DECL TOKEN* yylex(void) 41 42 #define FCODE 0x000FC0DE 43 #define MACRO 0x0000F00D 44 45 /* Defined fcode and string. */ 46 struct fcode { 47 const char *name; 48 long num; 49 int type; 50 struct fcode *l; 51 struct fcode *r; 52 }; 53 54 /* macro instruction as separate words */ 55 struct macro { 56 const char *name; 57 const char *equiv; 58 int type; 59 struct macro *l; 60 struct macro *r; 61 }; 62 63 /* 64 * FCode header -- assumes big-endian machine, 65 * otherwise the bits need twiddling. 66 */ 67 struct fcode_header { 68 char header; 69 char format; 70 short checksum; 71 int length; 72 }; 73 74 /* Tokenizer tokens */ 75 enum toktypes { 76 TOK_OCTAL = 8, 77 TOK_DECIMAL = 10, 78 TOK_HEX = 16, 79 80 TOK_NUMBER, 81 TOK_STRING_LIT, 82 TOK_C_LIT, 83 TOK_PSTRING, 84 TOK_TOKENIZE, 85 TOK_COMMENT, 86 TOK_COLON, 87 TOK_SEMICOLON, 88 TOK_TOSTRING, 89 90 /* These are special */ 91 TOK_ABORT_S, 92 TOK_AGAIN, 93 TOK_ALIAS, 94 TOK_GETTOKEN, 95 TOK_ASCII, 96 TOK_BEGIN, 97 TOK_BUFFER, 98 TOK_CASE, 99 TOK_CONSTANT, 100 TOK_CONTROL, 101 TOK_CREATE, 102 TOK_DEFER, 103 TOK_DO, 104 TOK_ELSE, 105 TOK_END0, 106 TOK_ENDCASE, 107 TOK_ENDOF, 108 TOK_EXTERNAL, 109 TOK_FCODE_VERSION2, 110 TOK_FCODE_END, 111 TOK_FIELD, 112 TOK_HEADERLESS, 113 TOK_HEADERS, 114 TOK_IF, 115 TOK_LEAVE, 116 TOK_LOOP, 117 TOK_OF, 118 TOK_OFFSET16, 119 TOK_REPEAT, 120 TOK_STARTX, 121 TOK_THEN, 122 TOK_TO, 123 TOK_UNTIL, 124 TOK_VALUE, 125 TOK_VARIABLE, 126 TOK_VERSION1, 127 TOK_WHILE, 128 129 /* Tokenizer directives */ 130 TOK_BEGTOK, 131 TOK_EMIT_BYTE, 132 TOK_ENDTOK, 133 TOK_FLOAD, 134 135 TOK_OTHER 136 }; 137