4 #include <stdint.h> // for intptr_t
10 #define YYSTYPE tree_ptr
11 void yyerror(const char *s
);
17 extern
int option_easy
;
24 %token LPAR RPAR LSQU RSQU LBRACE RBRACE COMMA
26 %left EQ NE LT T_GT LE GE
33 %token END
0 "end of file"
37 | input stmt
{ tree_eval_stmt
($2); }
42 | DEFINE ID LPAR parms RPAR LBRACE stmtlist RBRACE
{
43 $$
= tree_new_define
($2, $4, $7);
48 : { $$
= tree_new_empty_stmt_list
(); } // Empty.
49 | stmtlist stmt
{ tree_append
($1, $2); }
53 : { $$
= tree_new_empty_parms
(); } // Empty.
58 : ID
{ $$
= tree_new_empty_parms
(); tree_append
($$
, $1); }
59 | parms1 COMMA ID
{ tree_append
($1, $3); }
64 | ID ASSIGN expr
{ $$
= tree_new_assign
($1, $3); }
65 | expr QUESTION expr COLON expr
{ $$
= tree_new_ternary
($1, $3, $5); }
67 | molecule LSQU expr RSQU
{ $$
= tree_new_item
($1, $3); }
68 | expr EQ expr
{ $$
= tree_new_eq
($1, $3); }
69 | expr NE expr
{ $$
= tree_new_ne
($1, $3); }
70 | expr LE expr
{ $$
= tree_new_le
($1, $3); }
71 | expr GE expr
{ $$
= tree_new_ge
($1, $3); }
72 | expr LT expr
{ $$
= tree_new_lt
($1, $3); }
73 | expr T_GT expr
{ $$
= tree_new_gt
($1, $3); }
74 | expr PLUS expr
{ $$
= tree_new_add
($1, $3); }
75 | expr MINUS expr
{ $$
= tree_new_sub
($1, $3); }
76 | expr TIMES expr
{ $$
= tree_new_mul
($1, $3); }
77 | expr DIVIDE expr
{ $$
= tree_new_div
($1, $3); }
78 | expr POW expr
{ $$
= tree_new_pow
($1, $3); }
79 | MINUS expr %prec UMINUS
{ $$
= tree_new_neg
($2); }
84 : molecule LPAR exprlist RPAR
{ $$
= $3; tree_set_fun
($$
, $1); }
85 | LPAR expr RPAR
{ $$
= $2; }
90 : { $$
= tree_new_funcall
(); } // Empty.
95 : expr
{ tree_append
($$
= tree_new_funcall
(), $1); }
96 | nonemptyexprlist COMMA expr
{ tree_append
($1, $3); }
105 : LSQU sequence RSQU
{ $$
= $2; }
109 : expr
{ $$
= tree_new_list
($1); }
110 | sequence COMMA expr
{ tree_append
($1, $3); }