changes for jar build

This commit is contained in:
Krauß, Josefine 2024-07-01 17:45:07 +02:00
parent c24a483880
commit 192dfae94b
8 changed files with 119 additions and 39 deletions

7
.idea/encodings.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

4
.idea/misc.xml generated
View File

@ -24,7 +24,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/target" />
</component>
</project>

1
.idea/modules.xml generated
View File

@ -3,7 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/NichtHaskell.iml" filepath="$PROJECT_DIR$/NichtHaskell.iml" />
<module fileurl="file://$PROJECT_DIR$/src/NichtHaskell1.iml" filepath="$PROJECT_DIR$/src/NichtHaskell1.iml" />
</modules>
</component>
</project>

View File

@ -2,7 +2,10 @@
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/Source" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
</module>

34
pom.xml
View File

@ -4,25 +4,45 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Clippit.org</groupId>
<artifactId>NichtHaskell</artifactId>
<version>1</version>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<java.version>22</java.version>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<archive>
<manifest>
<mainClass>Compiler</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>

View File

@ -1,4 +1,4 @@
import abstractSyntaxTree.Class.RefType;
import TypeCheck.TypeCheckException;
import abstractSyntaxTree.Program;
import astGenerator.ASTGenerator;
import gen.DecafLexer;
@ -18,41 +18,54 @@ public class Compiler {
public static void main(String[] args) throws Exception{
Path filePath = Paths.get("src/main/java/TestClass.java");
// todo code für jar
// if (args.length < 1) {
// System.out.println("Usage: java -jar Compiler.jar <file_path> [--suppress-details]");
// return;
// }
//String filePath = args[0];
String filePath = "src/main/java/TestClass.java";
// TODO false setzen für jar-Build
boolean suppressDetails = true;
// todo remove this debug info
Path absolutePath = filePath.toAbsolutePath();
System.out.println("Processing input: " + absolutePath);
if (args.length > 1 && args[1].equals("--suppress-details")) {
suppressDetails = true;
}
String content;
try {
content = Files.readString(filePath);
}catch (java.nio.file.NoSuchFileException e){
System.out.println("File not found");
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
System.out.println("Your input file was not found: " + path);
return;
}
if(!suppressDetails)
System.out.println("Processing input: " + path);
System.out.println("--- print content ---");
System.out.println(content);
String content = Files.readString(path);
if(!suppressDetails)
System.out.println("The content of your input file is: \n" + content);
CharStream codeCharStream = CharStreams.fromString(content);
DecafLexer lexer = new DecafLexer(codeCharStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
System.out.println("--- print tokens ---");
tokens.fill();
List<Token> tokenList = tokens.getTokens();
if(!suppressDetails) {
StringBuilder stringBuilder = new StringBuilder();
for (Token token : tokenList) {
stringBuilder.append(token.getText()).append(" ");
List<Token> tokenList = tokens.getTokens();
StringBuilder stringBuilder = new StringBuilder();
for (Token token : tokenList) {
stringBuilder.append(token.getText()).append(" ");
}
String readableTokens = stringBuilder.toString().trim();
System.out.println("The tokens of your input are: \n" + readableTokens);
}
String readableTokens = stringBuilder.toString().trim();
System.out.println(readableTokens);
DecafParser parser = new DecafParser(tokens);
@ -63,14 +76,30 @@ public class Compiler {
Program abstractSyntaxTree =(Program) generator.visit(tree);
System.out.println("--- AST generator ---");
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes with names:");
for (RefType refType : abstractSyntaxTree.classes) {
System.out.println(refType.name);
}
if(!suppressDetails) {
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes: ");
abstractSyntaxTree.classes.forEach(refType -> {
System.out.print(refType.name);
if (abstractSyntaxTree.classes.indexOf(refType) < abstractSyntaxTree.classes.size() - 1) {
System.out.print(", ");
} else {
System.out.println();
}
});
}
// try {
// abstractSyntaxTree.typeCheck();
// }catch(TypeCheckException e){
// System.out.println("A TypeCheck error occurred. The compilation was stopped.");
// System.out.println(e);
// return;
// }
abstractSyntaxTree.typeCheck();
if(!suppressDetails)
System.out.println("No TypeCheck errors found.");
abstractSyntaxTree.codeGen();
System.out.println("Your input was compiler. You can find the output at ???");// todo wo output? überhaupt hinschreiben?
}
}

View File

@ -1,4 +1,4 @@
class Example1 {
class Example1b {
public int fak(int number){
if(number < 0){
return 1;

View File

@ -1,5 +1,27 @@
public class TestClass {
public static void main(String[] args){
class TestClass {
int i;
int a = 12345;
Example e;
public TestClass(){i = 3456;}
int meth(int n){
Example e = new Example();
int abc = e.example1.m1(2).m2().m3();
return 0;
}
Example m1(int n){
return new Example();
}
}
class Example {
int i;
boolean b;
char c;
TestClass example1;
TestClass m(int a){
return new TestClass();
}
Example m2(){return new Example();}
int m3(){return 1;}
}