parse int values
This commit is contained in:
+15
-2
@@ -21,10 +21,10 @@ struct parser_control {
|
||||
}
|
||||
|
||||
%token tLPAREN tRPAREN tDOT
|
||||
%token <datum> tSYMBOL
|
||||
%token <datum> tSYMBOL tINT
|
||||
|
||||
%type <datum> datum simple_datum symbol compound_datum
|
||||
%type <datum> list list_tail
|
||||
%type <datum> 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);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
%{
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; }
|
||||
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user