Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzepi authored and Jazzepi committed Nov 5, 2009
1 parent e3772dd commit 6ec2f81
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RobotWarsSVN</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Wed Nov 04 12:00:17 GMT-05:00 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
91 changes: 91 additions & 0 deletions src/lexer/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package lexer;

import java.util.ArrayList;

import lexer.Token.TokenType;

public class Block {

ArrayList<Statement> block = new ArrayList<Statement>();

Block(Token current, Token lookAhead, TextFile body)
{
while(current != null && lookAhead != null && (current.getType() == TokenType.KEYWORD | current.getType() == TokenType.GAMEORDER) && !current.getText().equals("RETURN"))
{
if(current.equals("IF"))
{
if (lookAhead.equals("("))
{
current = body.getNonWSToken();
lookAhead = body.getNonWSToken();
IfOnly ifOnlyBlockToBeAdded = new IfOnly(current, lookAhead, body);
block.add(ifOnlyBlockToBeAdded);
}
else
{
System.out.println("ERROR: ( expected after IF on line" + body.getLine());
}
}
else if(current.equals("IFELSE"))
{
if (lookAhead.equals("("))
{
current = body.getNonWSToken();
lookAhead = body.getNonWSToken();
IfElse ifElseBlockToBeAdded = new IfElse(current, lookAhead, body);
block.add(ifElseBlockToBeAdded);
}
else
{
System.out.println("ERROR: ( expected after IFELSE on line" + body.getLine());
}
}
else if(current.equals("WHILE"))
{
if (lookAhead.equals("("))
{
current = body.getNonWSToken();
lookAhead = body.getNonWSToken();
While whileBlockToBeAdded = new While(current, lookAhead, body);
block.add(whileBlockToBeAdded);
}
else
{
System.out.println("ERROR: ( expected after WHILE on line" + body.getLine());
}
}
else if(current.equals("VAR"))
{
if (lookAhead.getType() == TokenType.IDENTIFIER)
{
current = body.getNonWSToken();
lookAhead = body.getNonWSToken();
VariableAssignment variableAssignmentStatementToBeAdded = new VariableAssignment(current, lookAhead, body);
block.add(variableAssignmentStatementToBeAdded);
}
else
{
System.out.println("ERROR: IDENTIFIER expected after VAR on line" + body.getLine());
}
}
else if(current.getType() == TokenType.GAMEORDER)
{
if (lookAhead.equals("("))
{
current = body.getNonWSToken();
lookAhead = body.getNonWSToken();
GameCommand gameCommandStatementToBeAdded = new GameCommand(current, lookAhead, body);
block.add(gameCommandStatementToBeAdded);
}
else
{
System.out.println("ERROR: ( expected after GAMEORDER on line" + body.getLine());
}
}
else
{
System.out.println("ERROR: IF, IFELSE, WHILE, VAR, or GAMEORDER command expected while parsing line "+ body.getLine());
}
}
}
}
27 changes: 27 additions & 0 deletions src/lexer/Expression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lexer;

import java.util.ArrayList;

import lexer.Token.TokenType;

