/* Read the token list */
unsigned Current = 0;
unsigned Parens = 0;
- while (Parens != 0 && Tok != TOK_RPAREN) {
+ while (Parens != 0 || Tok != TOK_RPAREN) {
/* Check for end of line or end of input */
if (Tok == TOK_SEP || Tok == TOK_EOF) {
}
/* Get the next token */
+ ++Current;
NextTok ();
}
/* Count argument */
Count = ConstExpression ();
- if (Count > 100) {
+ if (Count < 0 || Count > 100) {
Error (ERR_RANGE);
Count = 1;
}
List = CollectTokens ((unsigned) Start, (unsigned) Count);
/* Insert it into the scanner feed */
-
-
-
+ PushTokList (List, ".MID");
}
#include "../common/xmalloc.h"
+#include "istack.h"
#include "scanner.h"
#include "toklist.h"
+static int ReplayTokList (void* List)
+/* Function that gets the next token from a token list and sets it. This
+ * function may be used together with the PushInput function from the istack
+ * module.
+ */
+{
+ /* Cast the generic pointer to an actual list */
+ TokList* L = List;
+
+ /* Set the next token from the list */
+ TokSet (L->Last);
+
+ /* If this was the last token, decrement the repeat counter. If it goes
+ * zero, delete the list and remove the function from the stack.
+ */
+ if (L->Last == 0) {
+ if (--L->Repeat == 0) {
+ /* Done with this list */
+ FreeTokList (L);
+ PopInput ();
+ } else {
+ /* Replay one more time */
+ L->Last = L->Root;
+ }
+ }
+
+ /* We have a token */
+ return 1;
+}
+
+
+
+void PushTokList (TokList* List, const char* Desc)
+/* Push a token list to be used as input for InputFromStack. This includes
+ * several initializations needed in the token list structure, so don't use
+ * PushInput directly.
+ */
+{
+ /* If the list is empty, just delete it and bail out */
+ if (List->Count == 0) {
+ FreeTokList (List);
+ return;
+ }
+
+ /* Reset the last pointer to the first element */
+ List->Last = List->Root;
+
+ /* Insert the list specifying our input function */
+ PushInput (ReplayTokList, List, Desc);
+}
+
+
+
void AddCurTok (TokList* T);
/* Add the current token to the token list */
+void PushTokList (TokList* List, const char* Desc);
+/* Push a token list to be used as input for InputFromStack. This includes
+ * several initializations needed in the token list structure, so don't use
+ * PushInput directly.
+ */
+
/* End of toklist.h */