我收到 Tatsu 错误
“tatsu.exceptions.FailedExpectingEndOfText: (1:1) 期望文本结束”
使用我提供的语法运行测试 - 目前尚不清楚问题是什么。
本质上,调用解析器的语句是:
ast = parse(GRAMMAR, '(instance ?FIFI Dog)')
整个python文件如下:
GRAMMAR = """
@@grammar::SUOKIF
KIF = {KIFexpression}* $ ;
WHITESPACE = /\s+/ ;
StringLiteral = /['"'][A-Za-z]+['"']/ ;
NumericLiteral = /[0-9]+/ ;
Identifier = /[A-Za-z]+/ ;
LPAREN = "(" ;
RPAREN = ")" ;
QUESTION = "?" ;
MENTION = "@" ;
EQUALS = "=" ;
RARROW = ">" ;
LARROW = "<" ;
NOT = "not"|"NOT" ;
OR = "or"|"OR" ;
AND = "and"|"AND" ;
FORALL = "forall"|"FORALL" ;
EXISTS = "exists"|"EXISTS" ;
STRINGLITERAL = {StringLiteral} ;
NUMERICLITERAL = {NumericLiteral} ;
IDENTIFIER = {Identifier} ;
KIFexpression
= Word
| Variable
| String
| Number
| Sentence
;
Sentence = Equation
| RelSent
| LogicSent
| QuantSent
;
LogicSent
= Negation
| Disjunction
| Conjunction
| Implication
| Equivalence
;
QuantSent
= UniversalSent
| ExistentialSent
;
Word = IDENTIFIER ;
Variable = ( QUESTION | MENTION ) IDENTIFIER ;
String = STRINGLITERAL ;
Number = NUMERICLITERAL ;
ArgumentList
= {KIFexpression}*
;
VariableList
= {Variable}+
;
Equation = LPAREN EQUALS KIFexpression KIFexpression RPAREN ;
RelSent = LPAREN ( Variable | Word ) ArgumentList RPAREN ;
Negation = LPAREN NOT KIFexpression RPAREN ;
Disjunction
= LPAREN OR ArgumentList RPAREN
;
Conjunction
= LPAREN AND ArgumentList RPAREN
;
Implication
= LPAREN EQUALS RARROW KIFexpression KIFexpression RPAREN
;
Equivalence
= LPAREN LARROW EQUALS RARROW KIFexpression KIFexpression RPAREN
;
UniversalSent
= LPAREN FORALL LPAREN VariableList RPAREN KIFexpression RPAREN
;
ExistentialSent
= LPAREN EXISTS LPAREN VariableList RPAREN KIFexpression RPAREN
;
"""
if __name__ == '__main__':
import pprint
import json
from tatsu import parse
from tatsu.util import asjson
ast = parse(GRAMMAR, '(instance ?FIFI Dog)')
print('# PPRINT')
pprint.pprint(ast, indent=2, width=20)
print()
print('# JSON')
print(json.dumps(asjson(ast), indent=2))
print()
任何人都可以帮我解决问题吗?
谢谢。
科林·戈德堡