cc: allow runes as macro names (from charles forsyth)
This commit is contained in:
parent
2d59b15c39
commit
651b2a32be
1 changed files with 33 additions and 21 deletions
|
@ -18,22 +18,27 @@ getnsn(void)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sym*
|
static void
|
||||||
getsym(void)
|
nextsym(int c)
|
||||||
{
|
{
|
||||||
int c;
|
int c1;
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
c = getnsc();
|
|
||||||
if(!isalpha(c) && c != '_' && c < Runeself) {
|
|
||||||
unget(c);
|
|
||||||
return S;
|
|
||||||
}
|
|
||||||
for(cp = symb;;) {
|
for(cp = symb;;) {
|
||||||
if(cp <= symb+NSYMB-4)
|
if(c >= Runeself) {
|
||||||
*cp++ = c;
|
for(c1=0;;) {
|
||||||
|
if(cp <= symb+NSYMB-4)
|
||||||
|
cp[c1++] = c;
|
||||||
|
if(fullrune(cp, c1))
|
||||||
|
break;
|
||||||
|
c = getc();
|
||||||
|
}
|
||||||
|
cp += c1;
|
||||||
|
}else
|
||||||
|
if(cp <= symb+NSYMB-4)
|
||||||
|
*cp++ = c;
|
||||||
c = getc();
|
c = getc();
|
||||||
if(isalnum(c) || c == '_' || c >= Runeself)
|
if(c >= Runeself || isalnum(c) || c == '_')
|
||||||
continue;
|
continue;
|
||||||
unget(c);
|
unget(c);
|
||||||
break;
|
break;
|
||||||
|
@ -41,6 +46,19 @@ getsym(void)
|
||||||
*cp = 0;
|
*cp = 0;
|
||||||
if(cp > symb+NSYMB-4)
|
if(cp > symb+NSYMB-4)
|
||||||
yyerror("symbol too large: %s", symb);
|
yyerror("symbol too large: %s", symb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sym*
|
||||||
|
getsym(void)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = getnsc();
|
||||||
|
if(c < Runeself && !isalpha(c) && c != '_') {
|
||||||
|
unget(c);
|
||||||
|
return S;
|
||||||
|
}
|
||||||
|
nextsym(c);
|
||||||
return lookup();
|
return lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +211,7 @@ void
|
||||||
macdef(void)
|
macdef(void)
|
||||||
{
|
{
|
||||||
Sym *s, *a;
|
Sym *s, *a;
|
||||||
char *args[NARG], *np, *base;
|
char *args[NARG], *base;
|
||||||
int n, i, c, len, dots;
|
int n, i, c, len, dots;
|
||||||
int ischr;
|
int ischr;
|
||||||
|
|
||||||
|
@ -235,15 +253,9 @@ macdef(void)
|
||||||
len = 1;
|
len = 1;
|
||||||
ischr = 0;
|
ischr = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(isalpha(c) || c == '_') {
|
if(c >= Runeself || isalpha(c) || c == '_') {
|
||||||
np = symb;
|
nextsym(c);
|
||||||
*np++ = c;
|
|
||||||
c = getc();
|
c = getc();
|
||||||
while(isalnum(c) || c == '_') {
|
|
||||||
*np++ = c;
|
|
||||||
c = getc();
|
|
||||||
}
|
|
||||||
*np = 0;
|
|
||||||
for(i=0; i<n; i++)
|
for(i=0; i<n; i++)
|
||||||
if(strcmp(symb, args[i]) == 0)
|
if(strcmp(symb, args[i]) == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -295,7 +307,7 @@ macdef(void)
|
||||||
c = getc();
|
c = getc();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(c == '\n') {
|
if(0 && c == '\n') {
|
||||||
yyerror("comment and newline in define: %s", s->name);
|
yyerror("comment and newline in define: %s", s->name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue