diff --git a/Platform/Apple/tools/PLASMA/src/codegen.h b/Platform/Apple/tools/PLASMA/src/codegen.h index 9046ddae..14ff6a38 100755 --- a/Platform/Apple/tools/PLASMA/src/codegen.h +++ b/Platform/Apple/tools/PLASMA/src/codegen.h @@ -26,6 +26,7 @@ void emit_def(char *name, int is_bytecode); int emit_data(int vartype, int consttype, long constval, int constsize); void emit_codetag(int tag); void emit_const(int cval); +void emit_conststr(long conststr, int strsize); void emit_lb(void); void emit_lw(void); void emit_llb(int index); diff --git a/Platform/Apple/tools/PLASMA/src/lex.c b/Platform/Apple/tools/PLASMA/src/lex.c index 938c3997..39390c10 100755 --- a/Platform/Apple/tools/PLASMA/src/lex.c +++ b/Platform/Apple/tools/PLASMA/src/lex.c @@ -75,6 +75,18 @@ void parse_error(char *errormsg) fprintf(stderr, "^\nError: %s\n", errormsg); exit(1); } + +int hexdigit(char ch) +{ + ch = toupper(ch); + if (ch >= '0' && ch <= '9') + return ch - '0'; + else if (ch >= 'A' && ch <= 'F') + return ch - 'A' + 10; + else + return -1; +} + t_token scan(void) { prevtoken = scantoken; @@ -152,12 +164,8 @@ t_token scan(void) constval = 0; while (scanpos++) { - if (*scanpos >= '0' && *scanpos <= '9') - constval = constval * 16 + *scanpos - '0'; - else if (*scanpos >= 'A' && *scanpos <= 'F') - constval = constval * 16 + *scanpos - 'A' + 10; - else if (*scanpos >= 'a' && *scanpos <= 'f') - constval = constval * 16 + *scanpos - 'a' + 10; + if (hexdigit(*scanpos) >= 0) + constval = constval * 16 + hexdigit(*scanpos); else break; } @@ -216,6 +224,7 @@ t_token scan(void) else if (scanpos[0] == '\"') { char *scanshift; + int scanoffset; /* * String constant. */ @@ -225,6 +234,7 @@ t_token scan(void) { if (*scanpos == '\\') { + scanoffset = 1; switch (scanpos[1]) { case 'n': @@ -248,12 +258,20 @@ t_token scan(void) case '0': *scanpos = '\0'; break; + case '$': + if (hexdigit(scanpos[2]) < 0 || hexdigit(scanpos[3]) < 0) { + parse_error("Bad string constant"); + return (-1); + } + *scanpos = hexdigit(scanpos[2]) * 16 + hexdigit(scanpos[3]); + scanoffset = 3; + break; default: parse_error("Bad string constant"); return (-1); } for (scanshift = scanpos + 1; *scanshift; scanshift++) - scanshift[0] = scanshift[1]; + scanshift[0] = scanshift[scanoffset]; } scanpos++; } diff --git a/Platform/Apple/tools/PLASMA/src/plasm.jar b/Platform/Apple/tools/PLASMA/src/plasm.jar index f6f96050..e06f418b 100644 Binary files a/Platform/Apple/tools/PLASMA/src/plasm.jar and b/Platform/Apple/tools/PLASMA/src/plasm.jar differ diff --git a/Platform/Apple/tools/PLASMA/src/test.pla b/Platform/Apple/tools/PLASMA/src/test.pla index 6a521338..7a74d8e6 100755 --- a/Platform/Apple/tools/PLASMA/src/test.pla +++ b/Platform/Apple/tools/PLASMA/src/test.pla @@ -125,4 +125,5 @@ puti(mystruc) putln puts(@constr); puti(constval); putln puts("Hello from in-line string!\n") +puts("Hi \$41pple.\n"); done