Skip to content
KristofferHolmsPublic

About

Computer Science Project 4. Semester

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Algorithm Frame Script (using CoCo/R)

A parser built for Algorithm Frame Script (AFS) using CoCo/R. Language specification can be found in CocoR/AFS.ATG.

Project Structure

  • src/main/java/afs/nodes: Here are folders for each syntactic category in the abstract syntax of AFS.
    • There is a node (class) for each rule in each syntactic category.
    • All nodes inherit from the abstract class AbstractSyntaxNode
      • For each syntactic category, there is an abstract class that inherit from AbstractSyntaxNode, all nodes in the syntactic category inherit from this class (e.g., all nodes representing statements inherit from StatementNode).
    • Nodes contain only references to their sub nodes (e.g., an ExprBinopNode representing $e_{1} \star e_{2}$ will include a reference left and right expression).
    • There are some helper classes that are not directly in the abstract syntax (e.g. Param).
  • src/main/java/afs/Main.java: This class is the main entry point to the AFS parser.
  • src/main/java/afs/astprinter/PrinterInterface.java: Defines an interface implemented by classes that want to print the abstract syntax tree.
  • src/main/java/afs/astprinter/RecursiveGraphvizPrinter.java: Prints the abstract syntax tree using DOT notation (requires Graphviz or DOT language plugin).
  • src/main/java/afs/semantic_analysis: This folder includes type checker and return system implementation
  • src/main/java/afs/interpreter: Includes all classes part of the interpreter implementation.
  • src/main/java/afs/SVGGenerator: Includes the classes used for generating SVG images.

Requirements

  • Java JDK 21
  • Gradle (use the included gradlew wrapper)
  • Coco/R (included in the CocoR/ directory)
  • Graphviz for printing the syntax tree as an image (optional)

Usage

Generating parser and scanner

  • The parser and scanner (lexer) can be generated running the shell script CocoR/cocoR.sh (Linux and Mac) or the bash script CocoR/cocR.bat or by running the CocoR/Coco.jar directly.
    • This generates a parser and scanner. By default, the parser is placed in src/main/java/afs/syntactic_analysis/. This can be changed by changing the input parameters.
  • The parser and scanner can also be generated by running ./gradlew clean build. This also builds the AFS.jar file.

Running AFS with an input file

  • Once AFS.jar file has been generated, it can either be run directly or through the shell scrip afs.sh (Linux and Mac) or the bash script afs.bat (Windows).
  • Usage is AFS <filename> <outputfile> [--print <outputfile>] [--w <width>] [--h <height>].
    • If the --print flag is specified, an outputfile must be provided.
    • There is a Gradle task that runs the shell/bash script ./gradlew runAFS.
  • The shell and bash scripts are set to run it with a default filename intput.txt and output file output.dot
  • Running the program results in a series of SVG images defined by the AFS program.
  • If --print was used, a picture can be compiled with dot -Tpng output.dot -o output.png or with a DOT language plugin the picture can be generated automatically when opening the output.dot file.
    • Running the terminal command requires Graphviz to be installed

About

Computer Science Project 4. Semester

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages