Browse Source

Merge pull request #23 from nv-vn/master

Began parser work
master
FourMan 6 years ago
parent
commit
7cc03d2cf9
  1. 23
      lexers/java/src/four/ast/BinaryOperation.java
  2. 35
      lexers/java/src/four/ast/BinaryOperationType.java
  3. 3
      lexers/java/src/four/ast/CompoundStatement.java
  4. 16
      lexers/java/src/four/ast/ElseIfStatement.java
  5. 11
      lexers/java/src/four/ast/ElseStatement.java
  6. 3
      lexers/java/src/four/ast/ExpressionNode.java
  7. 16
      lexers/java/src/four/ast/IfStatement.java
  8. 3
      lexers/java/src/four/ast/StatementNode.java
  9. 16
      lexers/java/src/four/ast/SyntaxNode.java
  10. 18
      lexers/java/src/four/ast/UnaryOperation.java
  11. 12
      lexers/java/src/four/ast/UnaryOperationType.java
  12. 5
      lexers/java/src/four/parser/Parser.java

23
lexers/java/src/four/ast/BinaryOperation.java

@ -0,0 +1,23 @@
package four.ast;
public class BinaryOperation extends ExpressionNode {
private BinaryOperationType type;
public BinaryOperation(BinaryOperationType type, ExpressionNode left, ExpressionNode right) {
this.type = type;
this.addChild(left);
this.addChild(right);
}
public ExpressionNode getLeft() {
return (ExpressionNode) this.children.get(0);
}
public ExpressionNode getRight() {
return (ExpressionNode) this.children.get(1);
}
public BinaryOperationType getType() {
return this.type;
}
}

35
lexers/java/src/four/ast/BinaryOperationType.java

@ -0,0 +1,35 @@
package four.ast;
public enum BinaryOperationType {
PLUS,
MINUS,
TIMES,
DIVIDE,
MODULUS,
BITWISE_AND,
BITWISE_OR,
BITWISE_XOR,
BITWISE_LEFT_SHIFT,
BITWISE_RIGHT_SHIFT,
PLUS_ASSIGNMENT,
MINUS_ASSIGNMENT,
TIMES_ASSIGNMENT,
DIVIDE_ASSIGNMENT,
MODULUS_ASSIGNMENT,
BITWISE_AND_ASSIGNMENT,
BITWISE_OR_ASSIGNMENT,
BITWISE_XOR_ASSIGNMENT,
BITWISE_LEFT_SHIFT_ASSIGNMENT,
BITWISE_RIGHT_SHIFT_ASSIGNMENT,
EQUAL_TO,
NOT_EQUAL_TO,
GREATER_THAN,
LESS_THAN,
GREATER_THAN_OR_EQUAL_TO,
LESS_THAN_OR_EQUAL_TO,
LOGICAL_AND,
LOGICAL_OR,
DOT,
UP_ARRAY,
DOWN_ARRAY
}

3
lexers/java/src/four/ast/CompoundStatement.java

@ -0,0 +1,3 @@
package four.ast;
public class CompoundStatement extends SyntaxNode {}

16
lexers/java/src/four/ast/ElseIfStatement.java

@ -0,0 +1,16 @@
package four.ast;
public class ElseIfStatement extends StatementNode {
public ElseIfStatement(ExpressionNode predicate, CompoundStatement body) {
this.addChild(predicate);
this.addChild(body);
}
public ExpressionNode getPredicate() {
return (ExpressionNode) this.children.get(0);
}
public CompoundStatement getBody() {
return (CompoundStatement) this.children.get(1);
}
}

11
lexers/java/src/four/ast/ElseStatement.java

@ -0,0 +1,11 @@
package four.ast;
public class ElseStatement extends StatementNode {
public ElseStatement(CompoundStatement body) {
this.addChild(body);
}
public CompoundStatement getBody() {
return (CompoundStatement) this.children.get(0);
}
}

3
lexers/java/src/four/ast/ExpressionNode.java

@ -0,0 +1,3 @@
package four.ast;
public class ExpressionNode extends SyntaxNode {}

16
lexers/java/src/four/ast/IfStatement.java

@ -0,0 +1,16 @@
package four.ast;
public class IfStatement extends StatementNode {
public IfStatement(ExpressionNode predicate, CompoundStatement body) {
this.addChild(predicate);
this.addChild(body);
}
public ExpressionNode getPredicate() {
return (ExpressionNode) this.children.get(0);
}
public CompoundStatement getBody() {
return (CompoundStatement) this.children.get(1);
}
}

3
lexers/java/src/four/ast/StatementNode.java

@ -0,0 +1,3 @@
package four.ast;
public class StatementNode extends SyntaxNode {}

16
lexers/java/src/four/ast/SyntaxNode.java

@ -0,0 +1,16 @@
package four.ast;
import java.util.ArrayList;
import java.util.List;
public class SyntaxNode {
protected List<SyntaxNode> children;
public SyntaxNode() {
this.children = new ArrayList<SyntaxNode>();
}
public void addChild(SyntaxNode child) {
this.children.add(child);
}
}

18
lexers/java/src/four/ast/UnaryOperation.java

@ -0,0 +1,18 @@
package four.ast;
public class UnaryOperation extends ExpressionNode {
private UnaryOperationType type;
public UnaryOperation(UnaryOperationType type, ExpressionNode operand) {
this.type = type;
this.addChild(operand);
}
public ExpressionNode getOperand() {
return (ExpressionNode) this.children.get(0);
}
public UnaryOperationType getType() {
return this.type;
}
}

12
lexers/java/src/four/ast/UnaryOperationType.java

@ -0,0 +1,12 @@
package four.ast;
public enum UnaryOperationType {
IDENTITY,
NEGATE,
BITWISE_NOT,
LOGICAL_NOT,
INCREMENT,
DECREMENT,
INCREMENT_EVALUATE,
DECREMENT_EVALUATE
}

5
lexers/java/src/four/parser/Parser.java

@ -0,0 +1,5 @@
package four.parser;
public class Parser {
}
Loading…
Cancel
Save