Skip to content

Commit 2808db1

Browse files
committed
Merge branch 'master' of github.com:Submitty/submitty.github.io
2 parents f063fc3 + 8d3e03f commit 2808db1

File tree

2 files changed

+154
-21
lines changed

2 files changed

+154
-21
lines changed

_docs/instructor/commonAST.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: commonAST
3+
category: Instructor
4+
order: 9
5+
---
6+
7+
commonast.py is a static analysis tool to count different programming language constructs.
8+
The tool functions in two modes: **count mode** and **print mode**
9+
10+
### Count Mode
11+
12+
```
13+
python commonast.py lang nodeType arg filename1 filename2 .... filenamen
14+
```
15+
will output the number of ```nodeType```s 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.
16+
17+
Supported ```lang```s:
18+
* -py
19+
* -cpp
20+
21+
22+
Supported ```nodeType```s:
23+
* -For counts the number of for loops
24+
* Supported args:
25+
* -Void
26+
27+
* -While counts the number of while loops
28+
* Supported args:
29+
* -Void
30+
31+
* -Call counts the number of calls (of a certain name or just calls in general)
32+
* Supported args:
33+
* -Void
34+
* Specific call name that we want to count (example: only count the number of calls to print)
35+
36+
(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)
37+
38+
You can count nodes on any number of filenames. The number returned will be the sum number of nodeTypes in all of the filenames.
39+
40+
### Print Mode
41+
42+
```
43+
python commonast.py outputOption lang filename
44+
```
45+
46+
Supported ```outputOption```s:
47+
* -json or -JSON
48+
49+
### Example Calls:
50+
51+
```Python commonast.py -py –For -Void hw1.py ```
52+
Counts the number of for loops in hw1.py
53+
54+
```Python commonast.py -py –Call check1 hw1.py ```
55+
Counts the number of calls to the function "check1" in hw1.py. Function "check1" may or may not exist in hw1.py
56+
57+
```Python commonast.py -json -cpp hw1.cpp ```
58+
Prints a json representation of the AST of hw1.cpp
59+
60+
61+
### Additional Install Steps:
62+
Running this on python files will work with the standard submitty install. In order to run this on C++ files, there are some additional install steps:
63+
1. navigate to ```/usr/local/submitty/GIT_CHECKOUT_SUBMITTY/.setup```
64+
2. run ```git checkout commonAST``` to switch to the correct branch
65+
3. run ```python clangInstall.py``` This could take a few hours
66+
4. navigate to ```/usr/local/submitty/GIT_CHECKOUT_AnalysisTools/```
67+
5. run ```git checkout commonASTInitial``` to switch to the correct branch
68+
6. run ```sudo /usr/local/submitty/.setup/INSTALL_SUBMITTY.sh``` to complete the installation

_docs/instructor/static_analysis.md

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ given assignment, supplying the type of feature to count, the feature itself,
1717
any number of source files, and optional configuration flags. For example:
1818

1919
```
20-
"submitty_count --language python call print *.py"
20+
submitty_count --language python call print *.py
2121
```
2222

2323
_Note: `submitty_count` is an alias for a program installed on the
@@ -32,7 +32,7 @@ This example will output the number of calls to the function ``print`` in all
3232
of the Python source files in the current directory. Another example:
3333

3434
```
35-
"submitty_count -l c token Goto main.cpp"
35+
submitty_count -l c token Goto main.cpp
3636
```
3737

3838
This second example will output the number of occurrences of the token ``goto`` in the
@@ -48,7 +48,88 @@ ___
4848

4949
## Countable Features
5050
Currently, three feature types can be counted: tokens, nodes, and function calls.
51+
The countable features contained in a given file can be identified using ``submitty_diagnostics``, for example as follows:
5152

53+
```
54+
/usr/local/submitty/SubmittyAnalysisTools/diagnostics -l python file.py
55+
```
56+
57+
This tool outputs JSON data by default.
58+
An interactive view of the data can be produced by specifying HTML format:
59+
60+
```
61+
/usr/local/submitty/SubmittyAnalysisTools/diagnostics -l python --format html file.py
62+
```
63+
64+
For example, if you would like to count additions, but are unsure of which token to count, you could use a test file like:
65+
66+
```
67+
# file.py
68+
print(1 + 1)
69+
```
70+
71+
Running `/usr/local/submitty/SubmittyAnalysisTools/diagnostics -l python file.py` on this file will produce the following output:
72+
73+
```
74+
{
75+
"/absolute/path/to/file.py": {
76+
"tokens": [
77+
{
78+
"end_col": 6,
79+
"token": "Identifier",
80+
"start_line": 2,
81+
"start_col": 1,
82+
"end_line": 2
83+
},
84+
{
85+
"end_col": 7,
86+
"token": "LeftParen",
87+
"start_line": 2,
88+
"start_col": 6,
89+
"end_line": 2
90+
},
91+
{
92+
"end_col": 8,
93+
"token": "IntegerLiteral",
94+
"start_line": 2,
95+
"start_col": 7,
96+
"end_line": 2
97+
},
98+
{
99+
"end_col": 10,
100+
"token": "Plus",
101+
"start_line": 2,
102+
"start_col": 9,
103+
"end_line": 2
104+
},
105+
{
106+
"end_col": 12,
107+
"token": "IntegerLiteral",
108+
"start_line": 2,
109+
"start_col": 11,
110+
"end_line": 2
111+
},
112+
{
113+
"end_col": 13,
114+
"token": "RightParen",
115+
"start_line": 2,
116+
"start_col": 12,
117+
"end_line": 2
118+
}
119+
],
120+
"nodes" : { ... node data here ... }
121+
}
122+
}
123+
```
124+
125+
The ``token`` fields specify tokens that can be given to ``submitty_count``.
126+
Notice that a token ``Plus`` is present between two ``IntegerLiteral`` tokens.
127+
You could verify that this is the right token by looking at the ``start_line``, ``end_line``, ``start_col``, and ``end_col`` fields, which indicate on what row and column the tokens begin and end within the file.
128+
Once you are sure that the token is correct, you could count it within student submissions with ``submitty_count``:
129+
130+
```
131+
submitty_count -l python *.py
132+
```
52133

53134
### Tokens
54135

@@ -107,12 +188,6 @@ should be the first tool considered when writing an assignment that
107188
requires static analysis. Only seek out more advanced options when
108189
necessary.
109190

110-
__TODO: Insert instructions to produce the intermediate tokens so the
111-
instructor user can experiment.__
112-
113-
__TODO: Insert link to list of valid tokens that can counted.__
114-
115-
116191
### Nodes
117192

118193
The next level of analysis enables counting _nodes_ within a parse tree, which
@@ -146,15 +221,15 @@ what kind of literal is present. This enables the counting of
146221
specific classes of node. For example:
147222

148223
```
149-
"submitty_count -l python literal *.py"
224+
submitty_count -l python literal *.py
150225
```
151226

152227
If run upon the code fragment from the start of this section, this will yield 3,
153228
counting all literals used within the code. Contrast:
154229
which will return `3`. In contrast:
155230

156231
```
157-
"submitty_count -l python integer *.py"
232+
submitty_count -l python integer *.py
158233
```
159234

160235
will return `2`, as it will only count the integer literals.
@@ -169,12 +244,6 @@ counting approach. However, these features have different nodes in the parse
169244
tree, so by counting nodes with certain tags it is possible to easily
170245
distinguish them.
171246

172-
__TODO: Insert instructions to produce a human readable version of the
173-
parse tree so the instructor user can experiment.__
174-
175-
__TODO: Insert link to valid tags (& nodes?) that can counted.__
176-
177-
178247
### Function Calls
179248

180249
This method is a bit higher level: it attempts via a language-dependent method
@@ -185,9 +254,5 @@ method at RPI is determining the number of calls to the ``print`` function
185254
present in Python code, for example:
186255

187256
```
188-
"submitty_count call print -l py *.py"
257+
submitty_count call print -l py *.py
189258
```
190-
191-
__TODO: Insert instructions to produce a human readable version of the
192-
functions found in a specific program(?) so the instructor user can experiment.__
193-

0 commit comments

Comments
 (0)