Example usage for org.antlr.v4.runtime CommonToken getType

List of usage examples for org.antlr.v4.runtime CommonToken getType

Introduction

In this page you can find the example usage for org.antlr.v4.runtime CommonToken getType.

Prototype

@Override
    public int getType() 

Source Link

Usage

From source file:PhpBaseLexer.java

License:Open Source License

@Override
public Token nextToken() {
    CommonToken token = (CommonToken) super.nextToken();

    if (token.getType() == PhpLexer.PHPEnd || token.getType() == PhpLexer.PHPEndSingleLineComment) {
        if (_mode == PhpLexer.SingleLineCommentMode) {
            // SingleLineCommentMode for such allowed syntax:
            // <?php echo "Hello world"; // comment ?>
            popMode(); // exit from SingleLineComment mode.
        }/*from  w w w . ja v  a 2s  .  c  o m*/
        popMode(); // exit from PHP mode.

        if (token.getText().equals("</script>")) {
            _phpScript = false;
            token.setType(PhpLexer.ScriptClose);
        } else {
            // Add semicolon to the end of statement if it is absente.
            // For example: <?php echo "Hello world" ?>
            if (_prevTokenType == PhpLexer.SemiColon || _prevTokenType == PhpLexer.Colon
                    || _prevTokenType == PhpLexer.OpenCurlyBracket
                    || _prevTokenType == PhpLexer.CloseCurlyBracket) {
                token.setChannel(PhpLexer.SkipChannel);
            } else {
                token = new CommonToken(PhpLexer.SemiColon);
            }
        }
    } else if (token.getType() == PhpLexer.HtmlName) {
        _htmlNameText = token.getText();
    } else if (token.getType() == PhpLexer.HtmlDoubleQuoteString) {
        if (token.getText().equals("php") && _htmlNameText.equals("language")) {
            _phpScript = true;
        }
    } else if (_mode == PhpLexer.HereDoc) {
        // Heredoc and Nowdoc syntax support: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
        switch (token.getType()) {
        case PhpLexer.StartHereDoc:
        case PhpLexer.StartNowDoc:
            _heredocIdentifier = token.getText().substring(3).trim().replace("\'", "");
            break;

        case PhpLexer.HereDocText:
            if (CheckHeredocEnd(token.getText())) {
                popMode();

                String heredocIdentifier = GetHeredocIdentifier(token.getText());
                if (token.getText().trim().endsWith(";")) {
                    token = new CommonToken(PhpLexer.SemiColon, heredocIdentifier + ";\n");
                } else {
                    token = (CommonToken) super.nextToken();
                    token.setText(heredocIdentifier + "\n;");
                }
            }
            break;
        }
    } else if (_mode == PhpLexer.PHP) {
        if (_channel != PhpLexer.HIDDEN) {
            _prevTokenType = token.getType();
        }
    }

    return token;
}

From source file:com.github.jknack.css.CSS.java

License:Apache License

public StyleSheet parse(final String content) {
    CssLexer lexer = new CssLexer(new ANTLRInputStream(content));
    //    lexer.removeErrorListeners();
    if (!debug) {
        lexer.addErrorListener(new ErrorReporter());
    }//from   www .j a v a  2  s  .com
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    tokens.fill();
    CssParser parser = new CssParser(tokens);
    //    parser.setErrorHandler(new BailErrorStrategy());
    //    parser.removeParseListeners();
    if (!debug) {
        parser.addErrorListener(new ErrorReporter());
    }
    if (debug) {
        for (Token tok : tokens.getTokens()) {
            CommonToken ct = (CommonToken) tok;
            String[] tokenNames = lexer.getTokenNames();
            int type = ct.getType();
            System.out.println((type > 0 ? tokenNames[type] : "EOF") + "(" + ct.getText() + ")");
        }
    }
    StyleSheetContext tree = parser.styleSheet();
    if (debug) {
        System.out.println(tree.toStringTree(parser));
    }
    CSSBuilder builder = new CSSBuilder();
    return (StyleSheet) builder.visit(tree);
}

From source file:com.khubla.jvmbasic.jvmbasicc.compiler.Dispatcher.java

License:Open Source License

