[mod] example:logic

This commit is contained in:
Christian Fraß 2022-03-20 14:39:35 +01:00
parent 90be104103
commit a7d1f9cb64
2 changed files with 18 additions and 10 deletions

View file

@ -6,8 +6,10 @@ import json as _json
def evaluate(node):
# _sys.stderr.write("eval: %s\n" % _json.dumps(node))
if (node["label"] == "constant"):
return node["value"][0]["data"]["value"]
if (node["label"] == "constant_false"):
return False
elif (node["label"] == "constant_true"):
return True
elif (node["label"] == "negation"):
return (not evaluate(node["children"][0]))
elif (node["label"] == "conjunction"):

View file

@ -1,4 +1,5 @@
{
"version": "1",
"lexer_rules": [
{
"type": "ignore",
@ -7,19 +8,17 @@
}
},
{
"type": "boolean",
"type": "string",
"parameters": {
"pattern": "false|0",
"id": "const",
"value": false
"id": "const_false"
}
},
{
"type": "boolean",
"type": "string",
"parameters": {
"pattern": "true|1",
"id": "const",
"value": true
"id": "const_true"
}
},
{
@ -60,10 +59,17 @@
],
"parser_rules": [
{
"label": "constant",
"label": "constant_false",
"premise": "formula",
"conclusion": [
{"type": "terminal", "parameters": {"id": "const"}}
{"type": "terminal", "parameters": {"id": "const_false"}}
]
},
{
"label": "constant_true",
"premise": "formula",
"conclusion": [
{"type": "terminal", "parameters": {"id": "const_true"}}
]
},
{