I would like to define a set of coding rules of a language structural proprietary language,
how can I proceed? thank you very much
I would like to define a set of coding rules of a language structural proprietary language,
how can I proceed? thank you very much
Some of your rules will be easy to deal with using only parsing. For example to find the number of lines in a function is not hard:
void function() : {
int firstLine, lastLine ; }
{
{firstLine = getToken(1).beginLine ; }
...
{lastLine = getToken(0).beginLine ; }
{check( lastLine - firstLine + 1 <= 150 ) ; }
}
Other rules, such as your example of nested ifs, will be best handled by traversing an abstract syntax tree. I'd suggest you look into JJTree. It supports visitors, which could be quite useful for encoding some of your rules.
If I have understood correctly, in the file .jj, I have to add this function , which allows to check how many line of code in a method
or in the file parseur.java generated by javacc.