code: def generate(inputfilename, outputfilename='', dump=0, **flags):
      
  
      if not outputfilename:
          if inputfilename[-2:] == '.g':
              outputfilename = inputfilename[:-2] + '.py'
          else:
              raise Exception("Missing output filename")
  
      print 'Input Grammar:', inputfilename
      print 'Output File:', outputfilename
  
      DIVIDER = '\n%%\n'  # This pattern separates the pre/post parsers
      preparser, postparser = None, None  # Code before and after the parser desc
  
      # Read the entire file
      s = open(inputfilename, 'r').read()
  
      # See if there's a separation between the pre-parser and parser
      f = find(s, DIVIDER)
      if f >= 0:
          preparser, s = s[:f] + '\n\n', s[f + len(DIVIDER):]
  
      # See if there's a separation between the parser and post-parser
      f = find(s, DIVIDER)
      if f >= 0:
          s, postparser = s[:f], '\n\n' + s[f + len(DIVIDER):]
  
      # Create the parser and scanner
      p = ParserDescription(ParserDescriptionScanner(s))
      if not p:
          return
  
      # Now parse the file
      t = wrap_error_reporter(p, 'Parser')
      if not t:
          return  # Error
      if preparser is not None:
          t.preparser = preparser
      if postparser is not None:
          t.postparser = postparser
  
      # Check the options
      for f in t.options.keys():
          for opt, _, _ in yapps_options:
              if f == opt:
                  break
          else:
              print 'Warning: unrecognized option', f
      # Add command line options to the set
      for f in flags.keys():
          t.options[f] = flags[f]
  
      # Generate the output
      if dump:
          t.dump_information()
      else:
          t.output = open(outputfilename, 'w')
          t.generate_output()
docs: Generate a grammar, given an input filename (X.g)
      and an output filename (defaulting to X.py).