JLSP is a lightweight Java parser designed for speed and customization. It supports custom operators, user-defined functions, and replaceable variables, making it a versatile tool for developers. With its linear time complexity, it efficiently handles parsing tasks, ensuring optimal performance for complex calculations.
JLSP: A Lightweight Linear-Time Java Parser
JLSP is an adaptable and efficient Java parser designed for processing mathematical expressions. With a compact footprint of approximately 40kb, this parser excels in speed and functionality, ensuring linear-time operations for enhanced performance.
A straightforward example demonstrates the parser's capabilities:
Parser parser = new Parser();
Formula formula = parser.parse("17.43+((3.5+2.1*(7-4%3))^2.3)/((6+4.2+(8%5)))");
System.out.println(formula.inOperationOrderResult());
For convenience, the StaticParser class can be employed for a global parser setup:
Formula formula = StaticParser.parse("17.43+((3.5+2.1*(7-4%3))^2.3)/((6+4.2+(8%5)))");
System.out.println(formula.inOperationOrderResult());
The parser allows the creation of custom variables and setting their values as follows:
Formula f = ParserStatic.parse("-4+ab+1.7*(k+a)");
// Assign values to variables in the order they appear
f.setVariables(4, 8, 3);
Custom operators and functions can be defined to expand the parser's capabilities. For instance:
addOperator('^', (a, b, extra) -> Math.pow(Math.abs(a), b), 10);
addFunction("sqrt", (caller, inOperationOrder, a) -> Math.sqrt(processEntity(caller, a[0], inOperationOrder)));
JLSP supports extensive configuration options to fine-tune parsing behavior:
For comprehensive documentation and additional capabilities, refer to the Javadocs.
Explore the potential of JLSP to enhance parsing efficiency and customize it according to specific application requirements.
No comments yet.
Sign in to be the first to comment.