SYMBOL nggen_find_symbol( char *name ) { SYMBOL sp; int hcode; char *cp; hcode = 0; /* hash code, bad ?? */ for ( cp = name; *cp != 0; cp++ ) { hcode = (hcode << 1) + *cp; } hcode &= SYMBOL_HASH_MASK; for ( sp = symbol_hash_table[hcode]; sp != NULL; sp = sp->s_next ) { if ( strcmp(name, sp->s_name) == 0 ) { return(sp); } } /* not found, then allocate symbol */ sp = XMALLOC(SYMBOL, sizeof(*sp)); memset((char *)sp, 0, sizeof(*sp)); sp->s_name = nggen_save_str(name); /* link it */ sp->s_next = symbol_hash_table[hcode]; symbol_hash_table[hcode] = sp; return(sp); }
expr nggen_read_rest_of_body( int flag ) { char *cp; int ch; char in_string; int nest_level; cp = yytext; if ( flag ) { *cp++ = '{'; /* already read */ } in_string = 0; nest_level = 1; do { ch = GETCH(); if ( ch == EOF ) { nggen_error("unexpected EOF"); break; } else if ( ch == '\\' ) { /* escape */ *cp++ = ch; *cp++ = GETCH(); continue; } if ( in_string != 0 && in_string == ch ) { in_string = 0; } else if ( in_string == 0 ) { /* out string */ if ( ch == '"' || ch == '\'' ) { in_string = ch; } else if ( ch == '{' ) { /* else count nest level */ nest_level++; } else if ( ch == '}' ) { nest_level--; } } *cp++ = ch; } while ( nest_level > 0 ); if ( !flag ) { cp--; } *cp = '\0'; return(nggen_make_enode_p(STRING_CONSTANT, nggen_save_str(yytext))); }
int nggen_read_string_constant( int mark ) { int ch; char *cp; int value; int i; cp = yytext; while ( (ch = GETCH()) != mark ) { switch ( ch ) { case EOF: nggen_error("unexpected EOF"); break; #ifdef not case '\n': nggen_error("newline in string or char constant"); break; #endif case '\\': /* escape */ switch ( ch = GETCH() ) { case '\n': continue; case 'n': ch = '\n'; break; case 'r': ch = '\r'; break; case 'b': ch = '\b'; break; case 't': ch = '\t'; break; case 'f': ch = '\f'; break; case 'v': ch = '\013'; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': value = ch - '0'; ch = GETCH(); /* try for 2 */ if ( ch >= '0' && ch <= '7' ) { value = (value << 3) | (ch - '0'); ch = GETCH(); if ( ch >= '0' && ch <= '7' ) { value = (value << 3) | (ch - '0'); } else { UNGETCH(ch); } } else { UNGETCH(ch); } ch = value; break; } default: *cp++ = ch; } if ( cp >= &yytext[lex_bufsize - 1] ) { nggen_fatal("too long string"); break; } } *cp = '\0'; if ( mark == '"' ) { /* end of string or char constant */ yylval.val = nggen_make_enode_p(STRING_CONSTANT, nggen_save_str(yytext)); return(STRING); } else { if ( cp == yytext ) { /* end the character constant */ nggen_error("empty character constant"); } if ( (unsigned)(cp - yytext) > (sizeof(int) / sizeof(char)) ) { nggen_error("too many characters in character constant"); } value = 0; for ( i = 0; (unsigned)i < sizeof(int); i++ ) { if ( yytext[i] == 0 ) { break; } value = (value << 8)| (0xFF & yytext[i]); } yylval.val = nggen_make_enode(INT_CONSTANT, value); } return(CONSTANT); }