Evaluate arifmetic expression with Real, Integer, Boolean, String and Set. Able to declare variable by expression assignment. Set can contain any type include other sets.
Interpretator developed based on ANTLR gramma, ANTLR visitor and implementation of each of 5 types .
Is not it clean and straight forward? I like ANTLR!
Special thanks to Shmatov and Mgrzeszczak for good examples of how to do ANTLR for numbers and simple sets.
Boolean and sets algebra following wiki below: Boolean algebra, De Morgan laws, Set math, Set symmetric difference, Complement set,Cartesian product, Ordered pair, univers, Inner product, Norm, Bit operations.
C:\ExprInt>run.cmd
Enter expression, help or quit...
>2+2
4
C:\ExprInt>java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
- Interpretator gramma does not implement functions(args);
- Powerset is not implemented.
Available operations are >=, >, <=, <, == (equals), != or <> (not equal), && (or), || (and), -> (implication), !& (nand), !| (nor), X| (xor), X! (xnor). There are two predefined boolean constants true and false.
Examples here: basic, boolean laws, the morgan laws.
Available operations with real and integer numbers are +, -, *, /, ** (power), ==, >=, >, <=, <.
There are two predefined real constants _pi (3.14) and _e (2.71).
Here are examples: arifmetika follows Shmatov example, set var follows Shmatov example
There are couple of bit operations available for integers as ~ (inversion), >> (right shift), >>> (unsigned right shift), << (left shift), & (and), | (or), ^^(xor). Here is bit example.
"This is a string constant in double quotation marks"
Available operations with strings are |"string length"|, + (concatenation), ==, !=. Here is string example.
Available operations are |{"Cardinality"}|, == (equals), @ (belongs), & (intersection), && (recursive intersection), | (union), \ (complements), /\ (disjunctive union), ' (complement set), * (cartesian product), ** (n-ary Cartesian product if set3), ** (inner product if setset), ||{"Norm"}||.
There couple special sets are {} (empty unordered set), [] (empty ordered set), {}' and []' (universal sets).
Here are examples: Basic operations, Assignment, Cardinality, Cardinality laws, Union, Union laws, Intersection, Intersection laws, Complements, Complements laws, Empty set laws, Complex set, Cartesian product, Cartesian laws, Set membership, Morgan laws, Relative laws, Symmetric difference laws, Universal set, Card deck example, Comparison, Inner product and Norm.