我为ParseKit写了一个C语法,它完美地工作,但令我发疯的是预处理语句。预处理器语句的正确符号定义是什么?ParseKit - 如何正确处理预处理器语句?
这里是什么,我已经试过了简单的例子...
@reportsCommentTokens = YES;
@commentState = '/';
@singleLineComments = '//';
@multiLineComments = '/*' '*/';
@commentState.fallbackState = delimitState;
@delimitState.fallbackState = symbolState;
@start = Empty | comments | preprocessor;
comments = comment*;
comment = Comment;
@symbols = '#include';
preprocessor = preprocessorIncludes;
preprocessorIncludes = preprocessorIncludeStatement*;
preprocessorIncludeStatement = preprocessorInclude quotedFileName*;
preprocessorInclude = '#include';
quotedFileName = QuotedString;
...但它不工作。将其作为简化的语法示例来捕获注释并包含带引号的语句(不适用于<>)。我试过这个语法上这个简单的文件...
/*
* Cryptographic API.
*
* RIPEMD-256 - RACE Integrity Primitives Evaluation Message Digest.
*
* Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
*
* Copyright (c) 2008 Adrian-Ken Rueegsegger <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
// Here's one line comment
/* One line multiline comment */
#include "ripemd.h"
/* 2nd one line multiline comment */
...它在/结束*一号线多行注释* /,报告为注释标记,然后它静静地失败。
所以我试图分开 '的#include' 符号......
@symbolState = '#' '#';
@symbol = '#';
numSymbol = '#';
preprocessorInclude = numSymbol 'include';
...但它仍然没有帮助。
也许Todd可以提供帮助,但是处理像'#include'这样的符号的正确方法是什么?
“*我不能完全肯定,但我不认为这是唯一的ParseKit问题*”不是。第一条规则使语法不是LL1语法,这意味着没有上下文无关递归下降解析器可以解析它。 – JeremyP 2012-07-16 18:56:22
托德,非常感谢!我试图弄清楚语法有什么问题,我正在创造很多变化,没有一个是它的工作,这一个是最后的混乱:(再次感谢。 – robertvojta 2012-07-16 20:01:02