int nggen_read_identifier( char ch ) { char *cp; SYMBOL sp; int rc = 0; cp = yytext; do { *cp++ = ch; ch = GETCH(); if ( cp >= &yytext[lex_bufsize-1] ) { nggen_fatal("too long identifier"); break; } } while ( isalnum((int)ch) || ch == '_' || ch == '$' ); UNGETCH(ch); /* push back */ *cp = '\0'; sp = nggen_find_symbol(yytext); switch ( sp->s_type ) { case S_KEYWORD: rc = sp->s_value; break; case S_TYPE: yylval.val = nggen_make_enode(BASIC_TYPE_NODE, sp->s_value); rc = TYPE; break; case S_CLASS: yylval.val = nggen_make_enode(MODE_SPEC_NODE, sp->s_value); rc = MODE; break; case S_DISTMODE: yylval.val = nggen_make_enode(DISTMODE_SPEC_NODE, sp->s_value); rc = DISTMODE; break; case S_IDENT: yylval.val = nggen_make_enode_p(IDENT, sp); rc = IDENTIFIER; break; default: nggen_fatal("nggen_read_identifier"); break; } return(rc); }
char * nggen_xmalloc( int size ) { char *p; if ( (p = (char *)malloc(size)) == NULL ) { nggen_fatal("no memory"); } return(p); }
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); }