public class Expression {



public Expression(Token current, Token lookAhead, TextFile body) {


ArrayList<Term> terms;
ArrayList<String> addops;

Term first = new Term(current, lookAhead, body);

while(!(current.getType() == TokenType.CONDITION))
{

Term tempT = new Term(current, lookAhead, body);
}

}

}
4 changes: 4 additions & 0 deletions src/lexer/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class GameCommand implements Statement {

public GameCommand(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

@Override
public ArrayList<String> evaluate() {
// TODO Auto-generated method stub
Expand Down
4 changes: 4 additions & 0 deletions src/lexer/IfElse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class IfElse implements Statement {

public IfElse(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

@Override
public ArrayList<String> evaluate() {
// TODO Auto-generated method stub
Expand Down
10 changes: 10 additions & 0 deletions src/lexer/IfOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

public class IfOnly implements Statement {

Expression leftExp, rightExp;
String Condition;

public IfOnly(Token current, Token lookAhead, TextFile body)
{
leftExp = new Expression(current, lookAhead, body);
Condition = current.getText();
rightExp = new Expression(current, lookAhead, body);
}

@Override
public ArrayList<String> evaluate() {
// TODO Auto-generated method stub
Expand Down
9 changes: 9 additions & 0 deletions src/lexer/MainProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lexer;

public class MainProgram {

public MainProgram(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

}
32 changes: 32 additions & 0 deletions src/lexer/Routine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package lexer;

import java.util.TreeSet;

public class Routine {

MainProgram main;
TreeSet<RoutineProgram> subroutines = new TreeSet<RoutineProgram>();

Routine(TextFile body)
{
Token current = body.getNonWSToken();
Token lookAhead = body.getNonWSToken();

if(current != null && lookAhead != null)
{
if(current.getText().equals("MAIN"))
{
main = new MainProgram(current, lookAhead, body);
}
else if(current.getText().equals("ROUTINE"))
{
RoutineProgram temp = new RoutineProgram(current, lookAhead, body);
subroutines.add(temp);
}
else
{
System.out.println("ERROR: MAIN or SUBROUTINE keyword expected while parsing line "+ body.getLine());
}
}
}
}
9 changes: 9 additions & 0 deletions src/lexer/RoutineProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lexer;

public class RoutineProgram {

public RoutineProgram(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

}
2 changes: 1 addition & 1 deletion src/lexer/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void main(String[] args) {

while(!sFile.isEndOfFile())
{
Token temp = sFile.getToken();
Token temp = sFile.getNonWSToken();
System.out.print(temp.getText() +" IS A:");
System.out.println(temp.getType());
}
Expand Down
10 changes: 10 additions & 0 deletions src/lexer/Term.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lexer;

public class Term {

public Term(Token current, Token lookAhead, TextFile body)
{

}

}
22 changes: 19 additions & 3 deletions src/lexer/TextFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,25 @@ public String getCharacter()
return character;
}

public Token getNonWSToken()
{
Token flag = getToken();
while (flag.getType() == TokenType.WS && flag != null)
{
flag = getToken();
}
return flag;
}

public Token getToken()
{

if(isEndOfFile())
{
System.out.println("Ran out of tokens.");
return null;
}

String rVal = body.get(rowPointer); //Get the string out of the array located at the rowPointer
rVal = rVal.substring(posPointer); //Get the portion of the string to the right of the posPointer
for(int i = rowPointer+1; i < body.size(); i++)
Expand Down Expand Up @@ -257,9 +274,8 @@ else if(TokenType.matchesToken(TokenType.IDENTIFIER, temp)) //If it is a properl
{
posPointer -= body.get(rowPointer).length();
rowPointer++;
}
// System.out.println("ROW:"+rowPointer);
// System.out.println("POS:"+posPointer);
}

return new Token(returnTokType, returnTokText);

}
Expand Down
4 changes: 4 additions & 0 deletions src/lexer/VariableAssignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class VariableAssignment implements Statement {

public VariableAssignment(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

@Override
public ArrayList<String> evaluate() {
// TODO Auto-generated method stub
Expand Down
4 changes: 4 additions & 0 deletions src/lexer/While.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class While implements Statement {

public While(Token current, Token lookAhead, TextFile body) {
// TODO Auto-generated constructor stub
}

@Override
public ArrayList<String> evaluate() {
// TODO Auto-generated method stub
Expand Down
10 changes: 10 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IF IFELSE ELSE VAR MAIN RETURN SUBROUTINE WHILE #Keywords
+-/*% #operators
{}()=;, #symbols
0 1 2 3 4 5 6 7 8 9 10 34943 39924 -324933 00-2394 #digits
!= == <= >= < > #conditions
#white space
isEnemyInRange isHealth directionOfClosestEnemy #game functions
move turn skip selfDestruct attackWithWeapon useItem #game orders
AHORSE A_3402aFdko230__ A_ A A439423 AGJFID IFF IFeLse IF4 WHILE9 While WHILE_#identifiers
_fdishfs 3asdjkj 3943ajsdjajds \ [ ] ~ ` . ? ! #errors

0 comments on commit 6ec2f81

Please sign in to comment.