Skip to content

Commit dd18bdc

Browse files
committed
started implementation
1 parent 7007c06 commit dd18bdc

File tree

6 files changed

+971
-0
lines changed

6 files changed

+971
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.classpath
2+
/.externalToolBuilders
3+
/.project
4+
/.settings
5+
/bin
6+
/*.jar

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# XML output generator for Open Fortran Parser
2+
3+
This is an extension of Open Fortran Parser (OFP), which outputs abstract syntaxt tree (AST)
4+
in XML format - to a file or to 'System.out'.
5+
6+
7+
## dependencies
8+
9+
- Open Fortran Parser 0.8.4-1
10+
11+
https://github.com/mbdevpl/open-fortran-parser/releases/tag/v0.8.4-1
12+
13+
This is a patched version of OFP. Specifically, 'FortranParserActionPrint' class in OFP
14+
could not be properly subclassed due to access levels of members of that class, so for example
15+
writing my own printer would introduce a lot of code duplication. Patch resolves this,
16+
without affecting any functionality of the Parser.
17+
18+
The patch also resolves some issue when compiling with recent GCC versions.
19+
20+
- ANTRL 3.3 (dependency of Open Fortran Parser)
21+
22+
http://www.antlr3.org/download/
23+
24+
- Apache Commons CLI
25+
26+
https://commons.apache.org/proper/commons-cli/download_cli.cgi
27+
28+
29+
## how to run
30+
31+
32+
## AST specification
33+
34+
In progress.
35+
36+
Root node is '<ofp>', it has one subnode '<file>'.

build.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" ?>
2+
<project name="open-fortran-parser-xml" default="jar">
3+
4+
<property name="debuglevel" value="source,lines,vars" />
5+
<property name="target" value="1.8" />
6+
<property name="source" value="1.8" />
7+
8+
<property name="src.dir" value="src" />
9+
<property name="bin.dir" value="bin" />
10+
<property name="lib.dir" value="lib" />
11+
<property name="jar.name" value="OpenFortranParserXml-0.1.0.jar" />
12+
13+
<path id="ofp.classpath">
14+
<pathelement location="bin" />
15+
<!-- <pathelement location="resources" /> -->
16+
<fileset dir="${lib.dir}" includes="*.jar" />
17+
</path>
18+
19+
<target name="clean">
20+
<delete dir="${bin.dir}" />
21+
<delete file="${jar.name}" />
22+
</target>
23+
24+
<target name="init">
25+
<mkdir dir="${bin.dir}" />
26+
<copy includeemptydirs="false" todir="${bin.dir}">
27+
<fileset dir="${src.dir}">
28+
<exclude name="**/*.java" />
29+
</fileset>
30+
</copy>
31+
<copy file="LICENSE" todir="${bin.dir}" />
32+
</target>
33+
34+
<target name="build" depends="clean,init">
35+
<echo message="${ant.project.name}: ${ant.file}" />
36+
<javac debug="true" debuglevel="${debuglevel}" destdir="${bin.dir}" includeantruntime="false" source="${source}" target="${target}" encoding="UTF-8">
37+
<src path="${src.dir}" />
38+
<classpath refid="ofp.classpath" />
39+
</javac>
40+
</target>
41+
42+
<target name="jar" depends="build">
43+
<jar jarfile="${jar.name}" basedir="bin" includes="**/*.class">
44+
<manifest>
45+
<attribute name="Main-Class" value="fortran.ofp.Xml" />
46+
</manifest>
47+
</jar>
48+
</target>
49+
50+
</project>

