From 2ee11a367f6b4942a55a86aa24f92a4d798c9cc2 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 12 Oct 2013 12:07:28 +0900 Subject: [PATCH] parse int values --- src/parse.y | 17 +++++++++++++++-- src/scan.l | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/parse.y b/src/parse.y index c8cb37c1..75cc11a1 100644 --- a/src/parse.y +++ b/src/parse.y @@ -21,10 +21,10 @@ struct parser_control { } %token tLPAREN tRPAREN tDOT -%token tSYMBOL +%token tSYMBOL tINT %type datum simple_datum symbol compound_datum -%type list list_tail +%type number integer list list_tail %% @@ -46,6 +46,7 @@ datum simple_datum : symbol + | number ; symbol @@ -55,6 +56,17 @@ symbol } ; +number + : integer +; + +integer + : tINT + { + $$ = $1; + } +; + compound_datum : list ; @@ -96,6 +108,7 @@ pic_parse(pic_state *pic, const char *str) struct parser_control p; p.pic = pic; + p.value = pic_int_value(42); yy_scan_string(str); yyparse(&p); diff --git a/src/scan.l b/src/scan.l index 27416a63..ddf32b28 100644 --- a/src/scan.l +++ b/src/scan.l @@ -1,4 +1,6 @@ %{ +#include + #include "picrin.h" #include "y.tab.h" @@ -14,6 +16,7 @@ struct parser_control { "(" return tLPAREN; ")" return tRPAREN; +[1-9][0-9]* { yylval.datum = pic_int_value(atoi(yytext)); return tINT; } [a-z0-9A-Z]+ { yylval.datum = pic_intern_cstr(p->pic, yytext); return tSYMBOL; } %%