Example usage for jdk.nashorn.internal.runtime.regexp.joni.exception SyntaxException SyntaxException

List of usage examples for jdk.nashorn.internal.runtime.regexp.joni.exception SyntaxException SyntaxException

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime.regexp.joni.exception SyntaxException SyntaxException.

Prototype

public SyntaxException(final String message) 

Source Link

Usage

From source file:com.fmi.dsa.cfg.cli_calculator.CliCalculator.java

private int evaluateFactor() throws SyntaxException {
    int numberValue = 0;

    if (terminal.peek() == 'N') {
        numberValue = terminalValues.pop();
        terminal.pop();/*from   w w w.j a v  a 2 s .c o  m*/
    } else if (terminal.peek() == ')') {
        terminal.pop();
        numberValue = evaluateExpression();
        if (terminal.peek() == '(') {
            terminal.pop();
        } else {
            ro.displayResult("Syntax Error");
            throw new SyntaxException("Syntax Error!");
        }
    } else {
        ro.displayResult("Syntax Error");
        throw new SyntaxException("Syntax Error!");
    }

    if (terminal.peek() == '-' && terminal.get(terminal.size() - 2) != 'N'
            && terminal.get(terminal.size() - 2) != ')') {
        terminal.pop();
        return -numberValue;
    }
    return numberValue;
}

From source file:com.mycompany.cse222_hw04_091044011_ercanuca_2016.InfixToPostfix.java

/**
 * Exracts and processes each token in infix and returns the equivalent
 * postfix string.//from w ww  . j  a  va2s.  c o m
 *
 * @param infix is token take from file
 * @return the equivalent postfix string 
 * throws com.mycompany.cse222_hw04_091044011_ercanuca_2016.InfixToPostfix.SyntaxErrorException
 */
public String convert(String infix) {
    operandStack = new Stack<>();
    postfix = new StringBuilder();
    StringTokenizer infixToken = new StringTokenizer(infix);
    try {
        // process each token in the infix string
        while (infixToken.hasMoreTokens()) {
            String nextToken = infixToken.nextToken();
            char firsChar = nextToken.charAt(0);
            // is it operand?
            if (Character.isJavaIdentifierPart(firsChar) || Character.isDigit(firsChar)) {
                postfix.append(nextToken);
                postfix.append(' ');
            } // is it an operator?
            else if (isOperator(firsChar)) {
                processOperator(firsChar);
            } else {
                throw new SyntaxException("Unexpected character encountered" + firsChar);
            }
        } // end while
          //pop any remaining operators and
          //and append them to postfix
        while (!operandStack.empty()) {
            char op = operandStack.pop();
            postfix.append(op);
            postfix.append(' ');
        }
        // assert: Stack is empty, return result
        return postfix.toString();
    } catch (EmptyStackException exp) {
        throw new SyntaxException("Syntax error: The stack is empty.");
    }
}

From source file:com.mycompany.cse222_hw04_091044011_ercanuca_2016.PostfixToAssembly.java

/**
 * save all tokens to linkedlist//w w  w .  j a v a  2s  .  co  m
 * @param postfix calculated InfixToPostfix class, it is postfix string.
 * @throws SyntaxException Syntax error: no tokens.
 */
public void saveToLinkedList(String postfix) throws SyntaxException {
    postfixes = new LinkedList<>();
    assembly = new StringBuilder();
    print = new LinkedList();
    /**
     * Take a tokenizer and save the postfix string
     */
    StringTokenizer postfixToken = new StringTokenizer(postfix);
    try {
        // process each token in the infix string
        while (postfixToken.hasMoreTokens()) {
            String nextToken = postfixToken.nextToken();
            // save like chars.
            postfixes.add(nextToken.charAt(0));
            /**
             * if our digit like, 45,56 integers
             */
            if (nextToken.length() > 1) {
                char firstChar = nextToken.charAt(1);
                postfixes.add(firstChar);
            }
            // save like string
            print.add(nextToken);

        } // end while 
    } catch (SyntaxException exp) {
        throw new SyntaxException("Syntax error: no tokens.");
    }
}

From source file:com.mycompany.hw04_eda_arikan_131044050.InfixToPosfix.java

/**
 * infix ifademiz postfixe cevriliyor// w ww.  j  ava  2 s  .c om
 *
 * @param infix gelen string ifademiz
 * @return String
 * @throws SyntaxException
 */
public String convert(String infix) throws SyntaxException {
    operatorStack = new Stack<>();
    postfix = new StringBuilder();

    String[] tokens = infix.split("\\s+");

    try {
        for (String nextToken : tokens) {

            char firstChar = nextToken.charAt(0);

            if (Character.isJavaIdentifierStart(firstChar) || Character.isDigit(firstChar)) {
                postfix.append(nextToken);
                postfix.append(' ');
            } else if (isOperator(firstChar)) {
                processOperator(firstChar);

            } else {
                throw new SyntaxException("unexpected char encountered: " + firstChar);
            }
        }

        while (!operatorStack.empty()) {

            char op = operatorStack.pop();
            postfix.append(op);
            postfix.append(' ');

        }

        return postfix.toString();

    } catch (EmptyStackException ex) {
        throw new SyntaxException("stack is empty ");
    }

}

From source file:com.mycompany.hw04_eda_arikan_131044050.PostfixEvaluater.java

/**
 * postfix cevirme - kitaptaki kodlardan yararlandim
 *
 * @return String//  w  ww. ja  v a  2s.co  m
 * @throws SyntaxException
 */
public String eval() throws SyntaxException {

    operatorStack = new Stack<String>();

    String[] tokens = expression.split("\\s+");

    try {
        for (String nextToken : tokens) {

            char firstChar = nextToken.charAt(0);

            if (Character.isDigit(firstChar) || isVariable(firstChar)) {
                operatorStack.push(nextToken);

            } else if (isOperator(nextToken.charAt(0))) {
                String result = evalOp(firstChar);
                operatorStack.push(result);

            } else {
                throw new SyntaxException("invalid character");

            }

        }

        String answer = operatorStack.pop();

        if (operatorStack.empty()) {
            return "";
        } else {
            throw new SyntaxException("stack must be empty");
        }
    } catch (EmptyStackException ex) {

        throw new SyntaxException("stack is empty");
    }

}