Next: The mfcalc Symbol Table, Previous: Declarations for mfcalc, Up: Multi-Function Calculator: mfcalc [Contents][Index]
mfcalcHere are the grammar rules for the multi-function calculator.
Most of them are copied directly from calc; three rules,
those which mention VAR or FUN, are new.
%% /* The grammar follows. */
input: %empty | input line ;
line:
'\n'
| exp '\n' { printf ("%.10g\n", 1ドル); }
| error '\n' { yyerrok; }
;
exp:
NUM
| VAR { $$ = 1ドル->value.var; }
| VAR '=' exp { $$ = 3ドル; 1ドル->value.var = 3ドル; }
| FUN '(' exp ')' { $$ = 1ドル->value.fun (3ドル); }
| exp '+' exp { $$ = 1ドル + 3ドル; }
| exp '-' exp { $$ = 1ドル - 3ドル; }
| exp '*' exp { $$ = 1ドル * 3ドル; }
| exp '/' exp { $$ = 1ドル / 3ドル; }
| '-' exp %prec NEG { $$ = -2ドル; }
| exp '^' exp { $$ = pow (1,ドル 3ドル); }
| '(' exp ')' { $$ = 2ドル; }
;
/* End of grammar. */ %%