]> git.sur5r.net Git - cc65/blob - src/da65/scanner.h
Support for preprocessing info file via cpp or m4.
[cc65] / src / da65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*           Configuration file scanner for the da65 disassembler            */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2011, 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 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
47 /* Info file tokens */
48 typedef enum token_t {
49     INFOTOK_NONE,
50     INFOTOK_INTCON,
51     INFOTOK_STRCON,
52     INFOTOK_CHARCON,
53     INFOTOK_IDENT,
54     INFOTOK_LCURLY,
55     INFOTOK_RCURLY,
56     INFOTOK_SEMI,
57     INFOTOK_COMMA,
58     INFOTOK_EQ,
59     INFOTOK_COLON,
60     INFOTOK_DOT,
61     INFOTOK_EOF,
62
63     /* Special tokens */
64     INFOTOK_GLOBAL,
65     INFOTOK_RANGE,
66     INFOTOK_LABEL,
67     INFOTOK_ASMINC,
68     INFOTOK_SEGMENT,
69
70     /* Global section */
71     INFOTOK_ARGUMENT_COLUMN,
72     INFOTOK_COMMENT_COLUMN,
73     INFOTOK_COMMENTS,
74     INFOTOK_CPU,
75     INFOTOK_HEXOFFS,
76     INFOTOK_INPUTNAME,
77     INFOTOK_INPUTOFFS,
78     INFOTOK_INPUTSIZE,
79     INFOTOK_LABELBREAK,
80     INFOTOK_MNEMONIC_COLUMN,
81     INFOTOK_NL_AFTER_JMP,
82     INFOTOK_NL_AFTER_RTS,
83     INFOTOK_OUTPUTNAME,
84     INFOTOK_PAGELENGTH,
85     INFOTOK_STARTADDR,
86     INFOTOK_TEXT_COLUMN,
87
88     /* Range section */
89     INFOTOK_START,
90     INFOTOK_END,
91     INFOTOK_TYPE,
92
93     INFOTOK_CODE,
94     INFOTOK_BYTETAB,
95     INFOTOK_DBYTETAB,
96     INFOTOK_WORDTAB,
97     INFOTOK_DWORDTAB,
98     INFOTOK_ADDRTAB,
99     INFOTOK_RTSTAB,
100     INFOTOK_TEXTTAB,
101     INFOTOK_SKIP,
102
103     /* Label section */
104     INFOTOK_NAME,
105     INFOTOK_COMMENT,
106     INFOTOK_ADDR,
107     INFOTOK_SIZE,
108
109     /* ASMINC section */
110     INFOTOK_FILE,
111     INFOTOK_COMMENTSTART,
112     INFOTOK_IGNOREUNKNOWN,
113
114     /* */
115     INFOTOK_TRUE,
116     INFOTOK_FALSE
117 } token_t;
118
119
120 /* Mapping table entry, special identifier --> token */
121 typedef struct IdentTok IdentTok;
122 struct IdentTok {
123     const char*         Ident;          /* Identifier */
124     token_t             Tok;            /* Token for identifier */
125 };
126 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
127
128
129
130 /* Current token and attributes */
131 #define CFG_MAX_IDENT_LEN  255
132 extern unsigned         InfoTok;
133 extern char             InfoSVal[CFG_MAX_IDENT_LEN+1];
134 extern long             InfoIVal;
135
136 /* Error location */
137 extern unsigned         InfoErrorLine;
138 extern unsigned         InfoErrorCol;
139
140 /* Options */
141 extern unsigned char    InfoSyncLines;
142
143
144 /*****************************************************************************/
145 /*                                   Code                                    */
146 /*****************************************************************************/
147
148
149
150 void InfoWarning (const char* Format, ...);
151 /* Print a warning message adding file name and line number of the config file */
152
153 void InfoError (const char* Format, ...);
154 /* Print an error message adding file name and line number of the config file */
155
156 void InfoNextTok (void);
157 /* Read the next token from the input stream */
158
159 void InfoConsume (unsigned T, const char* Msg);
160 /* Skip a token, print an error message if not found */
161
162 void InfoConsumeLCurly (void);
163 /* Consume a left curly brace */
164
165 void InfoConsumeRCurly (void);
166 /* Consume a right curly brace */
167
168 void InfoConsumeSemi (void);
169 /* Consume a semicolon */
170
171 void InfoConsumeColon (void);
172 /* Consume a colon */
173
174 void InfoOptionalComma (void);
175 /* Consume a comma if there is one */
176
177 void InfoOptionalAssign (void);
178 /* Consume an equal sign if there is one */
179
180 void InfoAssureInt (void);
181 /* Make sure the next token is an integer */
182
183 void InfoAssureStr (void);
184 /* Make sure the next token is a string constant */
185
186 void InfoAssureChar (void);
187 /* Make sure the next token is a char constant */
188
189 void InfoAssureIdent (void);
190 /* Make sure the next token is an identifier */
191
192 void InfoRangeCheck (long Lo, long Hi);
193 /* Check the range of InfoIVal */
194
195 void InfoSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
196 /* Map an identifier to one of the special tokens in the table */
197
198 void InfoBoolToken (void);
199 /* Map an identifier or integer to a boolean token */
200
201 void InfoSetName (const char* Name);
202 /* Set a name for a config file */
203
204 const char* InfoGetName (void);
205 /* Get the name of the config file */
206
207 int InfoAvail ();
208 /* Return true if we have an info file given */
209
210 void InfoOpenInput (void);
211 /* Open the input file if we have one */
212
213 void InfoCloseInput (void);
214 /* Close the input file if we have one */
215
216
217
218 /* End of scanner.h */
219
220 #endif