]> git.sur5r.net Git - cc65/blob - src/sim65/scanner.h
7607310d808e106f7df9fd257cb819d610ef133e
[cc65] / src / sim65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*            Configuration file scanner for the sim65 6502 simulator        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SCANNER_H
37 #define SCANNER_H
38
39
40                    
41 /* common */
42 #include "attrib.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 /* Config file tokens */
53 typedef enum {
54     CFGTOK_NONE,
55     CFGTOK_INTCON,
56     CFGTOK_STRCON,
57     CFGTOK_IDENT,
58     CFGTOK_LCURLY,
59     CFGTOK_RCURLY,
60     CFGTOK_SEMI,
61     CFGTOK_COMMA,
62     CFGTOK_EQ,
63     CFGTOK_COLON,
64     CFGTOK_DOT,
65     CFGTOK_DOTDOT,
66     CFGTOK_EOF,
67
68     /* Primary blocks */
69     CFGTOK_MEMORY,
70
71     /* Special identifiers */
72     CFGTOK_TRUE,
73     CFGTOK_FALSE
74
75 } cfgtok_t;
76
77
78
79 /* Mapping table entry, special identifier --> token */
80 typedef struct IdentTok IdentTok;
81 struct IdentTok {
82     const char* Ident;          /* Identifier */
83     cfgtok_t    Tok;            /* Token for identifier */
84 };
85 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
86
87
88
89 /* Current token and attributes */
90 #define CFG_MAX_IDENT_LEN  255
91 extern cfgtok_t         CfgTok;
92 extern char             CfgSVal [CFG_MAX_IDENT_LEN+1];
93 extern unsigned long    CfgIVal;
94
95 /* Error location */
96 extern unsigned         CfgErrorLine;
97 extern unsigned         CfgErrorCol;
98
99
100
101 /*****************************************************************************/
102 /*                                   Code                                    */
103 /*****************************************************************************/
104
105
106
107 void CfgWarning (const char* Format, ...) attribute((format(printf,1,2)));
108 /* Print a warning message adding file name and line number of the config file */
109
110 void CfgError (const char* Format, ...) attribute((format(printf,1,2)));
111 /* Print an error message adding file name and line number of the config file */
112
113 void CfgNextTok (void);
114 /* Read the next token from the input stream */
115
116 void CfgConsume (cfgtok_t T, const char* Msg);
117 /* Skip a token, print an error message if not found */
118
119 void CfgConsumeSemi (void);
120 /* Consume a semicolon */
121
122 void CfgConsumeColon (void);
123 /* Consume a colon */
124
125 void CfgOptionalComma (void);
126 /* Consume a comma if there is one */
127
128 void CfgOptionalAssign (void);
129 /* Consume an equal sign if there is one */
130
131 void CfgAssureInt (void);
132 /* Make sure the next token is an integer */
133
134 void CfgAssureStr (void);
135 /* Make sure the next token is a string constant */
136
137 void CfgAssureIdent (void);
138 /* Make sure the next token is an identifier */
139
140 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
141 /* Check the range of CfgIVal */
142
143 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
144 /* Map an identifier to one of the special tokens in the table */
145
146 void CfgBoolToken (void);
147 /* Map an identifier or integer to a boolean token */
148
149 void CfgSetName (const char* Name);
150 /* Set a name for a config file */
151
152 const char* CfgGetName (void);
153 /* Get the name of the config file */
154
155 void CfgSetBuf (const char* Buf);
156 /* Set a memory buffer for the config */
157
158 int CfgAvail (void);
159 /* Return true if we have a configuration available */
160
161 void CfgOpenInput (void);
162 /* Open the input file if we have one */
163
164 void CfgCloseInput (void);
165 /* Close the input file if we have one */
166
167
168
169 /* End of scanner.h */
170 #endif
171
172
173