mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-07-05 01:28:57 +00:00
Added hex character constants within strings.
This commit is contained in:
parent
951d03c4d3
commit
10db0b073a
@ -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);
|
||||
|
@ -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++;
|
||||
}
|
||||
|
Binary file not shown.
@ -125,4 +125,5 @@ puti(mystruc)
|
||||
putln
|
||||
puts(@constr); puti(constval); putln
|
||||
puts("Hello from in-line string!\n")
|
||||
puts("Hi \$41pple.\n");
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user