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} | ||||
| 
 | ||||
| %union { | ||||
|   int i; | ||||
|   double f; | ||||
|   char *cstr; | ||||
|   pic_value datum; | ||||
| } | ||||
| 
 | ||||
| %token tLPAREN tRPAREN tDOT | ||||
| %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> datum simple_datum compound_datum abbrev | ||||
|  | @ -86,9 +91,27 @@ datum | |||
| 
 | ||||
| simple_datum | ||||
| 	: tSYMBOL | ||||
| 	| tNUMBER | ||||
| 	| tBOOLEAN | ||||
| 	{ | ||||
| 	  $$ = pic_intern_cstr(p->pic, $1); | ||||
| 	  free($1); | ||||
| 	} | ||||
| 	| 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 | ||||
|  |  | |||
							
								
								
									
										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 */ | ||||
| {comment}	/* skip comment */ | ||||
| 
 | ||||
| "."		return tDOT; | ||||
| "("		return tLPAREN; | ||||
| ")"		return tRPAREN; | ||||
|  | @ -54,17 +55,34 @@ infnan		"+inf.0"|"-inf.0"|"+nan.0"|"-nan.0" | |||
| "`"		return tQUASIQUOTE; | ||||
| ","		return tUNQUOTE; | ||||
| ",@"		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; } | ||||
| {real} 		{ yylvalp->datum = pic_float_value(atof(yytext)); return tNUMBER; } | ||||
| {identifier}	{ yylvalp->datum = pic_intern_cstr(p->pic, yytext); return tSYMBOL; } | ||||
| 
 | ||||
| {boolean}	{ | ||||
|   yylvalp->i = (yytext[1] == 't'); | ||||
|   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); | ||||
| <STRING>{ | ||||
| 	[^\\"]*		yymore(); | ||||
| 	<<EOF>>		{ yyerror(p, "eof in string"); BEGIN(INITIAL); } | ||||
| 	"\""		{ | ||||
| 			  yytext[yyleng-1] = '\0'; | ||||
| 			  yylvalp->datum = pic_str_new_cstr(p->pic, yytext); | ||||
| 			  yylvalp->cstr = strdup(yytext); | ||||
| 			  BEGIN(INITIAL); | ||||
| 			  return tSTRING; | ||||
| 			} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Yuichi Nishiwaki
						Yuichi Nishiwaki