From 85e2726ddedd2981425c5ac07f7257bce1a6ddbf Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 1 Nov 2021 14:51:47 +0000 Subject: started work on translation to c --- code/FORTRAN2C/fortran2c/CWriter.java | 26 ++++++++++++++++++++++++++ code/FORTRAN2C/fortran2c/Compiler.java | 28 ++++++++++++++++++++++++++++ code/FORTRAN2C/fortran2c/Translation.java | 13 +++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 code/FORTRAN2C/fortran2c/CWriter.java create mode 100644 code/FORTRAN2C/fortran2c/Compiler.java create mode 100644 code/FORTRAN2C/fortran2c/Translation.java (limited to 'code/FORTRAN2C/fortran2c') diff --git a/code/FORTRAN2C/fortran2c/CWriter.java b/code/FORTRAN2C/fortran2c/CWriter.java new file mode 100644 index 0000000..fec748a --- /dev/null +++ b/code/FORTRAN2C/fortran2c/CWriter.java @@ -0,0 +1,26 @@ +package fortran2c; + +import java.io.*; +import java.util.HashSet; + +public class CWriter { + + private String filePath; + private File theFile; + private FileWriter theFileWriter; + private HashSet functions; + + public CWriter(String filePath) throws IOException { + this.filePath = filePath; + File theFile = new File(filePath); + + if (theFile.createNewFile()) { + FileWriter theFileWriter = new FileWriter(filePath); + theFileWriter.write("#include \n#include \n\nint main(int argc, char** argv) {\n}"); + theFileWriter.close(); + functions.add("main"); + } else { + throw new IOException("The file already exists"); + } + } +} diff --git a/code/FORTRAN2C/fortran2c/Compiler.java b/code/FORTRAN2C/fortran2c/Compiler.java new file mode 100644 index 0000000..7b124fa --- /dev/null +++ b/code/FORTRAN2C/fortran2c/Compiler.java @@ -0,0 +1,28 @@ +package fortran2c; +import fortran2c.parser.*; +import fortran2c.lexer.*; +import fortran2c.node.*; +import java.io.*; + +public class Compiler +{ + public static void main(String[] args) + { + try + { + System.out.println("Using source file: " + args[0]); + // Create a Parser instance. + Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(new FileInputStream(args[0])), 1024))); + // Parse the input. + Start tree = p.parse(); + // Apply the translation. + CWriter cWriter = new CWriter("build/out.c"); + + tree.apply(new Translation(cWriter)); + } + catch(Exception e) + { + System.out.println(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/code/FORTRAN2C/fortran2c/Translation.java b/code/FORTRAN2C/fortran2c/Translation.java new file mode 100644 index 0000000..f5eeaba --- /dev/null +++ b/code/FORTRAN2C/fortran2c/Translation.java @@ -0,0 +1,13 @@ +package fortran2c; +import fortran2c.analysis.*; +import fortran2c.node.*; + +class Translation extends DepthFirstAdapter +{ + + private CWriter writer; + + public Translation(CWriter writer) { + this.writer = writer; + } +} -- cgit v1.2.3