static ExprNode* FuncBlank (void)
/* Handle the .BLANK builtin function */
{
- int Result = 1;
-
- /* Assume no tokens if the closing brace follows (this is not correct in
- * all cases, since the token may be the closing brace, but this will
- * give a syntax error anyway and may not be handled by .BLANK.
+ /* We have a list of tokens that ends with the closing paren. Skip
+ * the tokens, and count them. Allow optionally curly braces.
*/
- if (Tok != TOK_RPAREN) {
- /* Skip any tokens */
- int Braces = 0;
- while (!TokIsSep (Tok)) {
- if (Tok == TOK_LPAREN) {
- ++Braces;
- } else if (Tok == TOK_RPAREN) {
- if (Braces == 0) {
- /* Done */
- break;
- } else {
- --Braces;
- }
- }
- NextTok ();
+ enum Token Term = GetTokListTerm (TOK_RPAREN);
+ unsigned Count = 0;
+ while (Tok != Term) {
+
+ /* 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 (TokIsSep (Tok)) {
+ break;
}
- Result = 0;
+
+ /* One more token */
+ ++Count;
+
+ /* Skip the token */
+ NextTok ();
}
- return GenLiteralExpr (Result);
+
+ /* If the list was enclosed in curly braces, skip the closing brace */
+ if (Term == TOK_RCURLY && Tok == TOK_RCURLY) {
+ NextTok ();
+ }
+
+ /* Return true if the list was empty */
+ return GenLiteralExpr (Count == 0);
}
/* Handle the .MATCH and .XMATCH builtin functions */
{
int Result;
- enum Token Term;
TokNode* Root = 0;
TokNode* Last = 0;
TokNode* Node;
* single linked list of tokens including attributes. The list is
* either enclosed in curly braces, or terminated by a comma.
*/
- if (Tok == TOK_LCURLY) {
- NextTok ();
- Term = TOK_RCURLY;
- } else {
- Term = TOK_COMMA;
- }
+ enum Token Term = GetTokListTerm (TOK_COMMA);
while (Tok != Term) {
/* We may not end-of-line of end-of-file here */
}
/* Read the second list which is optionally enclosed in curly braces and
- * terminated by the right parenthesis. Compare each token against the
+ * terminated by the right parenthesis. Compare each token against the
* one in the first list.
*/
- if (Tok == TOK_LCURLY) {
- NextTok ();
- Term = TOK_RCURLY;
- } else {
- Term = TOK_RPAREN;
- }
+ Term = GetTokListTerm (TOK_RPAREN);
Result = 1;
Node = Root;
while (Tok != Term) {
/* 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.
+ * the tokens, and count them. Allow optionally curly braces.
*/
- int Count = 0;
- unsigned Parens = 0;
- while (Parens != 0 || Tok != TOK_RPAREN) {
+ enum Token Term = GetTokListTerm (TOK_RPAREN);
+ int Count = 0;
+ while (Tok != Term) {
/* 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
/* 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 ();
}
+ /* If the list was enclosed in curly braces, skip the closing brace */
+ if (Term == TOK_RCURLY && Tok == TOK_RCURLY) {
+ NextTok ();
+ }
+
/* Return the number of tokens */
return GenLiteralExpr (Count);
}
static ExprNode* Function (ExprNode* (*F) (void))
/* Handle builtin functions */
-{
+{
ExprNode* E;
/* Skip the keyword */
}
/* The macro may optionally be enclosed in curly braces */
- if (Tok == TOK_LCURLY) {
- NextTok ();
- Term = TOK_RCURLY;
- } else {
- Term = TOK_COMMA;
- }
+ Term = GetTokListTerm (TOK_COMMA);
/* Read tokens for one parameter, accept empty params */
Last = 0;
/* Read the actual parameters */
while (Count--) {
- enum Token Term;
TokNode* Last;
/* The macro may optionally be enclosed in curly braces */
- if (Tok == TOK_LCURLY) {
- NextTok ();
- Term = TOK_RCURLY;
- } else {
- Term = TOK_COMMA;
- }
+ enum Token Term = GetTokListTerm (TOK_COMMA);
/* Check if there is really a parameter */
if (TokIsSep (Tok) || Tok == Term) {
/* */
/* */
/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2004 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
void FreeTokList (TokList* T);
/* Delete the token list including all token nodes */
+enum Token GetTokListTerm (enum Token Term);
+/* Determine if the following token list is enclosed in curly braces. This is
+ * the case if the next token is the opening brace. If so, skip it and return
+ * a closing brace, otherwise return Term.
+ */
+
void AddCurTok (TokList* T);
/* Add the current token to the token list */