expr nggen_list0( enum expr_code code ) { return(nggen_make_enode_p(code, NULL)); }
expr nggen_list1( enum expr_code code, expr x1 ) { return(nggen_make_enode_p(code, (void *)nggen_cons_list(x1, NULL))); }
expr nggen_list3( enum expr_code code, expr x1, expr x2, expr x3 ) { return(nggen_make_enode_p(code, (void *) nggen_cons_list(x1, nggen_cons_list(x2, nggen_cons_list(x3, NULL))))); }
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); }
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); }
int nggen_read_number( int ch ) { char *cp; long int value; value = 0; if ( ch == '0' ) { ch = GETCH(); if ( ch == 'x' || ch == 'X' ) { /* HEX */ for ( ; ; ) { ch = GETCH(); if ( !isxdigit(ch) ) { break; } if ( isdigit(ch) ) { value = value * 16 + ch - '0'; } else if ( isupper(ch) ) { value = value * 16 + ch - 'A' + 10; } else { value = value * 16 + ch - 'a' + 10; } } } if ( ch == '.' ) { goto read_floating; } else { /* octal */ while ( ch >= '0' && ch <= '7' ) { value = value * 8 + ch - '0'; ch = GETCH(); } } goto ret_INT; } /* else decimal or floating */ read_floating: cp = yytext; while ( isdigit(ch) ) { value = value * 10 + ch - '0'; *cp++ = ch; ch = GETCH(); } if ( ch != '.' && ch != 'e' && ch != 'E' ) { goto ret_INT; } /* floating */ if ( ch == '.' ) { *cp++ = ch; /* reading floating */ ch = GETCH(); while ( isdigit(ch) ) { *cp++ = ch; ch = GETCH(); } } if ( ch == 'e' || ch == 'E' ) { *cp++ = 'e'; ch = GETCH(); if ( ch == '+' || ch == '-' ) { *cp++ = ch; ch = GETCH(); } while ( isdigit(ch) ) { *cp++ = ch; ch = GETCH(); } } UNGETCH(ch); *cp = '\0'; yylval.val = nggen_make_enode_p(FLOAT_CONSTANT, nggen_save_float(atof(yytext))); return(CONSTANT); ret_INT: if ( ch == 'L' ) { yylval.val = nggen_make_enode(LONG_CONSTANT, value); } else { UNGETCH(ch); yylval.val = nggen_make_enode(INT_CONSTANT, value); } return(CONSTANT); }