Package fri.util

Examples of fri.util.TimeStopper


      if (ignoredSymbols == null)
        ignoredSymbols = separation.getIgnoredSymbols();
    }
    // else: assume that syntaxInput is a prebuilt lexer Syntax and a list of ignored tokens
   
    TimeStopper ts = new TimeStopper();
    LexerBuilder builder = newLexerBuilder(syntax, ignoredSymbols);
    Lexer lexer = builder.getLexer();
    lexer.setTerminals(tokenSymbols);
    System.err.println("Lexer scratch construction took "+ts.getTimeMillis()+" millis");
   
    if (PRODUCTION)
      write(ensureFileName(syntaxInput, baseName), lexer);

    return lexer;
View Full Code Here



  /** Test main. Building serialized Lexer takes 330, building from scratch takes 130 millis. */
  public static void main(String [] args)  {
    try  {
      TimeStopper ts = new TimeStopper();
      Lexer lexer = new SerializedLexer().get(StandardLexerRules.lexerSyntax, "SyntaxBuilder");
      System.err.println("Lexer was built in "+ts.getTimeMillis()+" millis");
    }
    catch (Exception e)  {
      e.printStackTrace();
    }
  }
View Full Code Here

    if (args.length <= 0)  {
      System.err.println("SYNTAX: java "+JavaParser.class.getName()+" file.java [file.java ...]");
      System.err.println("  Example Java Parser");
    }
    else  {
      TimeStopper timer = new TimeStopper();

      // read the syntax from EBNF file
      Reader syntaxInput = new InputStreamReader(JavaParser.class.getResourceAsStream("Java.syntax"));
     
      /* building from scratch, takes 4200 millis
      SyntaxBuilder builder = new SyntaxBuilder(syntaxInput);
      Lexer lexer = builder.getLexer();
      lexer.setDebug(true);
      ParserTables tables = new LALRParserTables(builder.getParserSyntax());
      Parser parser = new Parser(tables);
      parser.setLexer(lexer);
      */
     
      /* building with precompiled tables, takes 1600 millis
      SyntaxBuilder builder = new SyntaxBuilder(syntaxInput);
      Lexer lexer = builder.getLexer();
      ParserTables tables = new CompiledTables().get(builder.getParserSyntax(), "Java");
      Parser parser = new Parser(tables);
      parser.setLexer(lexer);
      */
     
      /* building serialized parser, takes 740 millis */
      Parser parser = new SerializedParser().get(null, syntaxInput, "Java");
      System.err.println("time to build Java file parser was "+timer.getInterval());

      //parser.getParserTables().dumpSyntaxNodes(System.out);
      //parser.getParserTables().dump(System.err);
     
      // we want to receive Java comments and spaces/newlines
      parser.getLexer().addTokenListener(new Lexer.TokenListener()  {
        public void tokenReceived(Token token, boolean ignored) {
          if (ignored)  {
            System.err.println("------------- Ignored Token Received -------------------");
            System.err.println(token.text);
            System.err.println("--------------------------------------------------------");
          }
        }
      });

      for (int i = 0; i < args.length; i++)  {
        String fileToParse = args[i];
        FileReader parseInput = new FileReader(fileToParse);
        System.err.println("========================================================");
        System.err.println("Parsing: "+fileToParse);

        parser.setInput(parseInput)// set file input to lexer
        boolean ok = parser.parse(new PrintSemantic())// parse input

        System.err.println("========================================================");
        System.err.println("Parsing result from "+fileToParse+" is: "+ok+", parsing took "+timer.getInterval()+" millis");
      }
    }
  }
View Full Code Here

      System.err.println("SYNTAX: java "+DtdLexer.class.getName()+" file.dtd [file.dtd ...]");
      System.err.println("  Example DTD Parser");
      System.exit(1);
    }

    TimeStopper timer = new TimeStopper();

    SerializedLexer builder = new SerializedLexer();
    LexerImpl lexer;
   
    if ((lexer = (LexerImpl) builder.readLexer(null, "Dtd")) == null)  {  // try to get serialized lexer
      // read the DTD syntax (fragment) from EBNF file
      Syntax dtdSyntax = new SyntaxBuilder(new InputStreamReader(DtdLexer.class.getResourceAsStream("Dtd.syntax"))).getSyntax();
      // read the XML syntax from EBNF file
      Syntax xmlSyntax = new SyntaxBuilder(new InputStreamReader(DtdLexer.class.getResourceAsStream("Xml.syntax"))).getSyntax();
     
      // resolve DTD syntax from XML syntax (which contains most of DTD rules for processing embedded DTDs)
      dtdSyntax.resolveFrom(xmlSyntax);
      //System.err.println("DTD Syntax is:\n"+dtdSyntax);
     
      // put the lexer to file cache for next call
      SyntaxSeparation separation = new SyntaxSeparation(dtdSyntax);
      lexer = (LexerImpl) builder.buildAndStoreLexer// store the lexer for next call
          separation.getLexerSyntax(),
          "Dtd",
          separation.getTokenSymbols(),
          separation.getIgnoredSymbols());
    }

    System.err.println("time to build DTD file parser was "+timer.getInterval());

    for (int i = 0; i < args.length; i++)  {
      String parseFile = args[i];
      FileReader parseInput = new FileReader(parseFile);
      lexer.setInput(parseInput);
     
      System.err.println("======================== Parsing: "+parseFile+" ========================");
      boolean ok = lexer.lex(new XmlLexer.PrintXmlLexerSemantic());
      System.err.println("========================================================");
     
      System.err.println("Lexing took "+timer.getInterval()+" millis.");
      System.err.println("Result was: "+ok);
    }
  }
View Full Code Here

      System.err.println("  Example XML Parser");
      System.exit(1);
    }

    // Standalone lexer as top-down parser.
    TimeStopper timer = new TimeStopper();
    // Building lexer from scratch takes 840 millis. Parsing takes 60 millis for a 70 line XML file.

    // read the syntax from EBNF file
    Reader syntaxInput = new InputStreamReader(XmlLexer.class.getResourceAsStream("Xml.syntax"));
    boolean PRODUCTION = false// always build from scratch at development time
    LexerImpl lexer = (LexerImpl) new SerializedLexer(PRODUCTION).get(syntaxInput, "Xml");

    System.err.println("time to build XML file parser was "+timer.getInterval());

    for (int i = 0; i < args.length; i++)  {
      String parseFile = args[i];
      Reader parseInput = new UnicodeReader(new FileInputStream(parseFile));
      lexer.setInput(parseInput);
     
      System.err.println("======================== Parsing: "+parseFile+" ========================");
      boolean result = lexer.lex(new PrintXmlLexerSemantic());
      System.err.println("========================================================");
     
      System.err.println("Lexing took "+timer.getInterval()+" millis.");
      System.err.println("Result was: "+result);
    }
  }
View Full Code Here

TOP

Related Classes of fri.util.TimeStopper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.