The original version does not support bit move operation. So I add bit move operators like "<<" and ">>" for bit move operation, and bit move assignment operators like "<<=" and ">>=" are supported. Then parser can parse expression like "3 << 26" or "l<<=r", the result is 0x0C000000 in Hex format.
These listed files are modified.
- org/apache/commons/jexl3/internal/Debugger.java
- org/apache/commons/jexl3/internal/Interpreter.java
- org/apache/commons/jexl3/internal/Operators.java
- org/apache/commons/jexl3/parser/ParserVisitor.java
- org/apache/commons/jexl3/parser/Parser.jjt
- org/apache/commons/jexl3/JexlArithmetic.java
- org/apache/commons/jexl3/JexlOperator.java
- Install JDK 1.8 or upper.
- Install the latest version of Maven.
- Set environment in local operation system.
- Run commands in command line(Windows) or terminal(Unix/Linux).
4.1 mvn package
4.2 Copy jar file 'commons-jexl3-3.1.jar' generated by maven into project directory and add it to build path.
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
public class Main {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
JexlBuilder builder = new JexlBuilder();
JexlEngine engine = builder.create();
JexlExpression expression = null;
JexlContext context = null;
context = new MapContext();
context.set("l", 3);
context.set("r", 26);
expression = engine.createExpression("l<<(r+1)");
Object ret = expression.evaluate(context);
if (ret instanceof Long) {
Long val = (Long) ret;
System.out.println(String.format("0x%08X", val.longValue()));
}
}
}
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
public class Main {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
JexlBuilder builder = new JexlBuilder();
JexlEngine engine = builder.create();
JexlExpression expression = null;
JexlContext context = null;
context = new MapContext();
context.set("l", 3);
context.set("r", 26);
expression = engine.createExpression("l<<=r");
Object ret = expression.evaluate(context);
if (ret instanceof Long) {
Long val = (Long) ret;
System.out.println(String.format("0x%08X", val.longValue()));
}
Object var = context.get("l");
if (var instanceof Long) {
Long val = (Long) var;
System.out.println(String.format("0x%08X", val.longValue()));
}
}
}