Example #1
0
void cpp_macro_lexer_next(ParseEnv* env, MLToken* token) {
	if( !env ) {
		cpp_lexer_next(env->lexer, token);
		return;
	}

	for(;;) {
		cpp_lexer_next(env->lexer, token);
		if( token->type==TK_MACRO ) {
			CppLexer mlexer;

			cpp_lexer_init(&mlexer, token->buf, token->len, token->line);
			cpp_parse_macro(env, &mlexer);
			cpp_lexer_final(&mlexer);
			continue;
		}

		if( token->type==TK_ID ) {
			MLStr name = { token->buf, token->len };
			CppElem* macro = find_macro(env, &name);

			if( !macro )
				break;

			if( macro_replace(env, macro, token) )
				continue;
		}

		break;
	}
}
int main(int argc,char *argv[])
{
	int i;
	FILE *fsrc,*fdest;
	if(argc!=3)
	{
		printf("Improper number of arguments\n");
		exit(0);
	}
	fsrc=fopen(argv[1],"r");
	fdest=fopen(argv[2],"w");
	macro_replace(fsrc,fdest);
	printf("macro identifier is replaced with token sequence\n");
	printf("Open the output file\n");
}