@Test public void shouldInterpretOperation() throws Exception { assertThat( interpreter.interpret( new OperationSyntaxNode(new IntegerSyntaxNode(1), new IntegerSyntaxNode(2), "+")), is(3)); }
/** * Takes an input string purporting to represent a program in L(G), where G is the context-free * grammar defined above, and prints the sequence of tokens of the program, terminated by a dummy * token. If an illegal token is present, it prints an error message to that effect. * * @param expr the string, represented as a string of tokens separated by whitespace characters as * recognized by the <code>Character.isWhitespace</code> predicate. */ private static void test(String program) { try { Interpreter interpreter = new Interpreter(); System.out.println(interpreter.interpret(program)); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } }
public Object exec(Context cx, Scriptable scope) { if (idata.itsFunctionType != 0) { // Can only be applied to scripts throw new IllegalStateException(); } if (!ScriptRuntime.hasTopCall(cx)) { // It will go through "call" path. but they are equivalent return ScriptRuntime.doTopCall(this, cx, scope, scope, ScriptRuntime.emptyArgs); } return Interpreter.interpret(this, cx, scope, scope, ScriptRuntime.emptyArgs); }
public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("java ScalaInterpretNIO [script file]"); return; } FileChannel fc = new FileInputStream(args[0]).getChannel(); MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); CharBuffer chb = Charset.defaultCharset().decode(buffer); Interpreter p = new Interpreter(new Settings()); p.interpret(chb.toString()); p.close(); }
@Override public byte[] pack(ISOComponent c) throws ISOException { try { String data = (String) c.getValue(); // System.out.println(data); String paddedData = padder.pad(data, getLength()); byte[] rawData = new byte [prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.getBytes().length)]; prefixer.encodeLength(paddedData.getBytes().length, rawData); interpreter.interpret(paddedData, rawData, prefixer.getPackedLength()); return rawData; } catch (Exception e) { e.printStackTrace(); throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Calls the function. * * @param cx the current context * @param scope the scope used for the call * @param thisObj the value of "this" * @param args function arguments. Must not be null. You can use {@link ScriptRuntime#emptyArgs} * to pass empty arguments. * @return the result of the function call. */ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!ScriptRuntime.hasTopCall(cx)) { return ScriptRuntime.doTopCall(this, cx, scope, thisObj, args); } return Interpreter.interpret(this, cx, scope, thisObj, args); }
@Test public void shouldInterpretSingleNumber() throws Exception { assertThat(interpreter.interpret(new IntegerSyntaxNode(1)), is(1)); }