syntactically correct but semantically wrong constructs statically. This could mean
things in the BNF like stmt: expr op expr which can match semantically wrong constructs
due to compile time invisibily/scoping issues as in x = x + 1 . This statement is wrong
because variable x is un-initialized. So such errors can be discovered using Octave-lint, when someone writes it.
Essentially a bare-bones algorithms would involve
- Parse the file & report errors if any.
- If no errors, start the (Left-Right-Root) post-order traversal, of the AST.
- At each visitor try and note down order of variables into a static table.
- Note down variable creation
- Flag suspicious variables
- Flag undefined variables
- Flag possible 'typos' of variables by Levenshtein distance of the misspelt / undefined variable name with variables on the table. Min of this metric must give us a possible suggestion for the wrong typo variable.
- Have more heuristic error cases to be trapped in the visitor, based on static tables.
- Finally the collected errors/warnings are reported to user, based on input options.
- Additional tuning can be done to run Lint on a set of files, with functions defined elsewhere, and rules for specific usage.
I think this would make a really nice project for someone who wants to learn C++ basics and hack on a real piece of software. It would be a great first-dip into the Free Software Ocean.
Cheers,
Muthu
No comments:
Post a Comment