Skip to content

Commit

Permalink
Ok
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosavian committed May 2, 2024
2 parents 0b4636c + 3eefe22 commit 0778b14
Show file tree
Hide file tree
Showing 18 changed files with 1,872 additions and 914 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Made by Eduardo Savian, Pablo Marques e Marcos Fehlauer
### Ant build

```bash
ant build
ant build
```

### Java Run

```bash
java -jar simplex.jar -parse tests/principal.expr -gui
java -jar simplex.jar -parser tests/test.expr -semantic
```

## Reference
Expand Down
18 changes: 14 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</path>

<!-- Compile task -->
<target name="compile">
<target name="compile" depends="init" unless="skip.build">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false" classpathref="classpath" debug="true" nowarn="true"/>
</target>
Expand All @@ -33,22 +33,24 @@
</target>

<!-- Build task -->
<target name="build" depends="clean, init, generate, compile, jar">
<target name="build" depends="clean, compile, jar">
<echo message="Build completed"/>
</target>

<!-- ANTLR task -->
<target name="generate">
<target name="parser" depends="init">
<java classname="org.antlr.v4.Tool" fork="true" classpath="${antlr4_path}:${CLASSPATH}">
<arg value="${simplex.dir}/SimplexLexer.g4"/>
<arg value="${simplex.dir}/SimplexParser.g4"/>
<arg value="-o"/>
<arg value="${src.dir}"/>
<arg value="-listener"/>
<arg value="-visitor"/>
</java>
</target>

<!-- Jar task -->
<target name="jar">
<target name="jar" depends="compile">
<jar destfile="${jar.file}" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
Expand All @@ -58,5 +60,13 @@
</jar>
</target>

<!-- Check if build is up to date -->
<target name="check-up-to-date">
<uptodate property="skip.build" targetfile="${build.dir}">
<srcfiles dir="${src.dir}">
<include name="**/*.java"/>
</srcfiles>
</uptodate>
</target>

</project>
5 changes: 1 addition & 4 deletions simplex/SimplexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ lexer grammar SimplexLexer;
// Whitespace rule to skip spaces, tabs, and line breaks
WS : [ \t\r\n]+ -> skip;


ECHO : 'ECHO';

// Branching keywords
IF : 'if';
ELSE : 'else';
Expand Down Expand Up @@ -88,4 +85,4 @@ SL_COMMENT : '//' ~[\r\n]* -> skip; // Single-line comments
ML_COMMENT : '/*' .*? '*/' -> skip; // Multi-line comments

// Rule for identifying identifiers (variable names, function names, etc.)
ID : [_a-zA-Z][a-zA-Z0-9_]*;
ID : [_a-zA-Z][a-zA-Z0-9_]*;
2 changes: 1 addition & 1 deletion simplex/SimplexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ real

indexing
: ID SQUARE_OPEN expression SQUARE_CLOSE
;
;
3 changes: 3 additions & 0 deletions src/File.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class File {

}
30 changes: 30 additions & 0 deletions src/Semantic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;

public class Semantic {
public void execute(String inputFilePath) throws IOException {
typeChecker(inputFilePath);
}

private void typeChecker(String inputFilePath) throws IOException {
InputStream inputStream = new FileInputStream(inputFilePath);

@SuppressWarnings("deprecation")
ANTLRInputStream input = new ANTLRInputStream(inputStream);

SimplexLexer lexer = new SimplexLexer(input);

CommonTokenStream tokens = new CommonTokenStream(lexer);

SimplexParser parser = new SimplexParser(tokens);

ParseTree tree = parser.program();

SimplexVisitor simplex = new SimplexVisitor();

simplex.visit(tree);
}
}
62 changes: 19 additions & 43 deletions src/Simplex.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
public class Simplex {
public enum Operation {
TOKENIZE("-tokenize"),
PARSE("-parse"),
GENERATE_TREE("-generate-tree");
PARSER("-parser"),
TYPE_CHECKER("-type-checker");

private final String flag;

Expand All @@ -28,58 +27,35 @@ public static void main(String[] args) throws Exception {
break;
}
}

switch (operationFlag) {
case TOKENIZE:

break;
case PARSE:
// Logic for parsing
//verify
case PARSER:
if (args.length < 3) {
System.err.println("Usage: java Main -parse <input_file> <print_type>");
System.exit(1);
}

Utils parser = new Utils();

String inputFilePath = args[1];
String printType = args[2];

switch (printType) {
case "-tree":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-gui":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-tokens":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-trace":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-diagnostics":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-ps":
parser.antlrCommand("Simplex", "program", inputFilePath, printType);
break;
case "-runTree":
parser.printTree(inputFilePath);
break;
case "-runWalk":
parser.printWalk(inputFilePath);
break;
default:
System.out.println("Invalid print type");
break;
Sintatic sintatic = new Sintatic();
sintatic.execute(inputFilePath, printType);
break;
case TYPE_CHECKER:
if (args.length < 2) {
System.err.println("Usage: java Main -generate-tree <input_file>");
System.exit(1);
}

String inputFilePath2 = args[1];

Semantic semantic = new Semantic();
semantic.execute(inputFilePath2);

break;
case GENERATE_TREE:
// Logic for generating syntax tree
default:
System.out.println("Invalid operation");
break;
}

}
}
Loading

0 comments on commit 0778b14

Please sign in to comment.