-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackConverter.java
More file actions
40 lines (35 loc) · 1.2 KB
/
Copy pathStackConverter.java
File metadata and controls
40 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* StackConverter – JNI bridge to the C library.
*
* The native library (libstackconverter.so / stackconverter.dll) must be
* on java.library.path. Run with:
* java -Djava.library.path=./lib lab5.StackConverterGUI
*/
public class StackConverter {
static {
System.loadLibrary("stackconverter");
}
/**
* Convert an infix expression to postfix (Reverse Polish) notation.
* Unary minus is represented as '~' in the output.
*
* @param infix e.g. "a+b*c" or "-a*b^2-c-(-b)"
* @return postfix string, or a message starting with "ERROR:"
*/
public native String toPostfix(String infix);
/**
* Convert an infix expression to prefix (Polish) notation.
*
* @param infix e.g. "a+b*c"
* @return prefix string, or a message starting with "ERROR:"
*/
public native String toPrefix(String infix);
/**
* Evaluate an infix expression given variable values.
*
* @param infix the infix expression
* @param vars comma-separated assignments, e.g. "a=1,b=2,c=3"
* @return numeric result as a string, or a message starting with "ERROR:"
*/
public native String evaluate(String infix, String vars);
}