]> git.sur5r.net Git - cc65/blob - src/sim65/scanner.h
Removed (pretty inconsistently used) tab chars from source code base.
[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-2012, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 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 #include "strbuf.h"
44
45
46
47 /*****************************************************************************/
48 /*                                   Data                                    */
49 /*****************************************************************************/
50
51
52
53 /* Config file tokens */
54 typedef enum {
55     CFGTOK_NONE,
56     CFGTOK_INTCON,
57     CFGTOK_STRCON,
58     CFGTOK_IDENT,
59     CFGTOK_LCURLY,
60     CFGTOK_RCURLY,
61     CFGTOK_SEMI,
62     CFGTOK_COMMA,
63     CFGTOK_EQ,
64     CFGTOK_COLON,
65     CFGTOK_DOT,
66     CFGTOK_DOTDOT,
67     CFGTOK_EOF,
68
69     /* Primary blocks */
70     CFGTOK_CPU,
71     CFGTOK_ADDRSPACE,
72
73     /* Secondary stuff */
74     CFGTOK_TYPE,
75
76     /* Special identifiers */
77     CFGTOK_TRUE,
78     CFGTOK_FALSE
79
80 } cfgtok_t;
81
82
83
84 /* Mapping table entry, special identifier --> token */
85 typedef struct IdentTok IdentTok;
86 struct IdentTok {
87     const char* Ident;          /* Identifier */
88     cfgtok_t    Tok;            /* Token for identifier */
89 };
90 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
91
92
93
94 /* Current token and attributes */
95 extern cfgtok_t         CfgTok;
96 extern StrBuf           CfgSVal;
97 extern unsigned long    CfgIVal;
98
99 /* Error location */
100 extern unsigned         CfgErrorLine;
101 extern unsigned         CfgErrorCol;
102
103
104
105 /*****************************************************************************/
106 /*                                   Code                                    */
107 /*****************************************************************************/
108
109
110
111 void CfgWarning (const char* Format, ...) attribute((format(printf,1,2)));
112 /* Print a warning message adding file name and line number of the config file */
113
114 void CfgError (const char* Format, ...) attribute((format(printf,1,2)));
115 /* Print an error message adding file name and line number of the config file */
116
117 void CfgNextTok (void);
118 /* Read the next token from the input stream */
119
120 void CfgConsume (cfgtok_t T, const char* Msg);
121 /* Skip a token, print an error message if not found */
122
123 void CfgConsumeSemi (void);
124 /* Consume a semicolon */
125
126 void CfgConsumeColon (void);
127 /* Consume a colon */
128
129 void CfgConsumeRCurly (void);
130 /* Consume a right curly brace */
131
132 void CfgOptionalComma (void);
133 /* Consume a comma if there is one */
134
135 void CfgOptionalAssign (void);
136 /* Consume an equal sign if there is one */
137
138 void CfgAssureInt (void);
139 /* Make sure the next token is an integer */
140
141 void CfgAssureStr (void);
142 /* Make sure the next token is a string constant */
143
144 void CfgAssureIdent (void);
145 /* Make sure the next token is an identifier */
146
147 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
148 /* Check the range of CfgIVal */
149
150 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
151 /* Map an identifier to one of the special tokens in the table */
152
153 void CfgBoolToken (void);
154 /* Map an identifier or integer to a boolean token */
155
156 void CfgSetName (const char* Name);
157 /* Set a name for a config file */
158
159 const char* CfgGetName (void);
160 /* Get the name of the config file */
161
162 void CfgSetBuf (const char* Buf);
163 /* Set a memory buffer for the config */
164
165 int CfgAvail (void);
166 /* Return true if we have a configuration available */
167
168 void CfgOpenInput (void);
169 /* Open the input file if we have one */
170
171 void CfgCloseInput (void);
172 /* Close the input file if we have one */
173
174
175
176 /* End of scanner.h */
177 #endif
178
179
180