I want to verify if each method MyFunction()
started with a comment. So I generated a parser by Javacc via the production rules.
extrait of jj file :
// here the comments of MyFunction()
void MyFunction : {}
{
<begin> <id> "(" (Argument ())* ")" {}
(Statement ()) *
<end>
}
void Argument:{}
{
<STRING> id
<STRING> id
}
void statement () {}
{
..........
}
how I can use regular expression to verifiy if existing comments before declaration of MyFunction()
in program source in input file stream.
What you could do is treat comments as special tokens. Special tokens are not passed on to the parser, but they are accessible from the next regular token.
Suppose comments are special tokens, spaces are skipped, and your input is
The each token has a
.next
pointer (to the right in the picture) and a.specialToken
pointer (down in the picture). (null pointers not shown.)So what you can do is look at the first token of your method. Was it preceded by a special token? And, if so, was that special token a comment?