Next: The mfcalc
Symbol Table, Previous: Declarations for mfcalc
, Up: Multi-Function Calculator: mfcalc
[Contents][Index]
mfcalc
Here 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. */ %%