1 /*****************************************************************************/
5 /* Token list for the ca65 macroassembler */
9 /* (C) 1998 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
38 #include "../common/xmalloc.h"
45 /*****************************************************************************/
47 /*****************************************************************************/
51 TokNode* NewTokNode (void)
52 /* Create and return a token node with the current token value */
57 unsigned Len = TokHasSVal (Tok)? strlen (SVal) : 0;
58 T = xmalloc (sizeof (TokNode) + Len);
60 /* Initialize the token contents */
65 memcpy (T->SVal, SVal, Len);
74 void FreeTokNode (TokNode* T)
75 /* Free the given token node */
82 void TokSet (TokNode* T)
83 /* Set the scanner token from the given token node */
89 strcpy (SVal, T->SVal);
94 enum TC TokCmp (const TokNode* T)
95 /* Compare the token given as parameter against the current token */
102 /* If the token has string attribute, check it */
103 if (TokHasSVal (T->Tok)) {
104 if (strcmp (T->SVal, SVal) != 0) {
107 } else if (TokHasIVal (T->Tok)) {
108 if (T->IVal != IVal) {
113 /* Tokens are identical */
119 void InitTokList (TokList* T)
120 /* Initialize a token list structure for later use */
122 /* Initialize the fields */
132 TokList* NewTokList (void)
133 /* Create a new, empty token list */
135 /* Allocate memory for the list structure */
136 TokList* T = xmalloc (sizeof (TokList));
138 /* Initialize the fields */
141 /* Return the new list */
147 void FreeTokList (TokList* List)
148 /* Delete the token list including all token nodes */
150 /* Free the token list */
151 TokNode* T = List->Root;
158 /* Free the list structure itself */
164 void AddCurTok (TokList* List)
165 /* Add the current token to the token list */
167 /* Create a token node with the current token value */
168 TokNode* T = NewTokNode ();
170 /* Insert the node into the list */
171 if (List->Root == 0) {
174 List->Last->Next = T;