验证每个函数是否以注释开头并验证此注释是否包含保留字 words.comments 包含保留字
verify if each function started with a comment and verify if this comments contains reserved words.comments contains reserved words
我检查了每个函数 Function()
是否以输入文件流中的注释开头。这就像:
SKIP : { " " | "\t" | "\n" | "\r" }
/* COMMENTS */
SPECIAL_TOKEN : { <SINGLE_LINE_COMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> }
void Function : {
Token firstToken, id;} {
firstToken=<start> id=<id> "(" ")"
.........
<end>
{ if( firstToken.specialToken == null
|| firstToken.specialToken.kind != COMMENT )
System.out.println("Function " +id.image+
" is not preceded by a comment!" ) ;
} }
所以,我想验证一下这条评论是否包含保留字
提前致谢。
如果你只是想知道评论是否包含给定的词,你不妨使用Java的字符串搜索机制。假设您想知道函数定义之前的注释中的单词 "bandersnatch" 是否为
void Function() : {
Token firstToken, id;}
{
firstToken=<start> id=<id> "(" ")"
.........
<end>
{ if( firstToken.specialToken == null
|| firstToken.specialToken.kind != COMMENT )
System.out.println("Function " +id.image+
" is not preceded by a comment!" ) ;
else {
String comment = firstToken.specialToken.image ;
boolean hasBandersnatch = comment.indexOf("bandersnatch") != -1 ; if( ! hasBandersnatch )
System.out.println("Function " +id.image+
" is preceded by a comment that does not contain 'bandersnatch'!" ) ; }
}
}
如果您希望搜索不区分大小写,请更改 comment
的初始化。
String comment = firstToken.specialToken.image.toLower() ;
我检查了每个函数 Function()
是否以输入文件流中的注释开头。这就像:
SKIP : { " " | "\t" | "\n" | "\r" }
/* COMMENTS */
SPECIAL_TOKEN : { <SINGLE_LINE_COMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> }
void Function : {
Token firstToken, id;} {
firstToken=<start> id=<id> "(" ")"
.........
<end>
{ if( firstToken.specialToken == null
|| firstToken.specialToken.kind != COMMENT )
System.out.println("Function " +id.image+
" is not preceded by a comment!" ) ;
} }
所以,我想验证一下这条评论是否包含保留字
提前致谢。
如果你只是想知道评论是否包含给定的词,你不妨使用Java的字符串搜索机制。假设您想知道函数定义之前的注释中的单词 "bandersnatch" 是否为
void Function() : {
Token firstToken, id;}
{
firstToken=<start> id=<id> "(" ")"
.........
<end>
{ if( firstToken.specialToken == null
|| firstToken.specialToken.kind != COMMENT )
System.out.println("Function " +id.image+
" is not preceded by a comment!" ) ;
else {
String comment = firstToken.specialToken.image ;
boolean hasBandersnatch = comment.indexOf("bandersnatch") != -1 ; if( ! hasBandersnatch )
System.out.println("Function " +id.image+
" is preceded by a comment that does not contain 'bandersnatch'!" ) ; }
}
}
如果您希望搜索不区分大小写,请更改 comment
的初始化。
String comment = firstToken.specialToken.image.toLower() ;