1 /*****************************************************************************/
5 /* Get next token and handle token level functions */
9 /* (C) 2000 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 /*****************************************************************************/
44 /*****************************************************************************/
46 /*****************************************************************************/
50 static TokList* CollectTokens (unsigned Start, unsigned Count)
51 /* Read a list of tokens that is terminated by a right paren. For all tokens
52 * starting at the one with index Start, and ending at (Start+Count-1), place
53 * them into a token list, and return this token list.
56 /* Create the token list */
57 TokList* List = NewTokList ();
59 /* Read the token list */
62 while (Parens != 0 && Tok != TOK_RPAREN) {
64 /* Check for end of line or end of input */
65 if (Tok == TOK_SEP || Tok == TOK_EOF) {
66 Error (ERR_UNEXPECTED_EOL);
70 /* Collect tokens in the given range */
71 if (Current >= Start && Current < Start+Count) {
72 /* Add the current token to the list */
76 /* Check for and count parenthesii */
77 if (Tok == TOK_LPAREN) {
79 } else if (Tok == TOK_RPAREN) {
83 /* Get the next token */
87 /* Eat the closing paren */
90 /* Return the list of collected tokens */
96 static void FuncMid (void)
97 /* Handle the .MID function */
106 /* Left paren expected */
110 Start = ConstExpression ();
111 if (Start < 0 || Start > 100) {
118 Count = ConstExpression ();
125 /* Read the token list */
126 List = CollectTokens ((unsigned) Start, (unsigned) Count);
128 /* Insert it into the scanner feed */
137 /* Get next token and handle token level functions */
139 /* Get the next raw token */
142 /* Check for token handling functions */
158 void Consume (enum Token Expected, unsigned ErrMsg)
159 /* Consume Expected, print an error if we don't find it */
161 if (Tok == Expected) {
170 void ConsumeSep (void)
171 /* Consume a separator token */
173 /* Accept an EOF as separator */
174 if (Tok != TOK_EOF) {
175 if (Tok != TOK_SEP) {
176 Error (ERR_TOO_MANY_CHARS);
186 void ConsumeLParen (void)
187 /* Consume a left paren */
189 Consume (TOK_LPAREN, ERR_LPAREN_EXPECTED);
194 void ConsumeRParen (void)
195 /* Consume a right paren */
197 Consume (TOK_RPAREN, ERR_RPAREN_EXPECTED);
202 void ConsumeComma (void)
203 /* Consume a comma */
205 Consume (TOK_COMMA, ERR_COMMA_EXPECTED);
210 void SkipUntilSep (void)
211 /* Skip tokens until we reach a line separator */
213 while (Tok != TOK_SEP && Tok != TOK_EOF) {