Search in sources :

Example 1 with Symbol

use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.

the class CompLexer method alloy_num.

private final Symbol alloy_num(String txt) throws Err {
    Pos p = alloy_here(txt);
    int n = 0;
    try {
        txt = txt.replaceAll("_", "");
        n = Integer.parseInt(txt);
    } catch (NumberFormatException ex) {
        throw new ErrorSyntax(p, "The number " + txt + " " + ex);
    }
    return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 2 with Symbol

use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.

the class CompLexer method alloy_hexnum.

private final Symbol alloy_hexnum(String txt) throws Err {
    Pos p = alloy_here(txt);
    int n = 0;
    try {
        txt = txt.substring(2).replaceAll("_", "");
        n = Integer.parseInt(txt, 16);
    } catch (NumberFormatException ex) {
        throw new ErrorSyntax(p, "The hex number " + txt + " " + ex);
    }
    return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 3 with Symbol

use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.

the class CUP$CompParser$actions method parse.

@Override
public Symbol parse() throws java.lang.Exception {
    // current action code
    int act;
    // the Symbol/stack element returned by a reduce
    Symbol lhs_sym = null;
    // information about production being reduced with
    short handle_size, lhs_sym_num;
    boolean logging = AlloyCore.isDebug();
    production_tab = production_table();
    action_tab = action_table();
    reduce_tab = reduce_table();
    init_actions();
    user_init();
    // start
    cur_token = scan();
    stack.removeAllElements();
    stack.push(getSymbolFactory().startSymbol("START", 0, start_state()));
    tos = 0;
    for (_done_parsing = false; !_done_parsing; ) {
        act = get_action(((Symbol) stack.peek()).parse_state, cur_token.sym);
        if (act > 0) {
            // "shift"; thus, we shift to the encoded state by pushing it on the stack
            if (logging)
                System.out.println("shift " + cur_token.sym);
            cur_token.parse_state = act - 1;
            stack.push(cur_token);
            tos++;
            cur_token = scan();
        } else if (act < 0) {
            // "reduce"
            if (logging)
                System.out.println("reduce " + ((-act) - 1));
            lhs_sym = do_action((-act) - 1, this, stack, tos);
            lhs_sym_num = production_tab[(-act) - 1][0];
            handle_size = production_tab[(-act) - 1][1];
            for (int i = 0; i < handle_size; i++) {
                stack.pop();
                tos--;
            }
            act = get_reduce(((Symbol) stack.peek()).parse_state, lhs_sym_num);
            lhs_sym.parse_state = act;
            stack.push(lhs_sym);
            tos++;
        } else {
            // "error"
            if (logging)
                System.out.println("error");
            syntax_error(cur_token);
            done_parsing();
        }
    }
    return lhs_sym;
}
Also used : Symbol(java_cup.runtime.Symbol)

Example 4 with Symbol

use of java_cup.runtime.Symbol in project webtools.sourceediting by eclipse.

the class InternalXPathParser method parse.

/**
 * Tries to parse the xpath expression
 *
 * @param xpath
 *            is the xpath string.
 * @param isRootlessAccess
 *            if 'true' then PsychoPath engine can't parse xpath expressions starting with / or //.
 * @throws XPathParserException.
 * @return the xpath value.
 * @since 2.0
 */
public XPath parse(String xpath, boolean isRootlessAccess) throws XPathParserException {
    XPathFlex lexer = new XPathFlex(new StringReader(xpath));
    try {
        XPathCup p = new XPathCup(lexer);
        Symbol res = p.parse();
        XPath xPath2 = (XPath) res.value;
        if (isRootlessAccess) {
            xPath2.accept(new DefaultVisitor() {

                public Object visit(XPathExpr e) {
                    if (e.slashes() > 0) {
                        throw new XPathParserException("Access to root node is not allowed (set by caller)");
                    }
                    do {
                        // check the single step (may have filter with root access)
                        e.expr().accept(this);
                        // follow singly linked list of the path, it's all relative past the first one
                        e = e.next();
                    } while (e != null);
                    return null;
                }
            });
        }
        return xPath2;
    } catch (JFlexError e) {
        throw new XPathParserException("JFlex lexer error: " + e.reason());
    } catch (CupError e) {
        throw new XPathParserException("CUP parser error: " + e.reason());
    } catch (StaticError e) {
        throw new XPathParserException(e.code(), e.getMessage());
    } catch (Exception e) {
        throw new XPathParserException(e.getMessage());
    }
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) Symbol(java_cup.runtime.Symbol) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) StringReader(java.io.StringReader) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 5 with Symbol

use of java_cup.runtime.Symbol in project webtools.sourceediting by eclipse.

the class XPathFlexTest method testUTF16_SurogatePair_valid.

public void testUTF16_SurogatePair_valid() throws IOException {
    // SPEAK-NO-EVIL MONKEY is a valid XML name
    // Unicode: U+1F64A (U+D83D U+DE4A)
    XPathFlex lexer = new XPathFlex(new StringReader(" monkey\uD83D\uDE4Ame "));
    Symbol symbol = lexer.next_token();
    assertEquals("monkey\uD83D\uDE4Ame", symbol.value);
}
Also used : Symbol(java_cup.runtime.Symbol) StringReader(java.io.StringReader)

Aggregations

Symbol (java_cup.runtime.Symbol)15 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)6 Pos (edu.mit.csail.sdg.alloy4.Pos)5 StringReader (java.io.StringReader)2 Expr (edu.mit.csail.sdg.ast.Expr)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeSet (java.util.TreeSet)1 CompilationUnit (net.jangaroo.jooc.ast.CompilationUnit)1 BOMStripperInputStream (net.jangaroo.utils.BOMStripperInputStream)1 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)1 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)1 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)1 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)1