Previous: , Up: Multi-function Calc   [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[])
{
  int i;
  /* Enable parse traces on option -p.  */
  for (i = 1; i < argc; ++i)
    if (!strcmp(argv[i], "-p"))
      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.