Skip to content

Commit

Permalink
-Automated Operator.Solve(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paras DPain committed Nov 18, 2015
1 parent c50ee2f commit b29c21b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/Paras.xml

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

Binary file modified Grammar_plans.docx
Binary file not shown.
Binary file modified bin/framework/Operator.class
Binary file not shown.
11 changes: 9 additions & 2 deletions src/engine/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
public class Tester {

public static void main(String[] args) {

displayMatrix(Operator.Solve("A*B+C-D"));

Matrix variables[] = new Matrix[4];
variables[0] = new Matrix(5, (long)10);
variables[1] = new Matrix(5, (long)10);
variables[2] = new Matrix(5, (long)10);
variables[3] = new Matrix(5, (long)10);

String varNames[] = {"A", "B", "C", "D"};
displayMatrix(Operator.Solve("A*(B/C+D)", varNames, variables));

/*
Scanner scanner = new Scanner (System.in);
Expand Down
31 changes: 16 additions & 15 deletions src/framework/Operator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package framework;

import java.util.List;

import nodes.ExpressionNode;
import parser.EvaluationException;
import parser.Parser;
Expand All @@ -20,29 +22,28 @@ public class Operator {
* ------------------------ */

// Parse and solve an equation of matrices
public static Matrix Solve(String input){
public static Matrix Solve(String input, String varNames[], Matrix variables[]){
Parser parser = new Parser();
try
{
ExpressionNode expr = parser.parse(input);
// Set Variables if any exist
expr.accept(new SetVariable("A", new Matrix(3, (long)10)));
expr.accept(new SetVariable("B", new Matrix(3, (long)10)));
expr.accept(new SetVariable("C", new Matrix(3, (long)10)));
expr.accept(new SetVariable("D", new Matrix(3, (long)10)));
return expr.getValue();

}
catch (ParserException e)
{
System.out.println(e.getMessage());

// Set variables for each entry in the list
if(varNames.length == variables.length){
for (int i=0;i<varNames.length;i++) {
expr.accept(new SetVariable(varNames[i], variables[i]));
}
// Evaluate the expression
return expr.getValue();
}
else return error;
}
catch (EvaluationException e)
catch (ParserException | EvaluationException e)
{
System.out.println(e.getMessage());
}
return error;

return error;
}

// Returns an invalid Matrix if the caller is sending invalid data
Expand Down
Binary file removed ~$ammar_plans.docx
Binary file not shown.

0 comments on commit b29c21b

Please sign in to comment.