[mod] examples
This commit is contained in:
parent
71d5370d77
commit
236504e350
|
|
@ -1,5 +1,5 @@
|
|||
## Usage
|
||||
|
||||
- `cat examples/arithmetics/arithmetics.tp2 | tools/conv > /tmp/arithmetics.tp2.json`
|
||||
- `echo '2+3' | build/type2 /tmp/arithmetics.tp2.json`
|
||||
- `echo '(2+3)*5' | build/type2 /tmp/arithmetics.tp2.json | examples/arithmetics/eval`
|
||||
- `cat arithmetics.tp2 | ../../tools/convert > /tmp/arithmetics.tp2.json`
|
||||
- `echo '2+3' | type2 /tmp/arithmetics.tp2.json`
|
||||
- `echo '(2+3)*5' | type2 /tmp/arithmetics.tp2.json | ./eval`
|
||||
|
|
|
|||
19
examples/logic/logic.tp2
Normal file
19
examples/logic/logic.tp2
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
@1
|
||||
|
||||
[] : " |\t|\n"
|
||||
[const_false] : "false|0"
|
||||
[const_true] : "true|1"
|
||||
[not] : "¬|-|\!|not"
|
||||
[and] : "∧|&|and"
|
||||
[or] : "∨|\||or"
|
||||
[open] : "\(|\["
|
||||
[close] : "\)|\]"
|
||||
|
||||
{constant_false} : <formula> : [const_false]
|
||||
{constant_true} : <formula> : [const_true]
|
||||
{negation} : <formula> : [not] <formula>
|
||||
{conjunction} : <formula> : <formula> [and] <formula>
|
||||
{disjunction} : <formula> : <formula> [or] <formula>
|
||||
{priorised} : <formula> : [open] <formula> [close]
|
||||
|
||||
<formula>
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
{
|
||||
"version": "1",
|
||||
"lexer_rules": [
|
||||
{
|
||||
"type": "ignore",
|
||||
"parameters": {
|
||||
"pattern": " |\\t|\\n"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"parameters": {
|
||||
"pattern": "false|0",
|
||||
"id": "const_false"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"parameters": {
|
||||
"pattern": "true|1",
|
||||
"id": "const_true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "void",
|
||||
"parameters": {
|
||||
"pattern": "¬|-|\\!|not",
|
||||
"id": "not"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "void",
|
||||
"parameters": {
|
||||
"pattern": "∧|&|and",
|
||||
"id": "and"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "void",
|
||||
"parameters": {
|
||||
"pattern": "∨|\\||or",
|
||||
"id": "or"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "void",
|
||||
"parameters": {
|
||||
"pattern": "\\(|\\[",
|
||||
"id": "open"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "void",
|
||||
"parameters": {
|
||||
"pattern": "\\)|\\]",
|
||||
"id": "close"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser_rules": [
|
||||
{
|
||||
"label": "constant_false",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "terminal", "parameters": {"id": "const_false"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "constant_true",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "terminal", "parameters": {"id": "const_true"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "negation",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "terminal", "parameters": {"id": "not"}},
|
||||
{"type": "variable", "parameters": {"id": "formula"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "conjunction",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "variable", "parameters": {"id": "formula"}},
|
||||
{"type": "terminal", "parameters": {"id": "and"}},
|
||||
{"type": "variable", "parameters": {"id": "formula"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "disjunction",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "variable", "parameters": {"id": "formula"}},
|
||||
{"type": "terminal", "parameters": {"id": "or"}},
|
||||
{"type": "variable", "parameters": {"id": "formula"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "priorised",
|
||||
"premise": "formula",
|
||||
"conclusion": [
|
||||
{"type": "terminal", "parameters": {"id": "open"}},
|
||||
{"type": "variable", "parameters": {"id": "formula"}},
|
||||
{"type": "terminal", "parameters": {"id": "close"}}
|
||||
]
|
||||
}
|
||||
],
|
||||
"parser_start": "formula"
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
## Usage
|
||||
|
||||
- `echo '0&1' | build/type2 examples/logic/logic.tp2.json`
|
||||
- `echo 'not (false and true)' | build/type2 examples/logic/logic.tp2.json | examples/logic/eval`
|
||||
- `cat logic.tp2 | ../../tools/convert > /tmp/logic.tp2.json`
|
||||
- `echo '0&1' | type2 /tmp/logic.tp2.json`
|
||||
- `echo 'not (false and true)' | type2 /tmp/logic.tp2.json | ./eval`
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue