commonast.py is a static analysis tool to count different programming language constructs. The tool functions in two modes: count mode and print mode

Count Mode

python commonast.py lang nodeType arg filename1 filename2 .... filenamen 

will output the number of nodeTypes under the argument arg in the source file filename which is written in language lang. It will also output valuable information about the AST depending on the outputOption.

Supported langs:

Supported nodeTypes:

(The infrastructure is there to count many more nodes. I’m only adding them to this once they’ve been tested against Sam’s tool to make sure they’re correct)

You can count nodes on any number of filenames. The number returned will be the sum number of nodeTypes in all of the filenames.

python commonast.py outputOption filename lang

Supported outputOptions:

Example Calls:

Python commonast.py -py –For -Void hw1.py Counts the number of for loops in hw1.py

Python commonast.py -py –Call check1 hw1.py Counts the number of calls to the function “check1” in hw1.py. Function “check1” may or may not exist in hw1.py

Python commonast.py -json -cpp hw1.cpp Prints a json representation of the AST of hw1.cpp