Logo Search packages:      
Sourcecode: jflex version File versions

static void JFlex::Main::generate ( File  inputFile  )  [inline, static]

Generates a scanner for the specified input file.

Parameters:
inputFile a file containing a lexical specification to generate a scanner for.

Definition at line 67 of file Main.java.

References JFlex::DFA::checkActions(), JFlex::ScannerException::column, JFlex::Emitter::emit(), JFlex::ScannerException::file, JFlex::NFA::getDFA(), JFlex::ScannerException::line, JFlex::ScannerException::message, JFlex::DFA::minimize(), JFlex::NFA::numStates, JFlex::Timer::start(), JFlex::Timer::stop(), JFlex::DFA::writeDot(), and JFlex::NFA::writeDot().

Referenced by main().

                                              {

    Out.resetCounters();

    Timer totalTime = new Timer();
    Timer time      = new Timer();
      
    LexScan scanner = null;
    LexParse parser = null;
    FileReader inputReader = null;
    
    totalTime.start();      

    try {  
      Out.println("Reading \""+inputFile+"\"");
      inputReader = new FileReader(inputFile);
      scanner = new LexScan(inputReader);
      scanner.setFile(inputFile);
      parser = new LexParse(scanner);
    }
    catch (FileNotFoundException e) {
      Out.error("Sorry, couldn't find the file \""+inputFile+"\"");
      throw new GeneratorException();
    }
    catch (IOException e) {
      Out.error("Sorry, error opening input file \""+inputFile+"\"");
      throw new GeneratorException();
    }
      
    try {  
      NFA nfa = (NFA) parser.parse().value;      

      Out.checkErrors();

      if (Out.DUMP) Out.dump("NFA is"+Out.NL+nfa+Out.NL);
      
      if (Out.DOT) 
        nfa.writeDot(Emitter.normalize("nfa.dot", null, null));      

      Out.println(nfa.numStates+" states in NFA");
      
      time.start();
      DFA dfa = nfa.getDFA();
      time.stop();
      Out.time("DFA construction took "+time);

      dfa.checkActions(scanner, parser);

      nfa = null;

      if (Out.DUMP) Out.dump("DFA is"+Out.NL+dfa+Out.NL);      

      if (Out.DOT) 
        dfa.writeDot(Emitter.normalize("dfa-big.dot", null, null));

      time.start();
      dfa.minimize();
      time.stop();

      Out.time("Minimization took "+time);
      
      if (Out.DUMP) Out.dump("Miniminal DFA is"+Out.NL+dfa);

      if (Out.DOT) 
        dfa.writeDot(Emitter.normalize("dfa-min.dot", null, null));

      time.start();
      
      Emitter e = new Emitter(inputFile, parser, dfa);
      e.emit();

      time.stop();

      Out.time("Writing took "+time);
      
      totalTime.stop();
      
      Out.time("Overall scanner generation time : "+totalTime);
    }
    catch (ScannerException e) {
      Out.error(e.file, e.message, e.line, e.column);
      throw new GeneratorException();
    }
    catch (MacroException e) {
      Out.error(e.getMessage());
      throw new GeneratorException();
    }
    catch (IOException e) {
      Out.error("An I/O-Error occured : "+e);
      throw new GeneratorException();
    }
    catch (OutOfMemoryError e) {
      Out.error(OUT_OF_MEMORY);
      throw new GeneratorException();
    }
    catch (GeneratorException e) {
      throw new GeneratorException();
    }
    catch (Exception e) {
      e.printStackTrace();
      throw new GeneratorException();
    }

  }


Generated by  Doxygen 1.6.0   Back to index