mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 17:29:50 +00:00
Working on .MID
git-svn-id: svn://svn.cc65.org/cc65/trunk@130 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
0ebf91be52
commit
158714acf9
@ -61,7 +61,7 @@ static TokList* CollectTokens (unsigned Start, unsigned Count)
|
||||
/* 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) {
|
||||
@ -83,6 +83,7 @@ static TokList* CollectTokens (unsigned Start, unsigned Count)
|
||||
}
|
||||
|
||||
/* Get the next token */
|
||||
++Current;
|
||||
NextTok ();
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ static void FuncMid (void)
|
||||
|
||||
/* Count argument */
|
||||
Count = ConstExpression ();
|
||||
if (Count > 100) {
|
||||
if (Count < 0 || Count > 100) {
|
||||
Error (ERR_RANGE);
|
||||
Count = 1;
|
||||
}
|
||||
@ -197,9 +198,7 @@ static void FuncMid (void)
|
||||
List = CollectTokens ((unsigned) Start, (unsigned) Count);
|
||||
|
||||
/* Insert it into the scanner feed */
|
||||
|
||||
|
||||
|
||||
PushTokList (List, ".MID");
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include "../common/xmalloc.h"
|
||||
|
||||
#include "istack.h"
|
||||
#include "scanner.h"
|
||||
#include "toklist.h"
|
||||
|
||||
@ -181,3 +182,56 @@ void AddCurTok (TokList* List)
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -105,6 +105,12 @@ void FreeTokList (TokList* T);
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user