Skip to content

Commit

Permalink
Executor planned. Interpreted started. Minor fixes in Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
lautaropaske committed Jun 26, 2019
1 parent 31b70fc commit 7766605
Show file tree
Hide file tree
Showing 26 changed files with 229 additions and 28 deletions.
14 changes: 14 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/modules/executor/tp3.executor.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/modules/executor/tp3.executor.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .idea/modules/executor/tp3.executor.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/modules/interpreter/tp3.interpreter.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/modules/interpreter/tp3.interpreter.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/modules/interpreter/tp3.interpreter.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/modules/lexer/tp3.lexer.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/modules/lexer/tp3.lexer.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/modules/main/tp3.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/modules/parser/tp3.parser.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/modules/parser/tp3.parser.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ project(':parser') {
compile project(":lexer")
}
}

project(':interpreter') {
dependencies {
compile project(":lexer")
compile project(":parser")
}
}

project(':executor') {
dependencies {
compile project(":lexer")
compile project(":parser")
compile project(":interpreter")
}
}
23 changes: 23 additions & 0 deletions executor/src/main/java/Executor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import lexer.Lexer;
import lexer.LexerImpl;
import parser.Parser;
import parser.ParserImpl;
import interpreter.Interpreter;
import interpreter.InterpreterImpl;

public class Executor {

private Lexer lexer;
private Parser parser;
private Interpreter interpreter;

public Executor(){
this.lexer = new LexerImpl();
this.parser = new ParserImpl();
this.interpreter = new InterpreterImpl();
}

public void execute(String file){
interpreter.interpret(parser.parse(lexer.lex(file)));
}
}
15 changes: 15 additions & 0 deletions executor/src/test/java/ExecutorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.junit.jupiter.api.Test;

public class ExecutorTest {

@Test
public void executeLines(){
Executor executor = new Executor();

String program = "let foo : number= 5;\n" +
"let bar :number = foo + 4;\n" +
"print(bar + \"is a\" + \'word\');\n";

executor.execute(program);
}
}
7 changes: 7 additions & 0 deletions interpreter/src/main/java/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package interpreter;

import ast.ASTNode;

public interface Interpreter {
void interpret(ASTNode program);
}
10 changes: 10 additions & 0 deletions interpreter/src/main/java/interpreter/InterpreterImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package interpreter;

import ast.ASTNode;

public class InterpreterImpl implements Interpreter {
@Override
public void interpret(ASTNode program) {

}
}
2 changes: 1 addition & 1 deletion lexer/src/main/java/lexer/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface Lexer {
* @param file a text file converted to string properly separated by the ' ' character (whitespace)
* @return a list of the tokens contained in the file, in lexical order
*/
List<Token> tokenize(String file);
List<Token> lex(String file);
}
2 changes: 1 addition & 1 deletion lexer/src/main/java/lexer/LexerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public LexerImpl(){
}

@Override
public List<Token> tokenize(String file) {
public List<Token> lex(String file) {
return mapToToken(splitPossibleTokens(file));
}

Expand Down
19 changes: 11 additions & 8 deletions parser/src/main/java/ast/ASTNodeFactory.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package ast;

import exceptions.ParserException;
import handlers.AssignationHandler;
import handlers.DeclarationAssignationHandler;
import handlers.DeclarationHandler;
import handlers.PrintHandler;
import handlers.*;
import tokens.Token;
import tokens.TokenType;

import java.util.List;

public class ASTNodeFactory {
private DeclarationHandler declarationHandler;
private AssignationHandler assignationHandler;
private DeclarationAssignationHandler declarationAssignationHandler;
private PrintHandler printHandler;
private Handler declarationHandler;
private Handler assignationHandler;
private Handler declarationAssignationHandler;
private Handler printHandler;

public ASTNodeFactory(){
this.declarationHandler = new DeclarationHandler();
this.assignationHandler = new AssignationHandler();
this.declarationAssignationHandler = new DeclarationAssignationHandler();
this.printHandler = new PrintHandler();
}

public ASTNode getNode(List<Token> statement) {
switch (statement.get(0).getType()) {
Expand Down
4 changes: 2 additions & 2 deletions parser/src/main/java/handlers/ExpressionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ protected ASTNode parseNode(List<Token> expression) {
() -> parseBinaryExpression(TokenType.MINUS, expression).orElseGet(
() -> parseBinaryExpression(TokenType.MULTIPLY, expression).orElseGet(
() -> parseBinaryExpression(TokenType.DIVIDE, expression).orElseGet(
()-> parseIndentifierOrLiteral(expression)
()-> parseIdentifierOrLiteral(expression)
)
)
)
);
}

private ASTNode parseIndentifierOrLiteral(List<Token> expression) {
private ASTNode parseIdentifierOrLiteral(List<Token> expression) {
Token token = expression.get(0);
if(Arrays.asList(TokenType.NUM_LITERAL, TokenType.STR_LITERAL).contains(expression.get(0).getType())) return new Literal(Type.from(token), token.getValue());
if(TokenType.IDENTIFIER == token.getType()) return new Identifier(token.getValue());
Expand Down
Loading

0 comments on commit 7766605

Please sign in to comment.