/**
 * dispatch//w ww .  j  a va  2s  .c o m
 */
public static boolean dispatch(GenerationContext generationContext) throws Exception {
    try {
        if (null != generationContext.getParseTree()) {
            final Object o = generationContext.getParseTree().getPayload();
            if (o.getClass() == CommonToken.class) {
                final CommonToken commonToken = (CommonToken) o;
                final Function function = FunctionRegistry.getInstance()
                        .getTokenFunction(commonToken.getType());
                logger.info("Dispatching to '" + function.getClass().getSimpleName() + "' for token '"
                        + jvmBasicParser.tokenNames[commonToken.getType()] + "'");
                return function.execute(generationContext);
            } else {
                final ParserRuleContext parserRuleContext = (ParserRuleContext) o;
                final Function function = FunctionRegistry.getInstance()
                        .getRuleFunction(parserRuleContext.getRuleIndex());
                logger.info("Dispatching to '" + function.getClass().getSimpleName() + "' for rule '"
                        + jvmBasicParser.ruleNames[parserRuleContext.getRuleIndex()] + "'");
                return function.execute(generationContext);
            }
        }
        return true;
    } catch (final Exception e) {
        throw new Exception("Exception in dispatch at line " + generationContext.getLineNumber(), e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.compiler.TreePrinter.java

License:Open Source License

@Override
public void token(CommonToken commonToken, int ctxlevel) {
    if (commonToken.getType() != -1) {
        logger.info(indentString(ctxlevel) + "[" + commonToken.getType() + " "
                + jvmBasicParser.tokenNames[commonToken.getType()] + "] " + commonToken.getText());
    }//ww  w  .ja v a 2 s .  c o  m
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.addingExpressionRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {/*from w  ww .  j  a  v a  2s  .c o  m*/
        /*
         * get the operands
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * if there are 3 values, we add them
         */
        if (generationContext.getParseTree().getChildCount() == 3) {
            /*
             * operation
             */
            final AddingExpressionContext addingExpressionContext = (AddingExpressionContext) generationContext
                    .getParseTree();
            final CommonToken commonToken = (CommonToken) addingExpressionContext.getChild(1).getPayload();
            if (commonToken.getType() == jvmBasicParser.PLUS) {
                /*
                 * add
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DADD);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            } else {
                /*
                 * swap the stack arguments so we have the prompt on top and the variable name next
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V");
                /*
                 * subtract
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DSUB);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            }
            return true;
        } else {
            /**
             * do nothing
             */
            return true;
        }
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.multiplyingExpressionRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {/*from   w  w  w .ja  va2 s .  com*/
        /*
         * get the operands
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * check for 3 values
         */
        if (generationContext.getParseTree().getChildCount() == 3) {
            /*
             * operation
             */
            final MultiplyingExpressionContext multiplyingExpressionContext = (MultiplyingExpressionContext) generationContext
                    .getParseTree();
            final CommonToken commonToken = (CommonToken) multiplyingExpressionContext.getChild(1).getPayload();
            if (commonToken.getType() == jvmBasicParser.TIMES) {
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DMUL);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            } else {
                /*
                 * swap the stack arguments so we have the prompt on top and the variable name next
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V");
                /*
                 * divide
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DDIV);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            }
            return true;
        } else {
            /*
             * do nothing
             */
            return true;
        }
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.relationalExpressionRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {/* ww  w . j ava  2 s. c  o m*/
        /*
         * get the operands
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * check for 3 values
         */
        if (generationContext.getParseTree().getChildCount() == 3) {
            /*
             * sign
             */
            final RelopContext relopContext = (RelopContext) generationContext.getParseTree().getChild(1);
            final CommonToken commonToken = (CommonToken) relopContext.getChild(0).getPayload();
            if (commonToken.getType() == jvmBasicParser.GTE) {
                /*
                 * compare
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC,
                        RTLHelper.JASIC_RUNTIME_MATH, "GTE",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Boolean;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Boolean;)V");
            } else if (commonToken.getType() == jvmBasicParser.GT) {
                /*
                 * compare
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC,
                        RTLHelper.JASIC_RUNTIME_MATH, "GT",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Boolean;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Boolean;)V");
            } else if (commonToken.getType() == jvmBasicParser.LTE) {
                /*
                 * compare
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC,
                        RTLHelper.JASIC_RUNTIME_MATH, "LTE",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Boolean;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Boolean;)V");
            } else if (commonToken.getType() == jvmBasicParser.LT) {
                /*
                 * compare
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC,
                        RTLHelper.JASIC_RUNTIME_MATH, "LT",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Boolean;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Boolean;)V");
            }
            return true;
        } else {
            /*
             * do nothing
             */
            return true;
        }
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.spotify.heroic.grammar.QueryListener.java

License:Apache License

@Override
public void exitString(StringContext ctx) {
    final ParseTree child = ctx.getChild(0);
    final CommonToken token = (CommonToken) child.getPayload();
    final Context c = context(ctx);

    if (token.getType() == HeroicQueryLexer.SimpleString || token.getType() == HeroicQueryLexer.Identifier) {
        push(new StringExpression(c, child.getText()));
        return;/*w w w .  j  av  a  2  s . co  m*/
    }

    push(new StringExpression(c, parseQuotedString(c, child.getText())));
}

From source file:controle.dicionario.Dicionario.java

private void analisaAssunto(String nomeArquivo, String texto) throws Exception {
    //ArrayList<String> tags = null;
    ArrayList<String> tagsMorf = null;
    CommonTokenStream tokensMorf = null;
    CommonTokenStream tokens = null;/*from w w w . j av a 2s. co  m*/
    Referencia referenciaBanco = referenciasHash.get(nomeArquivo);
    referenciaBanco.setQtd(0);
    referenciaDAO.atualiza(referenciaBanco);
    this.nomeArquivo = nomeArquivo;
    SrsGrammarLexer lexer = new SrsGrammarLexer(new ANTLRInputStream(texto));
    tokens = new CommonTokenStream(lexer);
    SrsGrammarParser parser = new SrsGrammarParser(tokens);
    System.out.println(tokens.getText());

    analisePeriodo = new AnalisePeriodo(texto);

    SrsGrammarLexer lexerMorf = new SrsGrammarLexer(new ANTLRInputStream(texto));
    tokensMorf = new CommonTokenStream(lexerMorf);
    System.out.println(tokensMorf.getText());
    tagsMorf = etiquetar(tokensMorf);

    try {
        Sigla sigla = new Sigla();
        siglas.putAll(sigla.reconheceSiglas(tokens));

    } catch (Exception e) {
        e.printStackTrace();
    }

    Iterator it1 = tokens.getTokens().iterator();
    CommonToken ob = null;
    int qtdPalavrasRelevantes = 0;
    int qtdRadicais = 0;

    while (it1.hasNext()) {
        ob = (CommonToken) it1.next();
        //Retirando o caractere '-' do inicio da palavra
        if (ob.getText().length() > 1 && ob.getText().charAt(0) == '-') {
            ob.setText(ob.getText().substring(1));
        }
        //Retirando o caractere '-' do fim da palavra
        if (ob.getText().length() > 1 && (ob.getText().charAt(ob.getText().length() - 1) == '-')) {
            ob.setText(ob.getText().substring(0, ob.getText().length() - 2));
        }

        String palavra = ob.getText().toLowerCase();
        String palavraLemmaa = ob.getText();

        //Filtrando as palavras relevantes do texto
        if ((ob.getType() == SrsGrammarLexer.PALAVRA) && (ob.getText().length() > 4)
                && stopWordsHash.get(palavra) == null && !ehTudoIgual(palavra)) {
            qtdPalavrasRelevantes++;

            String radical;
            //Recuperando radical da palavra
            //Obtem radical utilizando o PTStemmer
            radical = getRadicalPTStemmer(palavra);

            String lemma;
            //Obtem lemma utilizando o TreeTagger
            //                lemma = AnalisePeriodo.tagger.getLemma(palavraLemmaa);
            lemma = AnalisePeriodo.recuperaLemma(palavraLemmaa);
            palavraLemma.put(palavraLemmaa, lemma);

            Lemma lemmaBanco = new Lemma(null, lemma);
            Radical radicalBanco = new Radical(null, radical);
            Palavra palavraBanco = new Palavra(null, palavra, lemmaBanco, radicalBanco);

            if (!palavrasHash.containsKey(palavra)) {
                palavrasHash.put(palavra, palavraBanco);
            }

            if (!radicaisHash.containsKey(radical)) {
                radicaisHash.put(radical, radicalBanco);
            }

            if (!lemmaHash.containsKey(lemma)) {
                lemmaHash.put(lemma, lemmaBanco);
            }

            Dados dadosBanco = new Dados();
            dadosBanco.setF(1);
            dadosBanco.setIdPalavra(palavraBanco);
            dadosBanco.setIdRadical(radicalBanco);
            dadosBanco.setIdReferencia(referenciaBanco);
            dadosBanco.setIdProjeto(projetoSelecionado);
            String chaveDados = projetoSelecionado.getId() + referenciaBanco.getId() + radical + palavra;
            if (!dadosHash.containsKey(chaveDados)) {
                dadosHash.put(chaveDados, dadosBanco);
                palavraBanco = palavrasHash.get(palavra);
                dadosBanco.setQtdDoc(dadosBanco.getQtdDoc() + 1);
            } else {
                Integer i = dadosHash.get(chaveDados).getF() + 1;
                dadosBanco.setF(i);
                dadosBanco.setQtdDoc(1);
                dadosHash.replace(chaveDados, dadosBanco);
            }

            DadoRadical dadoRadicalBanco = new DadoRadical();
            dadoRadicalBanco.setF(1);
            dadoRadicalBanco.setIdRadical(radicalBanco);
            dadoRadicalBanco.setIdReferencia(referenciaBanco);
            dadoRadicalBanco.setIdProjeto(projetoSelecionado);
            String chaveDadoRadical = projetoSelecionado.getId() + referenciaBanco.getId() + radical;
            if (!dadoRadicalHash.containsKey(chaveDadoRadical)) {
                dadoRadicalHash.put(chaveDadoRadical, dadoRadicalBanco);
                radicalBanco = radicaisHash.get(radical);
                dadoRadicalBanco.setQtdDoc(dadoRadicalBanco.getQtdDoc() + 1);
            } else {
                Integer i = dadoRadicalHash.get(chaveDadoRadical).getF() + 1;
                dadoRadicalBanco.setF(i);
                dadoRadicalBanco.setQtdDoc(1);
                dadoRadicalHash.replace(chaveDadoRadical, dadoRadicalBanco);
            }

        }
    }
    referenciaBanco.setQtdRelevante(qtdPalavrasRelevantes);
    referenciaBanco.setPercRelevante(((float) qtdPalavrasRelevantes / tokens.size()) * 100);
    referenciaDAO.atualiza(referenciaBanco);

    tagsMorf = etiquetar(tokensMorf);

    ParseTree tree;
    tree = parser.init();
    oracoes = parser.oracoes;
    ArrayList<String> oracoes1 = new ArrayList<>();
    for (String oracao : oracoes) {
        if (!oracao.equals("\n")) {
            oracoes1.add(oracao);
        }
    }
    parser.oracoes.clear();
    parser.oracoes.addAll(oracoes1);

    addAbreviatura();

}

From source file:nl.lxtreme.libtdl.TdlHelper.java

License:Apache License

/**
 * @param input/* ww w. j a  va 2 s. co m*/
 *            the text to split into tokens.
 * @return a list of {@link TdlToken}s, never <code>null</code>.
 */
protected List<TdlToken> tokenize(CharStream input) {
    setInput(input);
    reset();

    List<TdlToken> tokens = new ArrayList<TdlToken>();

    Token token;
    while ((token = m_lexer.nextToken()).getType() != EOF) {
        CommonToken ctoken = (CommonToken) token;

        int startIdx = ctoken.getStartIndex();
        int stopIdx = ctoken.getStopIndex();

        int offset = startIdx;
        int length = (stopIdx + 1) - startIdx;

        TdlTokenType type = TdlTokenFactory.convertTokenType(m_config, ctoken.getType());

        tokens.add(new TdlTokenImpl(type, offset, length, ctoken.getText()));
    }

    return tokens;
}