Add example algorithm

This commit is contained in:
Юлия Строева 2023-06-16 18:35:59 +04:00
parent a7c2be61c8
commit 90f29a6188
15 changed files with 79 additions and 16 deletions

BIN
images/ASTClass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
images/ASTCondition.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
images/ASTConditionEx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
images/ASTField.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
images/ASTFinish.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

BIN
images/ASTLoop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
images/ASTLoopField.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
images/ASTMetArgs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
images/ASTMethod1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
images/ASTMethod2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
images/ExampleAST.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

BIN
paper.pdf

Binary file not shown.

View File

@ -113,53 +113,116 @@ We developed an algorithm to extract the structure of the project in the source
N^{Class} = \lbrace N_{i} \in N | F \left( N_{i}.data \right) = \text{`Class'} \rbrace,
\end{equation*}
\begin{table}[]
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
public class Main \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTClass.png}} \\ \hline
\end{tabular}
\end{table}
\item Select nodes with the `Class field' as the $N^{Vars}$ set from the $N^{Class}$ set:
\begin{equation*}
N^{Vars} = \lbrace N_{i}^{Class} \in N^{Class} | F \left( N_{i}^{Class}.data \right) = \text{`Field'} \rbrace,
\end{equation*}
\begin{table}[]
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
private String a; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTField.png}} \\ \hline
\end{tabular}
\end{table}
\item Select nodes with the `Methods' type as the $N^{Methods}$ set from the $N^{Class}$ set:
\begin{equation*}
N^{Methods} = \lbrace N_{i}^{Class} \in N^{Class} | F \left( N_{i}^{Class}.data \right) = \text{`Method'} \rbrace,
\end{equation*}
\begin{table}[]
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
void run() \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMethod1.png}} \\ \hline
void show(String text) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMethod2.png}} \\ \hline
\end{tabular}
\end{table}
\item Select nodes with the `Method Argument' type as the $N^{MethodsArgs}$ set from the $N^{Methods}$ set:
\begin{equation*}
N^{MethodsArgs} = \lbrace N_{i}^{Methods} \in N^{Methods} | F \left( N_{i}^{Methods}.data \right) = \text{`Arg'} \rbrace,
\end{equation*}
\begin{table}[]
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
void show(String text) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMetArgs.png}} \\ \hline
\end{tabular}
\end{table}
\item Select nodes with the `Operator' type as the $N^{MethodsOps}$ from the $N^{Methods}$ set:
\begin{equation*}
N^{MethodsOps} = \lbrace N_{i}^{Methods} \in N^{Methods} | F \left( N_{i}^{Methods}.data \right) = \text{`Operator'} \rbrace,
\end{equation*}
\begin{table}[]
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
while(true) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTLoop.png}} \\ \hline
int a = 1; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTLoopField.png}} \\ \hline
if (a == 1) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTCondition.png}} \\ \hline
this.show("Hello") & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTConditionEx.png}} \\ \hline
int c = "Foo"; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTConditionField.png}} \\ \hline
System.out.println(text); & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTFinish.png}} \\ \hline
\end{tabular}
\end{table}
\item Create the set of ties $R$ between the nodes from sets obtained in previous steps.
\item Save the resulting AST in a graph database (GDB).
\end{enumerate}
In this algorithm, F (*) is a search function that finds nested nodes. The function input is a node or subtree, and the output is a node of the desired type.
Figure \ref{fig:SourceCodeAndAST} shows the resulting AST for the following source code:
Figure 1\ref{fig:ExampleAST} shows the resulting ACT for the following source code:
\begin{lstlisting}
package com.example.demo.simple;
public class Main {
private String a;
void run() {
while(true) {
int a = 1;
if (a == 1) {
this.show("Hello")
}
package laba1;
public class Scheduler {
private final int time = 5;
private ArrayList<Thread> threads = new ArrayList<Thread>();
void scheduler() {
for (int i=0; i<threads.size(); i++) {
threads.get(i).run(time);
System.out.println(threads.get(i).toString());
}
int c = "Foo";
}
void show(String text) {
System.out.println(text);
}
\end{lstlisting}
This source code looks different, but the AST is the same:
\begin{lstlisting}
package os-lab-1;
public class Planing {
private final int QUANT = 10;
private List<Stream> streams = new ArrayList<>();
void plan() {
for (Stream stream: streams) {
stream.run(QUANT);
System.out.println(stream.toString());
}
}
}
\end{lstlisting}
\begin{figure}
\centering
\includegraphics[width=0.71\textwidth]{images/AST.png}
\caption{Sample source code and its AST.} \label{fig:SourceCodeAndAST}
\includegraphics[width=0.71\textwidth]{images/ExampleAST.png}
\caption{Sample AST.} \label{fig:ExampleAST}
\end{figure}