我爲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