を解析してantlr4とプリプロセッサ行を取得します私はCコードを解析するAntlr4を使用していますが、私が解析し、次の文法を使用しています:Cコード
デフォルトで上記の文法は、任意の解析規則を提供していません。プリプロセッサステートメントを取得します。
私は次の行に
externalDeclaration
: functionDefinition
| declaration
| ';' // stray ;
| preprocessorDeclaration
;
preprocessorDeclaration
: PreprocessorBlock
;
PreprocessorBlock
: '#' ~[\r\n]*
-> channel(HIDDEN)
;
を追加することによって、プリプロセッサの行を取得するには、わずかに文法を変更し、Javaで、私は方法があるプリプロセッサライン
@Override
public void enterPreprocessorDeclaration(PreprocessorDeclarationContext ctx) {
System.out.println("Preprocessor Directive found");
System.out.println("Preprocessor: " + parser.getTokenStream().getText(ctx));
}
を取得するには、次のリスナーを使用しています誘発されなかった誰かがプリプロセッサの行を取得する方法を提案することはできますか?
入力:
#include <stdio.h>
int k = 10;
int f(int a, int b){
int i;
for(i = 0; i < 5; i++){
printf("%d", i);
}
}
与えられたリンクに文法があります。 –
少なくとも#1から始まる解析行を入力してください。 – BernardK
#include int main(){ int a = 5; } –