Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Structure for Abstract Syntax Trees #50

Open
pmbittner opened this issue Dec 3, 2020 · 0 comments · Fixed by #63
Open

Data Structure for Abstract Syntax Trees #50

pmbittner opened this issue Dec 3, 2020 · 0 comments · Fixed by #63

Comments

@pmbittner
Copy link
Collaborator

For new research projects, we have to abstract from software projects to be able to compare variants and their code fragments.
Therefore, as a first step we want to represent projects and software artefacts in a tree structure.
The following is a first draft for how such an abstract syntax tree (AST) structure could look like:

class AST<Grammar, Value> {
    int UUID;
    Grammar type;
    Value value;
    List<AST<Grammar, Value>> children = new ArrayList<>();

    /// getters, setters, and utility methods here
}

where a Grammar would be an enum over grammar symbols of for example Java or C++ grammar.
The grammar, this describes the type of a node in the tree.

For now, the goal is to stick to a line-based structure such as used in git diff.
Thus, an initial grammar would be:

public enum LineGrammar {
    Directory, File, Line
}

Thus, we would distinguish between directories, files and lines of source code in that file.
For example, the following would be the way to construct a tree for a java Hello World program manually:

AST<LineGrammar, String> srcDir = new AST<>(LineGrammar.Directory, "src");
AST<LineGrammar, String> mainJava = new AST<>(LineGrammar.File, "Main.java");
srcDir.children.add(mainJava);
mainJava.children.addAll(Arrays.asList(
        new AST<>(LineGrammar.Line, "public class Main {"),
        new AST<>(LineGrammar.Line, "    public static void main(String[] args)"),
        new AST<>(LineGrammar.Line, "        System.out.println(\"Hello World\");"),
        new AST<>(LineGrammar.Line, "    }"),
        new AST<>(LineGrammar.Line, "}")));

This tree structure should be part of the VariantSyncCoreLibrary from issue #49.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment