aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorCamil Staps2015-07-03 17:24:29 +0200
committerCamil Staps2015-07-03 17:24:29 +0200
commit6ff517a8e4227d9489c7b771984dda7508a8158b (patch)
tree8011bcdc4645f9fcf4132c08ab51ceeb637c6729 /README.md
parentParser; cleanup (diff)
Improved parser
Diffstat (limited to 'README.md')
-rw-r--r--README.md48
1 files changed, 46 insertions, 2 deletions
diff --git a/README.md b/README.md
index dc01fb5..0d2c3f6 100644
--- a/README.md
+++ b/README.md
@@ -15,9 +15,17 @@ Read further for examples.
### Operators
-There is one unary operator (`Op1`): `Not`.
+There is one unary operator (`Op1`): `Not`. It binds stronger than all other operators.
-There are four binary operators (`Op2`): `And`, `Or`, `Impl` and `Equiv`. `And` is considered left-associative; all others are considered right-associative. Associativity is only important in `toString` functions. `Expr` itself is an unambiguous recursive type.
+There are four binary operators (`Op2`). In order of descending precedence: `And`, `Or`, `Impl` and `Equiv`. `And` is considered left-associative; all others are considered right-associative. Associativity is only important in `toString` functions. `Expr` itself is an unambiguous recursive type.
+
+The operators are represented as:
+
+ * Not: `~`
+ * And: `&`
+ * Or: `|`
+ * Impl: `->`
+ * Equiv: `<->`
### Expressions
@@ -95,12 +103,48 @@ The `truthtable` of `e15`:
True | True | False | False | False
True | True | True | True | True
+## Parsing
+
+The `parse` function may be used to read an expression from a String. The following rules are used:
+
+ * Whitespace is ignored.
+ * All latin letters (`[a-zA-Z]`) are considered atomic expressions
+ * Operators are expected in their representation described above
+ * True and False are expected as `1` and `0`, respectively
+
+A usage example is found in `LogicParser.icl`. This file, once compiled, reads the command line arguments and shows their truth tables:
+
+ $./LogicParser -b -nt -e "~~(((A | (A -> B)) -> B) -> B)"
+ A | B | A -> B | A | (A -> B) | A | (A -> B) -> B | (A | (A -> B) -> B) -> B | ~((A | (A -> B) -> B) -> B) | ~~((A | (A -> B) -> B) -> B)
+ -------+-------+--------+--------------+-------------------+--------------------------+-----------------------------+------------------------------
+ False | False | True | True | False | True | False | True
+ False | True | True | True | True | True | False | True
+ True | False | False | True | False | True | False | True
+ True | True | True | True | True | True | False | True
+
+Here, `-b` and `-nt` are common Clean options to disable outputting basic values for constructors, and disable outputting execution times, respectively.
+
+The option `-e` tells the parser to show the extended truth table. With this option, only the first formula is considered. Without `-e`, multiple formulas may be given (possibly with different atomic expressions), and all will be evaluated in one table:
+
+ $./LogicParser -b -nt "~~(((A | (A -> B)) -> B) -> B)" "A & B"
+ A | B | ~~((A | (A -> B) -> B) -> B) | A & B
+ -------+-------+------------------------------+-------
+ False | False | True | False
+ False | True | True | False
+ True | False | True | False
+ True | True | True | True
+ False | False | True | False
+ False | True | True | False
+ True | False | True | False
+ True | True | True | True
+
## Future ideas
* Different `toString` formats for operators: HTML (`&not;`), UTF-8 (&not;), LaTeX (`\neg`)
* Different `toString` formats for booleans: `0` and `1` or `T` and `F` instead of `True` and `False`
* Simplifying expressions with atomic expressions as far as possible
* Testing equivalence or impliance of expressions with atomic expressions
+ * Add support for multi-letter atomic expressions
## License