1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-22 12:30:41 +00:00

Added the .TCOUNT function

git-svn-id: svn://svn.cc65.org/cc65/trunk@151 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-07-15 10:33:32 +00:00
parent 9cc7dc1284
commit 359a89d0bf
4 changed files with 49 additions and 4 deletions

View File

@ -117,7 +117,7 @@ static void FreeExprNode (ExprNode* E)
/* Dump an expression tree on stdout for debugging */
/*****************************************************************************/
static void InternalDumpExpr (ExprNode* Expr)
/* Dump an expression in UPN */
@ -467,6 +467,44 @@ static int FuncReferenced (void)
static int FuncTCount (void)
/* Handle the .TCOUNT function */
{
/* We have a list of tokens that ends with the closing paren. Skip
* the tokens, handling nested braces and count them.
*/
int Count = 0;
unsigned Parens = 0;
while (Parens != 0 || Tok != TOK_RPAREN) {
/* Check for end of line or end of input. Since the calling function
* will check for the closing paren, we don't need to print an error
* here, just bail out.
*/
if (Tok == TOK_SEP || Tok == TOK_EOF) {
break;
}
/* One more token */
++Count;
/* Keep track of the nesting level */
switch (Tok) {
case TOK_LPAREN: ++Parens; break;
case TOK_RPAREN: --Parens; break;
default: break;
}
/* Skip the token */
NextTok ();
}
/* Return the number of tokens */
return Count;
}
static int FuncXMatch (void)
/* Handle the .XMATCH function */
{
@ -492,7 +530,7 @@ static ExprNode* Function (int (*F) (void))
NextTok ();
/* Call the function itself */
Result = (F () != 0);
Result = F ();
/* Closing brace must follow */
ConsumeRParen ();
@ -509,7 +547,7 @@ static ExprNode* Factor (void)
SymEntry* S;
switch (Tok) {
case TOK_INTCON:
case TOK_CHARCON:
N = LiteralExpr (IVal);
@ -620,6 +658,10 @@ static ExprNode* Factor (void)
N = Function (FuncReferenced);
break;
case TOK_TCOUNT:
N = Function (FuncTCount);
break;
case TOK_XMATCH:
N = Function (FuncXMatch);
break;

View File

@ -1164,6 +1164,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoSmart },
{ ccNone, DoUnexpected }, /* .STRING */
{ ccNone, DoSunPlus },
{ ccNone, DoUnexpected }, /* .TCOUNT */
{ ccNone, DoWord },
{ ccNone, DoUnexpected }, /* .XMATCH */
{ ccNone, DoZeropage },

View File

@ -221,6 +221,7 @@ struct DotKeyword {
{ "SMART", TOK_SMART },
{ "STRING", TOK_STRING },
{ "SUNPLUS", TOK_SUNPLUS },
{ "TCOUNT", TOK_TCOUNT },
{ "WORD", TOK_WORD },
{ "XMATCH", TOK_XMATCH },
{ "XOR", TOK_BXOR },

View File

@ -183,13 +183,14 @@ enum Token {
TOK_REFERENCED,
TOK_RELOC,
TOK_REPEAT,
TOK_RES,
TOK_RES,
TOK_RIGHT,
TOK_RODATA,
TOK_SEGMENT,
TOK_SMART,
TOK_STRING,
TOK_SUNPLUS,
TOK_TCOUNT,
TOK_WORD,
TOK_XMATCH,
TOK_ZEROPAGE,