Package org.woped.metrics.formalGrammar

Examples of org.woped.metrics.formalGrammar.metricsGrammarParser


      throws CalculateFormulaException {
    try {
      CharStream stream = new ANTLRStringStream(formula);
      metricsGrammarLexer lexer = new metricsGrammarLexer(stream);
      TokenStream tokenStream = new CommonTokenStream(lexer);
      metricsGrammarParser parser = new metricsGrammarParser(tokenStream,
          mc, stack, doNotDisplay, syntaxCheck);
      return parser.evaluator();
    } catch (RecognitionException re) {
      //This Exception will only be thrown if there is a general Error like a letter which is not allowed
      return caughtRecognitionException(re, formula, mc, stack,
          doNotDisplay, syntaxCheck);
    } catch (FormulaVariableNotFoundException fvnfe) {
View Full Code Here


    // the math framework is correct
    formula = mathToLowerCase(formula);
    CharStream stream = new ANTLRStringStream(formula);
    metricsGrammarLexer lexer = new metricsGrammarLexer(stream);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    metricsGrammarParser parser = new metricsGrammarParser(tokenStream, mc,
        stack, doNotDisplay, syntaxCheck);
    try {
      double value = parser.evaluator();
      // The new Formula worked well. The user should be informed
      // that he should chance the formula. Therefore we throw a EnhancementException.
      // We have to find the ID of the formula
      throw new EnhancementException(formula, value);
    } catch (RecognitionException e2) {
View Full Code Here

    // the math framework is correct
    formula = mathToLowerCase(formula);
    CharStream stream = new ANTLRStringStream(formula);
    metricsGrammarLexer lexer = new metricsGrammarLexer(stream);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    metricsGrammarParser parser = new metricsGrammarParser(tokenStream, mc,
        stack, doNotDisplay, syntaxCheck);
    try {
      double value = parser.evaluator();
      // The new Formula worked well. The user should be informed
      // that he should chance the formula. Therefore we throw a EnhancementException.
      // We have to find the ID of the formula
      throw new EnhancementException(formula, value);
    } catch (FormulaVariableNotFoundException fvnfe) {
View Full Code Here

     
    }   
    CharStream stream = new ANTLRStringStream(formula);
    metricsGrammarLexer lexer = new metricsGrammarLexer(stream);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    metricsGrammarParser parser = new metricsGrammarParser(tokenStream, mc,
        stack, doNotDisplay, syntaxCheck);
    try {
      parser.evaluator();
    }catch(NestedCalculateFormulaException ncfe2){
      ArrayList<FormulaVariableNotFoundException> newList = ncfe2.getFormulaVariableNotFoundExceptions();
      for(FormulaVariableNotFoundException fvnfe: newList){
        String variable = fvnfe.getVariable();
        if(variablelist.containsKey(variable)){
View Full Code Here

    int maxTries = 10;
    // Get actual Errors
    CharStream stream = new ANTLRStringStream(formula);
    metricsGrammarLexer lexer = new metricsGrammarLexer(stream);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    metricsGrammarParser parser = new metricsGrammarParser(tokenStream, mc,
        stack, doNotDisplay, syntaxCheck);
    try {
      parser.evaluator();
    } catch (NestedCalculateFormulaException ncfe) {

      ArrayList<MismatchedTokenException> oldList = ncfe
          .getMismatchedTokenExceptions();
      ArrayList<String> missingChar = new ArrayList<String>();
      int numberOfItemsStart;
      int numberOfItemsEnd;

      do {
        maxTries--;
        numberOfItemsStart = missingChar.size();

        for (MismatchedTokenException mmte : oldList) {
          if (mmte.c == Token.EOF) {
            try {
              if (AntlrException.getTokenList()[mmte.expecting]
                  .equals("')'")) {
                formula = formula + ")";
                missingChar.add(")");
              }
            } catch (ArrayIndexOutOfBoundsException aioob) {

            }
          }
        }

        CharStream stream2 = new ANTLRStringStream(formula);
        metricsGrammarLexer lexer2 = new metricsGrammarLexer(stream2);
        TokenStream tokenStream2 = new CommonTokenStream(lexer2);
        metricsGrammarParser parser2 = new metricsGrammarParser(
            tokenStream2, mc, stack, doNotDisplay, syntaxCheck);
        try {
          parser2.evaluator();
          oldList.clear();
        } catch (NestedCalculateFormulaException ncfe2) {
          oldList = ncfe2  .getMismatchedTokenExceptions();
        } catch (Exception e) {
          throw ncfeOriginal;
View Full Code Here

TOP

Related Classes of org.woped.metrics.formalGrammar.metricsGrammarParser

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.