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