如何调试无效的ParseKit语法? [英] How to debug an invalid ParseKit Grammar?

查看:60
本文介绍了如何调试无效的ParseKit语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为ParseKit编写语法,以使其与iPhone应用程序中的基本命题逻辑语句匹配.有人可以告诉我我哪里出问题了.

I am trying to write a grammar for ParseKit so that it matches basic propositional logic sentences in an iphone app. Can someone please tell me where im going wrong.

@start = wff;
wff = disjunction (implies disjunction)?;
disjunction = conjuction (or conjuction)*;
conjunction = notExpression (and notExpression)*;
notExpression = (not | not primaryExpression);
primaryExpression = variable | lbracket wff rbracket;
variable = p | q | r;

p = 'P';
q = 'Q';
r = 'R';

implies = '→';
and = '∧';
or = '∨';
not = '¬';
lbracket = '(';
rbracket = ')';

此外,我将如何添加一些额外的回叫,以便可以从语法中创建解析树.

Also how would i go about adding some extra call backs so that I can create a parse tree from the grammar.

推荐答案

此处 ParseKit 的开发人员.

我看到一个明显的问题:conjunction在您的语法中的几个地方拼写错误.

I see one obvious problem: conjunction is misspelled in a couple of places in your grammar.

ParseKit的语法分析器的错误消息不是最大的错误.理想情况下,您会收到一条很好的错误消息,提示您该问题(但是,嘿,它是开源的,因此欢迎任何人提供这种性质的修复程序).

ParseKit's Grammar Parser's error messages are not the greatest. Ideally, you would receive a nice error message leading you to the problem (but, hey it's open source so anyone is welcome to contribute a fix of this nature).

但是,我可以告诉您如何找到这些问题:

However, I can tell you how I find these issues:

  1. 将您的ParseKit工作副本更新到 Google代码主干的开头.
  2. 在Xcode中,打开断点并为所有异常添加一个断点
  3. 将您的ParseKit语法放在以下文件中:~/Desktop/grammar.txt
  4. (可选)在此文件中放置任何示例输入:~/Desktop/input.txt
  5. 在调试"配置中运行ParseKit DebugApp目标.
  6. 在应用运行时,在出现的窗口中单击大的Run按钮.
  7. 等待引发异常.断点被击中.
  1. Update your ParseKit working copy to head of the google code trunk.
  2. In Xcode, turn on breakpoints and add a breakpoint for all exceptions
  3. Place your ParseKit grammar in this file: ~/Desktop/grammar.txt
  4. (Optional) Place any example input in this file: ~/Desktop/input.txt
  5. Run the ParseKit DebugApp target in Debug configuration.
  6. Click the big Run button in the window that appears when the app runs.
  7. Wait for an exception to be thrown. Breakpoint is hit.

如果语法中有错误,您会发现该异常很可能发生在ParseKit汇编器回调中,例如:

If there is a bug in your grammar, you will find the exception has most likely occurred in a ParseKit Assembler callback like:

- (void)parser:(PKParser *)p didMatchExpression:(PKAssembly *)a

a打印到调试控制台.您会看到类似的内容:

print a to the debug console. You'll see something like:

(lldb) po a
(PKAssembly *) $1 = 0x00000001075a9010 [] /conjuction/ ^(/or/ /conjuction/)/*

这是传递到回调中的PKAssembly对象的打印输出.在这里,您可以看到ParseKit的语法解析器无法解析语法的位置.似乎在解析此表达式时ParseKit语法解析器失败:

This is a printout of the PKAssembly object passed into your callback. Here you can see where ParseKit's grammar parser failed to parse your grammar. It appears that the ParseKit Grammar Parser failed while parsing this expression:

conjuction (or conjuction)*;

^(插入符号)的位置,您可以在看到第一个conjuction之后立即告诉解析器被阻塞.

And from the position of the ^ (caret), you can tell the parser choked right after seeing the first conjuction.

此表达式仅位于语法的一行中:

This expression is located in just one line in your grammar:

disjunction = conjuction (or conjuction)*;

这就是我注意到此行中拼写错误的原因.

That's how I noticed that there was a misspelling in this line.

这种方法总是会导致您出现语法问题.希望有帮助.

This approach will invariably lead you to the problematic line in your grammar. Hope that helps.

这篇关于如何调试无效的ParseKit语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