create picrin objects in parser stage, not in scan stage
This commit is contained in:
		
							parent
							
								
									397a6b5473
								
							
						
					
					
						commit
						94e1e245ea
					
				
							
								
								
									
										29
									
								
								src/parse.y
								
								
								
								
							
							
						
						
									
										29
									
								
								src/parse.y
								
								
								
								
							|  | @ -31,12 +31,17 @@ void yylex_destroy(); | ||||||
| %lex-param {struct parser_control *p} | %lex-param {struct parser_control *p} | ||||||
| 
 | 
 | ||||||
| %union { | %union { | ||||||
|  |   int i; | ||||||
|  |   double f; | ||||||
|  |   char *cstr; | ||||||
|   pic_value datum; |   pic_value datum; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| %token tLPAREN tRPAREN tDOT | %token tLPAREN tRPAREN tDOT | ||||||
| %token tQUOTE tQUASIQUOTE tUNQUOTE tUNQUOTE_SPLICING | %token tQUOTE tQUASIQUOTE tUNQUOTE tUNQUOTE_SPLICING | ||||||
| %token <datum> tSYMBOL tNUMBER tBOOLEAN tSTRING | %token <i> tINT tBOOLEAN | ||||||
|  | %token <f> tFLOAT | ||||||
|  | %token <cstr> tSYMBOL tSTRING | ||||||
| 
 | 
 | ||||||
| %type <datum> program_data | %type <datum> program_data | ||||||
| %type <datum> datum simple_datum compound_datum abbrev | %type <datum> datum simple_datum compound_datum abbrev | ||||||
|  | @ -86,9 +91,27 @@ datum | ||||||
| 
 | 
 | ||||||
| simple_datum | simple_datum | ||||||
| 	: tSYMBOL | 	: tSYMBOL | ||||||
| 	| tNUMBER | 	{ | ||||||
| 	| tBOOLEAN | 	  $$ = pic_intern_cstr(p->pic, $1); | ||||||
|  | 	  free($1); | ||||||
|  | 	} | ||||||
| 	| tSTRING | 	| tSTRING | ||||||
|  | 	{ | ||||||
|  | 	  $$ = pic_str_new_cstr(p->pic, $1); | ||||||
|  | 	  free($1); | ||||||
|  | 	} | ||||||
|  | 	| tINT | ||||||
|  | 	{ | ||||||
|  | 	  $$ = pic_int_value($1); | ||||||
|  | 	} | ||||||
|  | 	| tFLOAT | ||||||
|  | 	{ | ||||||
|  | 	  $$ = pic_float_value($1); | ||||||
|  | 	} | ||||||
|  | 	| tBOOLEAN | ||||||
|  | 	{ | ||||||
|  | 	  $$ = pic_bool_value($1); | ||||||
|  | 	} | ||||||
| ; | ; | ||||||
| 
 | 
 | ||||||
| compound_datum | compound_datum | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								src/scan.l
								
								
								
								
							
							
						
						
									
										28
									
								
								src/scan.l
								
								
								
								
							|  | @ -47,6 +47,7 @@ infnan		"+inf.0"|"-inf.0"|"+nan.0"|"-nan.0" | ||||||
| 
 | 
 | ||||||
| [ \t\n\r]	/* skip whitespace */ | [ \t\n\r]	/* skip whitespace */ | ||||||
| {comment}	/* skip comment */ | {comment}	/* skip comment */ | ||||||
|  | 
 | ||||||
| "."		return tDOT; | "."		return tDOT; | ||||||
| "("		return tLPAREN; | "("		return tLPAREN; | ||||||
| ")"		return tRPAREN; | ")"		return tRPAREN; | ||||||
|  | @ -54,17 +55,34 @@ infnan		"+inf.0"|"-inf.0"|"+nan.0"|"-nan.0" | ||||||
| "`"		return tQUASIQUOTE; | "`"		return tQUASIQUOTE; | ||||||
| ","		return tUNQUOTE; | ","		return tUNQUOTE; | ||||||
| ",@"		return tUNQUOTE_SPLICING; | ",@"		return tUNQUOTE_SPLICING; | ||||||
| {boolean}	{ yylvalp->datum = pic_bool_value(strcmp(yytext, "#t") == 0 || strcmp(yytext, "#true") == 0); return tBOOLEAN; } | 
 | ||||||
| {integer}	{ yylvalp->datum = pic_int_value(atoi(yytext)); return tNUMBER; } | {boolean}	{ | ||||||
| {real} 		{ yylvalp->datum = pic_float_value(atof(yytext)); return tNUMBER; } |   yylvalp->i = (yytext[1] == 't'); | ||||||
| {identifier}	{ yylvalp->datum = pic_intern_cstr(p->pic, yytext); return tSYMBOL; } |   return tBOOLEAN; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | {integer}	{ | ||||||
|  |   yylvalp->i = atoi(yytext); | ||||||
|  |   return tINT; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | {real} 		{ | ||||||
|  |   yylvalp->f = atof(yytext); | ||||||
|  |   return tFLOAT; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | {identifier}	{ | ||||||
|  |   yylvalp->cstr = strdup(yytext); | ||||||
|  |   return tSYMBOL; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| "\""		BEGIN(STRING); | "\""		BEGIN(STRING); | ||||||
| <STRING>{ | <STRING>{ | ||||||
| 	[^\\"]*		yymore(); | 	[^\\"]*		yymore(); | ||||||
| 	<<EOF>>		{ yyerror(p, "eof in string"); BEGIN(INITIAL); } | 	<<EOF>>		{ yyerror(p, "eof in string"); BEGIN(INITIAL); } | ||||||
| 	"\""		{ | 	"\""		{ | ||||||
| 			  yytext[yyleng-1] = '\0'; | 			  yytext[yyleng-1] = '\0'; | ||||||
| 			  yylvalp->datum = pic_str_new_cstr(p->pic, yytext); | 			  yylvalp->cstr = strdup(yytext); | ||||||
| 			  BEGIN(INITIAL); | 			  BEGIN(INITIAL); | ||||||
| 			  return tSTRING; | 			  return tSTRING; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Yuichi Nishiwaki
						Yuichi Nishiwaki