A parser built for Algorithm Frame Script (AFS) using CoCo/R. Language specification can be found in CocoR/AFS.ATG.
-
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 fromStatementNode).
- For each syntactic category, there is an abstract class that inherit from
- 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.
- Java JDK 21
- Gradle (use the included
gradlewwrapper) - Coco/R (included in the
CocoR/directory) - Graphviz for printing the syntax tree as an image (optional)
- The parser and scanner (lexer) can be generated running the shell script
CocoR/cocoR.sh(Linux and Mac) or the bash scriptCocoR/cocR.bator by running theCocoR/Coco.jardirectly.- 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.
- This generates a parser and scanner. By default, the parser is placed in
- The parser and scanner can also be generated by running
./gradlew clean build. This also builds theAFS.jarfile.
- Once
AFS.jarfile has been generated, it can either be run directly or through the shell scripafs.sh(Linux and Mac) or the bash scriptafs.bat(Windows). - Usage is
AFS <filename> <outputfile> [--print <outputfile>] [--w <width>] [--h <height>].- If the
--printflag is specified, an outputfile must be provided. - There is a Gradle task that runs the shell/bash script
./gradlew runAFS.
- If the
- The shell and bash scripts are set to run it with a default filename
intput.txtand output fileoutput.dot - Running the program results in a series of SVG images defined by the AFS program.
- If
--printwas used, a picture can be compiled withdot -Tpng output.dot -o output.pngor with a DOT language plugin the picture can be generated automatically when opening theoutput.dotfile.- Running the terminal command requires Graphviz to be installed