Previous: , Up: Multi-Function Calculator: mfcalc   [Contents][Index]


2.5.5 The mfcalc Main

The error reporting function is unchanged, and the new version of main includes a call to init_table and sets the yydebug on user demand (See Tracing Your Parser, for details):

/* Called by yyparse on error. */
void yyerror (char const *s)
{
  fprintf (stderr, "%s\n", s);
}

int main (int argc, char const* argv[])
{
  /* Enable parse traces on option -p. */
  if (argc == 2 && strcmp(argv[1], "-p") == 0)
    yydebug = 1;
  init_table ();
  return yyparse ();
}

This program is both powerful and flexible. You may easily add new functions, and it is a simple job to modify this code to install predefined variables such as pi or e as well.