From 6b002da6039523520f6370e464c51b8278ae1629 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 23 Jun 2000 20:49:47 +0000 Subject: [PATCH] Removed the strexpr module and placed the implementation of the .STRING builtin function into the NextTok function. Added the .CONCAT function. git-svn-id: svn://svn.cc65.org/cc65/trunk@113 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/make/gcc.mak | 1 - src/ca65/make/watcom.mak | 2 - src/ca65/nexttok.c | 120 ++++++++++++++++++++++++++++++++++++++- src/ca65/pseudo.c | 20 +++---- src/ca65/scanner.c | 1 + src/ca65/scanner.h | 1 + src/ca65/strexpr.c | 97 ------------------------------- src/ca65/strexpr.h | 61 -------------------- 8 files changed, 129 insertions(+), 174 deletions(-) delete mode 100644 src/ca65/strexpr.c delete mode 100644 src/ca65/strexpr.h diff --git a/src/ca65/make/gcc.mak b/src/ca65/make/gcc.mak index 6013fca2d..90494d084 100644 --- a/src/ca65/make/gcc.mak +++ b/src/ca65/make/gcc.mak @@ -25,7 +25,6 @@ OBJS = condasm.o \ options.o \ pseudo.o \ scanner.o \ - strexpr.o \ symtab.o \ toklist.o \ ulabel.o diff --git a/src/ca65/make/watcom.mak b/src/ca65/make/watcom.mak index 8b4eba838..430b964fb 100644 --- a/src/ca65/make/watcom.mak +++ b/src/ca65/make/watcom.mak @@ -82,7 +82,6 @@ OBJS = condasm.obj \ options.obj \ pseudo.obj \ scanner.obj \ - strexpr.obj \ symtab.obj \ toklist.obj \ ulabel.obj @@ -126,7 +125,6 @@ FILE objfile.obj FILE options.obj FILE pseudo.obj FILE scanner.obj -FILE strexpr.obj FILE symtab.obj FILE toklist.obj FILE ulabel.obj diff --git a/src/ca65/nexttok.c b/src/ca65/nexttok.c index 393412634..418130d86 100644 --- a/src/ca65/nexttok.c +++ b/src/ca65/nexttok.c @@ -33,6 +33,8 @@ +#include + #include "error.h" #include "expr.h" #include "scanner.h" @@ -93,10 +95,79 @@ static TokList* CollectTokens (unsigned Start, unsigned Count) +static void FuncConcat (void) +/* Handle the .CONCAT function */ +{ + char Buf[MAX_STR_LEN+1]; + char* B; + unsigned Length; + unsigned L; + + /* Skip it */ + NextTok (); + + /* Left paren expected */ + ConsumeLParen (); + + /* Concatenate any number of strings */ + B = Buf; + B[0] = '\0'; + Length = 0; + while (1) { + + /* Next token must be a string */ + if (Tok != TOK_STRCON) { + Error (ERR_STRCON_EXPECTED); + SkipUntilSep (); + return; + } + + /* Get the length of the string const and check total length */ + L = strlen (SVal); + if (Length + L > MAX_STR_LEN) { + Error (ERR_STRING_TOO_LONG); + /* Try to recover */ + SkipUntilSep (); + return; + } + + /* Add the new string */ + memcpy (B, SVal, L); + Length += L; + B += L; + + /* Skip the string token */ + NextTok (); + + /* Comma means another argument */ + if (Tok == TOK_COMMA) { + NextTok (); + } else { + /* Done */ + break; + } + } + + /* Terminate the string */ + *B = '\0'; + + /* We expect a closing parenthesis, but will not skip it but replace it + * by the string token just created. + */ + if (Tok != TOK_RPAREN) { + Error (ERR_RPAREN_EXPECTED); + } else { + Tok = TOK_STRCON; + strcpy (SVal, Buf); + } +} + + + static void FuncMid (void) /* Handle the .MID function */ { - long Start; + long Start; long Count; TokList* List; @@ -104,13 +175,13 @@ static void FuncMid (void) NextTok (); /* Left paren expected */ - ConsumeRParen (); + ConsumeLParen (); /* Start argument */ Start = ConstExpression (); if (Start < 0 || Start > 100) { Error (ERR_RANGE); - Start = 0; + Start = 0; } ConsumeComma (); @@ -133,6 +204,41 @@ static void FuncMid (void) +static void FuncString (void) +/* Handle the .STRING function */ +{ + char Buf[MAX_STR_LEN+1]; + + /* Skip it */ + NextTok (); + + /* Left paren expected */ + ConsumeLParen (); + + /* Accept identifiers or numeric expressions */ + if (Tok == TOK_IDENT) { + /* Save the identifier, then skip it */ + strcpy (Buf, SVal); + NextTok (); + } else { + /* Numeric expression */ + long Val = ConstExpression (); + sprintf (Buf, "%ld", Val); + } + + /* We expect a closing parenthesis, but will not skip it but replace it + * by the string token just created. + */ + if (Tok != TOK_RPAREN) { + Error (ERR_RPAREN_EXPECTED); + } else { + Tok = TOK_STRCON; + strcpy (SVal, Buf); + } +} + + + void NextTok (void) /* Get next token and handle token level functions */ { @@ -142,10 +248,18 @@ void NextTok (void) /* Check for token handling functions */ switch (Tok) { + case TOK_CONCAT: + FuncConcat (); + break; + case TOK_MID: FuncMid (); break; + case TOK_STRING: + FuncString (); + break; + default: /* Quiet down gcc */ break; diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 3190d457f..c00d75a9c 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -52,7 +52,6 @@ #include "nexttok.h" #include "objcode.h" #include "options.h" -#include "strexpr.h" #include "symtab.h" #include "pseudo.h" @@ -250,7 +249,7 @@ static void DoASCIIZ (void) /* Define text with a zero terminator */ { while (1) { - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); return; } @@ -287,7 +286,7 @@ static void DoByte (void) /* Define bytes */ { while (1) { - if (StringExpression () != 0) { + if (Tok == TOK_STRCON) { /* A string */ EmitData (SVal, strlen (SVal)); NextTok (); @@ -399,7 +398,7 @@ static void DoEndProc (void) static void DoError (void) /* Use error */ { - if (StringExpression () == 0) { + if (Tok == TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); } else { Error (ERR_USER, SVal); @@ -535,7 +534,7 @@ static void DoFileOpt (void) ConsumeComma (); /* We accept only string options for now */ - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); return; } @@ -579,7 +578,7 @@ static void DoFileOpt (void) ConsumeComma (); /* We accept only string options for now */ - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); return; } @@ -656,7 +655,7 @@ static void DoIncBin (void) /* Include a binary file */ { /* Name must follow */ - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); } else { /* Try to open the file */ @@ -686,7 +685,7 @@ static void DoInclude (void) char Name [MAX_STR_LEN+1]; /* Name must follow */ - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); } else { strcpy (Name, SVal); @@ -823,7 +822,7 @@ static void DoOrg (void) static void DoOut (void) /* Output a string */ { - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); } else { /* Output the string and be sure to flush the output to keep it in @@ -950,7 +949,7 @@ static void DoSegment (void) char Name [sizeof (SVal)]; int SegType; - if (StringExpression () == 0) { + if (Tok != TOK_STRCON) { ErrorSkip (ERR_STRCON_EXPECTED); } else { @@ -1079,6 +1078,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoByte }, { ccNone, DoCase }, { ccNone, DoCode }, + { ccNone, DoUnexpected, }, /* .CONCAT */ { ccNone, DoUnexpected }, /* .CONST */ { ccNone, DoUnexpected }, /* .CPU */ { ccNone, DoData }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 7b0718b4d..357144aa1 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -136,6 +136,7 @@ struct DotKeyword { { "BYTE", TOK_BYTE }, { "CASE", TOK_CASE }, { "CODE", TOK_CODE }, + { "CONCAT", TOK_CONCAT }, { "CONST", TOK_CONST }, { "CPU", TOK_CPU }, { "DATA", TOK_DATA }, diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index 7c1a424c2..f28e30d47 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -118,6 +118,7 @@ enum Token { TOK_BYTE, TOK_CASE, TOK_CODE, + TOK_CONCAT, TOK_CONST, TOK_CPU, TOK_DATA, diff --git a/src/ca65/strexpr.c b/src/ca65/strexpr.c deleted file mode 100644 index e3d30baff..000000000 --- a/src/ca65/strexpr.c +++ /dev/null @@ -1,97 +0,0 @@ -/*****************************************************************************/ -/* */ -/* strexpr.c */ -/* */ -/* String expressions for the ca65 macroassembler */ -/* */ -/* */ -/* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ -/* */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - - - -#include - -#include "error.h" -#include "expr.h" -#include "scanner.h" -#include "strexpr.h" - - - -/*****************************************************************************/ -/* Code */ -/*****************************************************************************/ - - - -const char* StringExpression (void) -/* Evaluate a string expression. If there are no errors, the function will - * place the string into the token attribute buffer SVal and the token will - * be TOK_STRCON. A pointer to the buffer is returned. - * If there was an error, a NULL pointer is returned. - */ -{ - char Buf [sizeof (SVal)]; - - /* Check for a string constant or a function that returns a string */ - switch (Tok) { - - case TOK_STRING: - NextTok (); - ConsumeLParen (); - if (Tok == TOK_IDENT) { - /* Save the identifier, then skip it */ - strcpy (Buf, SVal); - NextTok (); - } else { - /* Numeric expression */ - long Val = ConstExpression (); - sprintf (Buf, "%ld", Val); - } - if (Tok != TOK_RPAREN) { - Error (ERR_RPAREN_EXPECTED); - } - /* Overwrite the token, do not skip it! */ - strcpy (SVal, Buf); - Tok = TOK_STRCON; - break; - - case TOK_STRCON: - /* We already have a string */ - break; - - default: - /* Error - no string constant */ - return 0; - } - - /* Return a pointer to the buffer */ - return SVal; -} - - - diff --git a/src/ca65/strexpr.h b/src/ca65/strexpr.h deleted file mode 100644 index 9457b9fe2..000000000 --- a/src/ca65/strexpr.h +++ /dev/null @@ -1,61 +0,0 @@ -/*****************************************************************************/ -/* */ -/* strexpr.h */ -/* */ -/* String expressions for the ca65 macroassembler */ -/* */ -/* */ -/* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ -/* */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - - - -#ifndef STREXPR_H -#define STREXPR_H - - - -/*****************************************************************************/ -/* Code */ -/*****************************************************************************/ - - - -const char* StringExpression (void); -/* Evaluate a string expression. If there are no errors, the function will - * place the string into the token attribute buffer SVal and the token will - * be TOK_STRCON. A pointer to the buffer is returned. - * If there was an error, a NULL pointer is returned. - */ - - - -/* End of strexpr.h */ - -#endif - - - -- 2.39.5