


/************************/
/*   generated          */



//default define
#ifndef __STDIO_H__
	#include <stdio.h>
#endif
#ifndef __STDLIB_H__
	#include <stdlib.h>
#endif
#ifndef __STRING_H__
	#include <string.h>
#endif
//

// default setting
#define BUFFER_SIZE 512
#define TOKEN_SIZE 512
#define PG_EXIT_SCAN 0
//
// pg_ variables //
char pg_buffer[BUFFER_SIZE];
char* pg_head=0;
char* pg_prev;
char pg_token[TOKEN_SIZE];
char* pg_save;
FILE* pg_input=0;
int pg_line=0;
// pg_ variables //
//



// generate by regex 0:  '\+|\*|-|/'
int R0_match(){

R0_ST0: 
	switch(*pg_head){
		case 0: goto R0_EXIT0;
		case 42: pg_head++; goto R0_ST1;
		case 43: pg_head++; goto R0_ST2;
		case 45: pg_head++; goto R0_ST3;
		case 47: pg_head++; goto R0_ST4;
		default:
	R0_EXIT0: 
	return 0;
	}
R0_ST1: //final
	switch(*pg_head){
		case 0: goto R0_EXIT1;
		default:
	R0_EXIT1: 
	return 1;
	}
R0_ST2: //final
	switch(*pg_head){
		case 0: goto R0_EXIT2;
		default:
	R0_EXIT2: 
	return 1;
	}
R0_ST3: //final
	switch(*pg_head){
		case 0: goto R0_EXIT3;
		default:
	R0_EXIT3: 
	return 1;
	}
R0_ST4: //final
	switch(*pg_head){
		case 0: goto R0_EXIT4;
		default:
	R0_EXIT4: 
	return 1;
	}

}
// ------------------------ //

// generate by regex 1:  '[0-9]+'
int R1_match(){

R1_ST0: 
	switch(*pg_head){
		case 0: goto R1_EXIT0;
		case 48: pg_head++; goto R1_ST1;
		case 57: pg_head++; goto R1_ST1;
		default:
		if(49<=*pg_head && *pg_head<=56){
			pg_head++; goto R1_ST1;
		}
	R1_EXIT0: 
	return 0;
	}
R1_ST1: //final
	switch(*pg_head){
		case 0: goto R1_EXIT1;
		case 48: pg_head++; goto R1_ST1;
		case 57: pg_head++; goto R1_ST1;
		default:
		if(49<=*pg_head && *pg_head<=56){
			pg_head++; goto R1_ST1;
		}
	R1_EXIT1: 
	return 1;
	}

}
// ------------------------ //

// generate by regex 2:  '(\n|\s|\t)+'
int R2_match(){

R2_ST0: 
	switch(*pg_head){
		case 0: goto R2_EXIT0;
		case 9: pg_head++; goto R2_ST1;
		case 10: pg_head++; goto R2_ST2;
		case 32: pg_head++; goto R2_ST3;
		default:
	R2_EXIT0: 
	return 0;
	}
R2_ST1: //final
	switch(*pg_head){
		case 0: goto R2_EXIT1;
		case 9: pg_head++; goto R2_ST1;
		case 10: pg_head++; goto R2_ST2;
		case 32: pg_head++; goto R2_ST3;
		default:
	R2_EXIT1: 
	return 1;
	}
R2_ST2: //final
	switch(*pg_head){
		case 0: goto R2_EXIT2;
		case 9: pg_head++; goto R2_ST1;
		case 10: pg_head++; goto R2_ST2;
		case 32: pg_head++; goto R2_ST3;
		default:
	R2_EXIT2: 
	return 1;
	}
R2_ST3: //final
	switch(*pg_head){
		case 0: goto R2_EXIT3;
		case 9: pg_head++; goto R2_ST1;
		case 10: pg_head++; goto R2_ST2;
		case 32: pg_head++; goto R2_ST3;
		default:
	R2_EXIT3: 
	return 1;
	}

}
// ------------------------ //

int update_token(int size){
	int i;
	for(i=0;i<size; i++){
		pg_token[i]=*pg_head++;
	}
	pg_token[i]=0;
}
int pg_lex(){
	int pg_sel,pg_rec,pg_i;
	int (*pg_rex_funcs[3])()={
		R0_match,
		R1_match,
		R2_match
	};
	if(!pg_input)pg_input = stdin;
	if(!pg_head)pg_head = pg_buffer;
	while(1){pg_sel=-1,pg_rec=-1;
		if(!*pg_head){
			if(fgets(pg_buffer,BUFFER_SIZE,pg_input)!=NULL){
				pg_head = pg_buffer; pg_line++;
			}else{
				return PG_EXIT_SCAN;
			}
		}
		//matching
		for(pg_i=0;pg_i<3;pg_i++){
			pg_prev=pg_head;//save
			if(pg_rex_funcs[pg_i]()){
				if(pg_rec<pg_head-pg_prev){
					pg_sel=pg_i;
					pg_rec=pg_head-pg_prev;
				}
			}
			pg_head=pg_prev;//repair
		}
		//no match
		if(pg_sel==-1){
			puts("[error] not matched");exit(1);
		}
		//token update
		for(pg_i=0;pg_i<pg_rec; pg_i++){
			pg_token[pg_i]=*pg_head++;
		}
		pg_token[pg_i]=0;
		//run usr code
		switch(pg_sel){
			case 0:
			/* usr code */
 printf("operator: %s\n", pg_token);
			/* usr code */
			break;

			case 1:
			/* usr code */
 printf("digit token: %s\n", pg_token);
			/* usr code */
			break;

			case 2:
			/* usr code */
 // skip
			/* usr code */
			break;

		}
		pg_head=pg_prev+pg_rec;
	}
}
/*   generated          */
/************************/


int main(void)
{
	pg_lex();
	return 0;
}