src/fortran/ofp/ArgsParser.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package fortran.ofp;
2+
3+
import org.apache.commons.cli.CommandLine;
4+
import org.apache.commons.cli.DefaultParser;
5+
import org.apache.commons.cli.HelpFormatter;
6+
import org.apache.commons.cli.Option;
7+
import org.apache.commons.cli.Options;
8+
import org.apache.commons.cli.ParseException;
9+
10+
public class ArgsParser {
11+
12+
private Options options;
13+
14+
public ArgsParser() {
15+
options = new Options();
16+
17+
Option output = new Option(null, "output", true, "output file path, print to System.out if not provided");
18+
output.setRequired(false);
19+
options.addOption(output);
20+
21+
Option verbosity = new Option(null, "verbosity", true, "verbosity level, assume max if not provided");
22+
options.addOption(verbosity);
23+
24+
Option help = new Option(null, "help", true, "print this help message and exit");
25+
help.setRequired(false);
26+
options.addOption(help);
27+
}
28+
29+
public CommandLine parse(String... args) {
30+
DefaultParser parser = new DefaultParser();
31+
CommandLine cmd = null;
32+
try {
33+
cmd = parser.parse(options, args);
34+
} catch (ParseException e) {
35+
System.err.println(e.getMessage());
36+
}
37+
38+
if (cmd == null || cmd.hasOption("help")) {
39+
HelpFormatter formatter = new HelpFormatter();
40+
formatter.printHelp("fortran.ofp.FrontEnd --class fortran.ofp.XMLPrinter",
41+
"XML output generator for Open Fortran Parser 0.8.4-1", options,
42+
"Copyright 2017 Apache License 2.0 Mateusz Bysiek https://mbdevpl.github.io/", true);
43+
System.exit(1);
44+
return null;
45+
}
46+
47+
return cmd;
48+
}
49+
50+
}

src/fortran/ofp/Main.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package fortran.ofp;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
import org.apache.commons.cli.CommandLine;
9+
import org.apache.commons.cli.DefaultParser;
10+
import org.apache.commons.cli.HelpFormatter;
11+
import org.apache.commons.cli.Option;
12+
import org.apache.commons.cli.Options;
13+
import org.apache.commons.cli.ParseException;
14+
15+
public class Main {
16+
17+
public static void main(String args[]) throws IOException {
18+
Options options = new Options();
19+
options.addOption(null, "RiceCAF", false, "use Rice University's CAF extensions");
20+
options.addOption(null, "LOPExt", false, "use OFP's LOPe research extensions");
21+
22+
Option input = new Option("f", "file", true, "input file path");
23+
input.setRequired(true);
24+
options.addOption(input);
25+
26+
Option verbose = new Option("v", false, "verbose");
27+
options.addOption(verbose);
28+
29+
Option output = new Option("o", "output", true, "output file");
30+
output.setRequired(false);
31+
options.addOption(output);
32+
33+
DefaultParser parser = new DefaultParser();
34+
CommandLine cmd = null;
35+
try {
36+
cmd = parser.parse(options, args);
37+
} catch (ParseException e) {
38+
System.out.println(e.getMessage());
39+
}
40+
41+
if (cmd == null || cmd.hasOption("help")) {
42+
HelpFormatter formatter = new HelpFormatter();
43+
formatter.printHelp("open-fortran-parser-xml [options] file", options);
44+
System.exit(1);
45+
return;
46+
}
47+
48+
System.out.println(cmd.getArgList().toString());
49+
System.out.println(Arrays.asList(cmd.getOptions()).toString());
50+
51+
String inputFilePath = cmd.getOptionValue("file");
52+
String outputFilePath = cmd.getOptionValue("output");
53+
54+
System.out.println(inputFilePath);
55+
System.out.println(outputFilePath);
56+
57+
List<String> ofpArgs = new ArrayList<String>();
58+
if (cmd.hasOption("RiceCAF"))
59+
ofpArgs.add("--RiceCAF");
60+
if (cmd.hasOption("LOPExt"))
61+
ofpArgs.add("--LOPExt");
62+
String[] ofpArgsArray = ofpArgs.toArray(new String[ofpArgs.size()]);
63+
64+
String type = "fortran.ofp.XMLPrinter";
65+
FrontEnd ofp = new FrontEnd(ofpArgsArray, cmd.getOptionValue("file"), type);
66+
ofp.setVerbose(cmd.hasOption("verbose"), null);
67+
// TODO: incomplete implementation
68+
}
69+
70+
}

0 commit comments

Comments
 (0)