/* * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* Generated By:JavaCC: Do not edit this line. ExpressionParser.java */package com.sun.tools.example.debug.expr; import com.sun.jdi.*; import java.util.Stack;import java.util.List;import java.util.ArrayList; public class ExpressionParser implements ExpressionParserConstants { Stack<LValue> stack = new Stack<LValue>(); VirtualMachine vm = null; GetFrame frameGetter = null; private static GetFrame lastFrameGetter; private static LValue lastLValue; LValue peek() { return stack.peek(); } LValue pop() { return stack.pop(); } void push(LValue lval) { stack.push(lval); } public static Value getMassagedValue() throws ParseException { return lastLValue.getMassagedValue(lastFrameGetter); } public interface GetFrame { StackFrame get() throws IncompatibleThreadStateException; } public static Value evaluate(String expr, VirtualMachine vm, GetFrame frameGetter) throws ParseException, InvocationException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException { // TODO StringBufferInputStream is deprecated. java.io.InputStream in = new java.io.StringBufferInputStream(expr); ExpressionParser parser = new ExpressionParser(in); parser.vm = vm; parser.frameGetter = frameGetter; parser.Expression(); lastFrameGetter = frameGetter; lastLValue = parser.pop(); return lastLValue.getValue(); } public static void main(String args[]) { ExpressionParser parser; System.out.print("Java Expression Parser: "); if (args.length == 0) { System.out.println("Reading from standard input . . ."); parser = new ExpressionParser(System.in); } else if (args.length == 1) { System.out.println("Reading from file " + args[0] + " . . ."); try { parser = new ExpressionParser(new java.io.FileInputStream(args[0])); } catch (java.io.FileNotFoundException e) { System.out.println("Java Parser Version 1.0.2: File " + args[0] + " not found."); return; } } else { System.out.println("Usage is one of:"); System.out.println(" java ExpressionParser < inputfile"); System.out.println("OR"); System.out.println(" java ExpressionParser inputfile"); return; } try { parser.Expression(); System.out.print("Java Expression Parser: "); System.out.println("Java program parsed successfully."); } catch (ParseException e) { System.out.print("Java Expression Parser: "); System.out.println("Encountered errors during parse."); } } /***************************************** * THE JAVA LANGUAGE GRAMMAR STARTS HERE * *****************************************/ /* * Type, name and expression syntax follows. */ final public void Type() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BOOLEAN: case BYTE: case CHAR: case DOUBLE: case FLOAT: case INT: case LONG: case SHORT: PrimitiveType(); break; case IDENTIFIER: Name(); break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACKET: ; break; default: jj_la1[1] = jj_gen; break label_1; } jj_consume_token(LBRACKET); jj_consume_token(RBRACKET); } } final public void PrimitiveType() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BOOLEAN: jj_consume_token(BOOLEAN); break; case CHAR: jj_consume_token(CHAR); break; case BYTE: jj_consume_token(BYTE); break; case SHORT: jj_consume_token(SHORT); break; case INT: jj_consume_token(INT); break; case LONG: jj_consume_token(LONG); break; case FLOAT: jj_consume_token(FLOAT); break; case DOUBLE: jj_consume_token(DOUBLE); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public String Name() throws ParseException { StringBuffer sb = new StringBuffer(); jj_consume_token(IDENTIFIER); sb.append(token); label_2: while (true) { if (jj_2_1(2)) { ; } else { break label_2; } jj_consume_token(DOT); jj_consume_token(IDENTIFIER); sb.append('.'); sb.append(token); } if (true) { return sb.toString(); } throw new Error("Missing return statement in function"); } final public void NameList() throws ParseException { Name(); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case COMMA: ; break; default: jj_la1[3] = jj_gen; break label_3; } jj_consume_token(COMMA); Name(); } } /* * Expression syntax follows. */ final public void Expression() throws ParseException { if (jj_2_2(2147483647)) { Assignment(); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case FALSE: case NEW: case NULL: case SUPER: case THIS: case TRUE: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case CHARACTER_LITERAL: case STRING_LITERAL: case IDENTIFIER: case LPAREN: case BANG: case TILDE: case INCR: case DECR: case PLUS: case MINUS: ConditionalExpression(); break; default: jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void Assignment() throws ParseException { PrimaryExpression(); AssignmentOperator(); Expression(); LValue exprVal = pop(); pop().setValue(exprVal); push(exprVal); } final public void AssignmentOperator() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: jj_consume_token(ASSIGN); break; case STARASSIGN: jj_consume_token(STARASSIGN); break; case SLASHASSIGN: jj_consume_token(SLASHASSIGN); break; case REMASSIGN: jj_consume_token(REMASSIGN); break; case PLUSASSIGN: jj_consume_token(PLUSASSIGN); break; case MINUSASSIGN: jj_consume_token(MINUSASSIGN); break; case LSHIFTASSIGN: jj_consume_token(LSHIFTASSIGN); break; case RSIGNEDSHIFTASSIGN: jj_consume_token(RSIGNEDSHIFTASSIGN); break; case RUNSIGNEDSHIFTASSIGN: jj_consume_token(RUNSIGNEDSHIFTASSIGN); break; case ANDASSIGN: jj_consume_token(ANDASSIGN); break; case XORASSIGN: jj_consume_token(XORASSIGN); break; case ORASSIGN: jj_consume_token(ORASSIGN); break; default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void ConditionalExpression() throws ParseException { ConditionalOrExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case HOOK: jj_consume_token(HOOK); Expression(); jj_consume_token(COLON); ConditionalExpression(); LValue falseBranch = pop(); LValue trueBranch = pop(); Value cond = pop().interiorGetValue(); if (cond instanceof BooleanValue) { push(((BooleanValue) cond).booleanValue() ? trueBranch : falseBranch); } else { { if (true) { throw new ParseException("Condition must be boolean"); } } } break; default: jj_la1[6] = jj_gen; ; } } final public void ConditionalOrExpression() throws ParseException { ConditionalAndExpression(); label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SC_OR: ; break; default: jj_la1[7] = jj_gen; break label_4; } jj_consume_token(SC_OR); ConditionalAndExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void ConditionalAndExpression() throws ParseException { InclusiveOrExpression(); label_5: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SC_AND: ; break; default: jj_la1[8] = jj_gen; break label_5; } jj_consume_token(SC_AND); InclusiveOrExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void InclusiveOrExpression() throws ParseException { ExclusiveOrExpression(); label_6: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_OR: ; break; default: jj_la1[9] = jj_gen; break label_6; } jj_consume_token(BIT_OR); ExclusiveOrExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void ExclusiveOrExpression() throws ParseException { AndExpression(); label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case XOR: ; break; default: jj_la1[10] = jj_gen; break label_7; } jj_consume_token(XOR); AndExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void AndExpression() throws ParseException { EqualityExpression(); label_8: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_AND: ; break; default: jj_la1[11] = jj_gen; break label_8; } jj_consume_token(BIT_AND); EqualityExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void EqualityExpression() throws ParseException { Token tok; InstanceOfExpression(); label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EQ: case NE: ; break; default: jj_la1[12] = jj_gen; break label_9; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EQ: tok = jj_consume_token(EQ); break; case NE: tok = jj_consume_token(NE); break; default: jj_la1[13] = jj_gen; jj_consume_token(-1); throw new ParseException(); } InstanceOfExpression(); LValue left = pop(); push( LValue.booleanOperation(vm, tok, pop(), left) ); } } final public void InstanceOfExpression() throws ParseException { RelationalExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case INSTANCEOF: jj_consume_token(INSTANCEOF); Type(); { if (true) { throw new ParseException("operation not yet supported"); } } break; default: jj_la1[14] = jj_gen; ; } } final public void RelationalExpression() throws ParseException { Token tok; ShiftExpression(); label_10: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case GT: case LT: case LE:Lines 1–500 of 3933. Load more
/* * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* Generated By:JavaCC: Do not edit this line. ExpressionParser.java */ package com.sun.tools.example.debug.expr; import com.sun.jdi.*; import java.util.Stack; import java.util.List; import java.util.ArrayList; public class ExpressionParser implements ExpressionParserConstants { Stack<LValue> stack = new Stack<LValue>(); VirtualMachine vm = null; GetFrame frameGetter = null; private static GetFrame lastFrameGetter; private static LValue lastLValue; LValue peek() { return stack.peek(); } LValue pop() { return stack.pop(); } void push(LValue lval) { stack.push(lval); } public static Value getMassagedValue() throws ParseException { return lastLValue.getMassagedValue(lastFrameGetter); } public interface GetFrame { StackFrame get() throws IncompatibleThreadStateException; } public static Value evaluate(String expr, VirtualMachine vm, GetFrame frameGetter) throws ParseException, InvocationException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException { // TODO StringBufferInputStream is deprecated. java.io.InputStream in = new java.io.StringBufferInputStream(expr); ExpressionParser parser = new ExpressionParser(in); parser.vm = vm; parser.frameGetter = frameGetter; parser.Expression(); lastFrameGetter = frameGetter; lastLValue = parser.pop(); return lastLValue.getValue(); } public static void main(String args[]) { ExpressionParser parser; System.out.print("Java Expression Parser: "); if (args.length == 0) { System.out.println("Reading from standard input . . ."); parser = new ExpressionParser(System.in); } else if (args.length == 1) { System.out.println("Reading from file " + args[0] + " . . ."); try { parser = new ExpressionParser(new java.io.FileInputStream(args[0])); } catch (java.io.FileNotFoundException e) { System.out.println("Java Parser Version 1.0.2: File " + args[0] + " not found."); return; } } else { System.out.println("Usage is one of:"); System.out.println(" java ExpressionParser < inputfile"); System.out.println("OR"); System.out.println(" java ExpressionParser inputfile"); return; } try { parser.Expression(); System.out.print("Java Expression Parser: "); System.out.println("Java program parsed successfully."); } catch (ParseException e) { System.out.print("Java Expression Parser: "); System.out.println("Encountered errors during parse."); } } /***************************************** * THE JAVA LANGUAGE GRAMMAR STARTS HERE * *****************************************/ /* * Type, name and expression syntax follows. */ final public void Type() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BOOLEAN: case BYTE: case CHAR: case DOUBLE: case FLOAT: case INT: case LONG: case SHORT: PrimitiveType(); break; case IDENTIFIER: Name(); break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACKET: ; break; default: jj_la1[1] = jj_gen; break label_1; } jj_consume_token(LBRACKET); jj_consume_token(RBRACKET); } } final public void PrimitiveType() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BOOLEAN: jj_consume_token(BOOLEAN); break; case CHAR: jj_consume_token(CHAR); break; case BYTE: jj_consume_token(BYTE); break; case SHORT: jj_consume_token(SHORT); break; case INT: jj_consume_token(INT); break; case LONG: jj_consume_token(LONG); break; case FLOAT: jj_consume_token(FLOAT); break; case DOUBLE: jj_consume_token(DOUBLE); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public String Name() throws ParseException { StringBuffer sb = new StringBuffer(); jj_consume_token(IDENTIFIER); sb.append(token); label_2: while (true) { if (jj_2_1(2)) { ; } else { break label_2; } jj_consume_token(DOT); jj_consume_token(IDENTIFIER); sb.append('.'); sb.append(token); } if (true) { return sb.toString(); } throw new Error("Missing return statement in function"); } final public void NameList() throws ParseException { Name(); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case COMMA: ; break; default: jj_la1[3] = jj_gen; break label_3; } jj_consume_token(COMMA); Name(); } } /* * Expression syntax follows. */ final public void Expression() throws ParseException { if (jj_2_2(2147483647)) { Assignment(); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case FALSE: case NEW: case NULL: case SUPER: case THIS: case TRUE: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case CHARACTER_LITERAL: case STRING_LITERAL: case IDENTIFIER: case LPAREN: case BANG: case TILDE: case INCR: case DECR: case PLUS: case MINUS: ConditionalExpression(); break; default: jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void Assignment() throws ParseException { PrimaryExpression(); AssignmentOperator(); Expression(); LValue exprVal = pop(); pop().setValue(exprVal); push(exprVal); } final public void AssignmentOperator() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: jj_consume_token(ASSIGN); break; case STARASSIGN: jj_consume_token(STARASSIGN); break; case SLASHASSIGN: jj_consume_token(SLASHASSIGN); break; case REMASSIGN: jj_consume_token(REMASSIGN); break; case PLUSASSIGN: jj_consume_token(PLUSASSIGN); break; case MINUSASSIGN: jj_consume_token(MINUSASSIGN); break; case LSHIFTASSIGN: jj_consume_token(LSHIFTASSIGN); break; case RSIGNEDSHIFTASSIGN: jj_consume_token(RSIGNEDSHIFTASSIGN); break; case RUNSIGNEDSHIFTASSIGN: jj_consume_token(RUNSIGNEDSHIFTASSIGN); break; case ANDASSIGN: jj_consume_token(ANDASSIGN); break; case XORASSIGN: jj_consume_token(XORASSIGN); break; case ORASSIGN: jj_consume_token(ORASSIGN); break; default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void ConditionalExpression() throws ParseException { ConditionalOrExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case HOOK: jj_consume_token(HOOK); Expression(); jj_consume_token(COLON); ConditionalExpression(); LValue falseBranch = pop(); LValue trueBranch = pop(); Value cond = pop().interiorGetValue(); if (cond instanceof BooleanValue) { push(((BooleanValue) cond).booleanValue() ? trueBranch : falseBranch); } else { { if (true) { throw new ParseException("Condition must be boolean"); } } } break; default: jj_la1[6] = jj_gen; ; } } final public void ConditionalOrExpression() throws ParseException { ConditionalAndExpression(); label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SC_OR: ; break; default: jj_la1[7] = jj_gen; break label_4; } jj_consume_token(SC_OR); ConditionalAndExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void ConditionalAndExpression() throws ParseException { InclusiveOrExpression(); label_5: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SC_AND: ; break; default: jj_la1[8] = jj_gen; break label_5; } jj_consume_token(SC_AND); InclusiveOrExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void InclusiveOrExpression() throws ParseException { ExclusiveOrExpression(); label_6: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_OR: ; break; default: jj_la1[9] = jj_gen; break label_6; } jj_consume_token(BIT_OR); ExclusiveOrExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void ExclusiveOrExpression() throws ParseException { AndExpression(); label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case XOR: ; break; default: jj_la1[10] = jj_gen; break label_7; } jj_consume_token(XOR); AndExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void AndExpression() throws ParseException { EqualityExpression(); label_8: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_AND: ; break; default: jj_la1[11] = jj_gen; break label_8; } jj_consume_token(BIT_AND); EqualityExpression(); { if (true) { throw new ParseException("operation not yet supported"); } } } } final public void EqualityExpression() throws ParseException { Token tok; InstanceOfExpression(); label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EQ: case NE: ; break; default: jj_la1[12] = jj_gen; break label_9; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EQ: tok = jj_consume_token(EQ); break; case NE: tok = jj_consume_token(NE); break; default: jj_la1[13] = jj_gen; jj_consume_token(-1); throw new ParseException(); } InstanceOfExpression(); LValue left = pop(); push( LValue.booleanOperation(vm, tok, pop(), left) ); } } final public void InstanceOfExpression() throws ParseException { RelationalExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case INSTANCEOF: jj_consume_token(INSTANCEOF); Type(); { if (true) { throw new ParseException("operation not yet supported"); } } break; default: jj_la1[14] = jj_gen; ; } } final public void RelationalExpression() throws ParseException { Token tok; ShiftExpression(); label_10: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case GT: case LT: case LE: