+static int FuncStrAt (void)
+/* Handle the .STRAT function */
+{
+ char Str [sizeof(SVal)];
+ long Index;
+
+ /* String constant expected */
+ if (Tok != TOK_STRCON) {
+ Error (ERR_STRCON_EXPECTED);
+ NextTok ();
+ return 0;
+
+ }
+
+ /* Remember the string and skip it */
+ strcpy (Str, SVal);
+ NextTok ();
+
+ /* Comma must follow */
+ ConsumeComma ();
+
+ /* Expression expected */
+ Index = ConstExpression ();
+
+ /* Must be a valid index */
+ if (Index >= strlen (Str)) {
+ Error (ERR_RANGE);
+ return 0;
+ }
+
+ /* Return the char, handle as unsigned */
+ return (unsigned char) Str[(size_t)Index];
+}
+
+
+
+static int FuncStrLen (void)
+/* Handle the .STRLEN function */
+{
+ /* String constant expected */
+ if (Tok != TOK_STRCON) {
+
+ Error (ERR_STRCON_EXPECTED);
+ /* Smart error recovery */
+ if (Tok != TOK_RPAREN) {
+ NextTok ();
+ }
+ return 0;
+
+ } else {
+
+ /* Get the length of the string */
+ int Len = strlen (SVal);
+
+ /* Skip the string */
+ NextTok ();
+
+ /* Return the length */
+ return Len;
+
+ }
+}
+
+
+
static int FuncTCount (void)
/* Handle the .TCOUNT function */
{
switch (Tok) {
case TOK_LPAREN: ++Parens; break;
case TOK_RPAREN: --Parens; break;
- default: break;
+ default: break;
}
/* Skip the token */
SymEntry* S;
switch (Tok) {
-
+
case TOK_INTCON:
case TOK_CHARCON:
- N = LiteralExpr (IVal);
+ N = LiteralExpr (IVal);
NextTok ();
break;
/* Create symbol node */
N = NewExprNode ();
N->Op = EXPR_SYMBOL;
- N->V.Sym = S;
+ N->V.Sym = S;
}
NextTok ();
}
N = Function (FuncReferenced);
break;
+ case TOK_STRAT:
+ N = Function (FuncStrAt);
+ break;
+
+ case TOK_STRLEN:
+ N = Function (FuncStrLen);
+ break;
+
case TOK_TCOUNT:
N = Function (FuncTCount);
break;
{ "LOCALCHAR", TOK_LOCALCHAR },
{ "MAC", TOK_MACRO },
{ "MACPACK", TOK_MACPACK },
- { "MACRO", TOK_MACRO },
+ { "MACRO", TOK_MACRO },
{ "MATCH", TOK_MATCH },
{ "MID", TOK_MID },
{ "MOD", TOK_MOD },
{ "RELOC", TOK_RELOC },
{ "REPEAT", TOK_REPEAT },
{ "RES", TOK_RES },
- { "RIGHT", TOK_RIGHT },
- { "RODATA", TOK_RODATA },
- { "SEGMENT", TOK_SEGMENT },
- { "SHL", TOK_SHL },
- { "SHR", TOK_SHR },
- { "SMART", TOK_SMART },
- { "STRING", TOK_STRING },
- { "SUNPLUS", TOK_SUNPLUS },
- { "TCOUNT", TOK_TCOUNT },
- { "WORD", TOK_WORD },
- { "XMATCH", TOK_XMATCH },
- { "XOR", TOK_BXOR },
- { "ZEROPAGE", TOK_ZEROPAGE },
+ { "RIGHT", TOK_RIGHT },
+ { "RODATA", TOK_RODATA },
+ { "SEGMENT", TOK_SEGMENT },
+ { "SHL", TOK_SHL },
+ { "SHR", TOK_SHR },
+ { "SMART", TOK_SMART },
+ { "STRAT", TOK_STRAT },
+ { "STRING", TOK_STRING },
+ { "STRLEN", TOK_STRLEN },
+ { "SUNPLUS", TOK_SUNPLUS },
+ { "TCOUNT", TOK_TCOUNT },
+ { "WORD", TOK_WORD },
+ { "XMATCH", TOK_XMATCH },
+ { "XOR", TOK_BXOR },
+ { "ZEROPAGE", TOK_ZEROPAGE },
};