pl.edu.pjwstk.yaod.yaql.visitors
Class EvalVisitor

java.lang.Object
  |
  +--pl.edu.pjwstk.yaod.yaql.visitors.EvalVisitor
All Implemented Interfaces:
Visitor

public class EvalVisitor
extends java.lang.Object
implements Visitor

The EvalVisitor class represents one of the interpratations of the program - in this case evaluataion. It consists of many visit methods - each for one main node in abstract syntax tree.

Author:
Jakub Trzetrzelewski, jakub_trzetrzelewski@yahoo.com
See Also:
AbstractSyntaxTree, Visitor, EvalException

Constructor Summary
EvalVisitor(java.io.PrintWriter wr, QueryResultStack QRES, EnvironmentalStack ENVS, SVRP SP, java.util.Vector results)
          Creates a new evaluator with specified environmental stack, query result stack, abstract syntax tree, server process, writer and vector of results.
 
Method Summary
 QueryResult combine(NonAlgebraicExpression n, QueryResult e, QueryResult tmp)
          Auxilary method responsible for evaluating binary non algebraic expression nodes.
 boolean compare(QueryResult l, QueryResult r)
          Auxilary method responsible for evaluating binary non algebraic expression node - precisely SortingExpression.
 void compareAndReplace(SequenceValue seq, int i, int j, int z)
          Auxilary method responsible for evaluating binary non algebraic expression node - precisely SortingExpression.
 QueryResult compute(AlgebraicExpression n, QueryResult l, QueryResult r)
          Auxilary method responsible for evaluating binary expression nodes.
 QueryResult compute(NonParametricExpression n, QueryResult r)
          Auxilary method responsible for evaluating unary expression nodes.
 QueryResult compute(ParametricExpression n, QueryResult l, QueryResult r)
          Auxilary method responsible for evaluating unary expression nodes.
 QueryResult compute(SingleExpression n)
          Auxilary method responsible for evaluating single expression nodes.
 QueryResult compute(TernaryExpression n, QueryResult l, QueryResult m, QueryResult r)
          Auxilary method responsible for evaluating ternary expression nodes.
 ObjectID getEntry()
          Returns the entry of the object store.
 ObjectManager getObjectManager()
          Returns the object manager of the object store.
 QueryResult merge(NonAlgebraicExpression n, BagValue bag)
          Auxilary method responsible for evaluating binary non algebraic expression nodes.
 void visit(AlgebraicExpression n)
          Method responsible for traversing certain binary node in abstract syntax tree.
 void visit(BlockStatement n)
          Method responsible for traversing node representing block statement ({ ... }) in abstract syntax tree.
 void visit(BreakStatement n)
          Method responsible for traversing node representing break statement (break ;)in abstract syntax tree.
 void visit(DeleteStatement n)
          Method responsible for traversing node representing delete statement (delet ...
 void visit(DoWhileStatement n)
          Method responsible for traversing node representing do while statement (do ... while (...)
 void visit(EmptyBlockStatement n)
          Method responsible for traversing node representing empty block statement ({ }) in abstract syntax tree.
 void visit(EmptyProcedureDeclarationStatement n)
          Method responsible for traversing node representing empty procedure declaration statement (procedure without parameters) (procedure/function id() { ... }) in abstract syntax tree.
 void visit(EmptyReturnStatement n)
          Method responsible for traversing node representing empty return statement (return ;) in abstract syntax tree.
 void visit(EmptyStatement n)
          Method responsible for traversing node representing empty statement ( ;) in abstract syntax tree.
 void visit(ExpressionStatement n)
          Method responsible for traversing node representing expression statement (...
 void visit(ForEachStatement n)
          Method responsible for traversing node representing for each statement (for each ... do ...) in abstract syntax tree.
 void visit(ForStatement n)
          Method responsible for traversing node representing for statement (for (...; ...; ...)
 void visit(IfElseStatement n)
          Method responsible for traversing node representing if else statement (if (...)
 void visit(IfStatement n)
          Method responsible for traversing node representing if statement (if (...)
 void visit(InsertIntoStatement n)
          Method responsible for traversing node representing insert into statement (insert ... into ...
 void visit(LastStatementList n)
          Method responsible for traversing node representing last statement list (...
 void visit(NonAlgebraicExpression n)
          Method responsible for traversing certain binary node in abstract syntax tree.
 void visit(NonParametricExpression n)
          Method responsible for traversing certain unary node in abstract syntax tree.
 void visit(PairStatementList n)
          Method responsible for traversing node representing pair statement list (...
 void visit(ParametricExpression n)
          Method responsible for traversing certain unary node in abstract syntax tree.
 void visit(PrintStatement n)
          Method responsible for traversing node representing print statement (print (...)
 void visit(ProcedureDeclarationStatement n)
          Method responsible for traversing node representing procedure declaration statement (procedure/function id(...) {
 void visit(RenameToStatement n)
          Method responsible for traversing node representing rename to statement (rename ... to ...
 void visit(ReturnStatement n)
          Method responsible for traversing node representing return statement (return ...;) in abstract syntax tree.
 void visit(ShowStatement n)
          Method responsible for traversing node representing show statement (show (...)
 void visit(SingleExpression n)
          Method responsible for traversing certain single node in abstract syntax tree.
 void visit(TernaryExpression n)
          Method responsible for traversing certain ternary node in abstract syntax tree.
 void visit(UpdateToStatement n)
          Method responsible for traversing node representing update to statement (update ... to ...
 void visit(WhileStatement n)
          Method responsible for traversing node representing while statement (while (...)
 void visit(XmlPrintStatement n)
          Method responsible for traversing node representing xmlprint statement (xmlprint (...)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EvalVisitor

public EvalVisitor(java.io.PrintWriter wr,
                   QueryResultStack QRES,
                   EnvironmentalStack ENVS,
                   SVRP SP,
                   java.util.Vector results)
Creates a new evaluator with specified environmental stack, query result stack, abstract syntax tree, server process, writer and vector of results.
Parameters:
wr - an object responsible for displaying information.
QRES - a query result stack.
ENVS - an environmental stack.
SP - a link to data store (server process).
results - vector of results of evaluation.
See Also:
QueryResultStack, EnvironmentalStack, SVRP
Method Detail

getEntry

public ObjectID getEntry()
Returns the entry of the object store.
Returns:
entry of the object store.
See Also:
ObjectID, SVRP

getObjectManager

public ObjectManager getObjectManager()
Returns the object manager of the object store.
Returns:
object manager of the object store.
See Also:
ObjectManager, SVRP

visit

public void visit(SingleExpression n)
           throws EvalException
Method responsible for traversing certain single node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain single node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
SingleExpression

visit

public void visit(ParametricExpression n)
           throws EvalException
Method responsible for traversing certain unary node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain unary node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
UnaryExpression, ParametricExpression

visit

public void visit(NonParametricExpression n)
           throws EvalException
Method responsible for traversing certain unary node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain unary node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
UnaryExpression, NonParametricExpression

visit

public void visit(AlgebraicExpression n)
           throws EvalException
Method responsible for traversing certain binary node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain binary node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
BinaryExpression, AlgebraicExpression

visit

public void visit(NonAlgebraicExpression n)
           throws EvalException
Method responsible for traversing certain binary node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain binary node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
BinaryExpression, NonAlgebraicExpression

visit

public void visit(TernaryExpression n)
           throws EvalException
Method responsible for traversing certain ternary node in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a certain ternary node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
TernaryExpression

visit

public void visit(EmptyStatement n)
           throws EvalException
Method responsible for traversing node representing empty statement ( ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a empty statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
EmptyStatement

visit

public void visit(ExpressionStatement n)
           throws EvalException
Method responsible for traversing node representing expression statement (... ;)in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a expression statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ExpressionStatement

visit

public void visit(PrintStatement n)
           throws EvalException
Method responsible for traversing node representing print statement (print (...) ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a print statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
PrintStatement

visit

public void visit(XmlPrintStatement n)
           throws EvalException
Method responsible for traversing node representing xmlprint statement (xmlprint (...) ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a xmlprint statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
XmlPrintStatement

visit

public void visit(ShowStatement n)
           throws EvalException
Method responsible for traversing node representing show statement (show (...) ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a show statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ShowStatement

visit

public void visit(BlockStatement n)
           throws EvalException
Method responsible for traversing node representing block statement ({ ... }) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a block statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
BlockStatement

visit

public void visit(EmptyBlockStatement n)
           throws EvalException
Method responsible for traversing node representing empty block statement ({ }) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a empty block statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
EmptyBlockStatement

visit

public void visit(IfStatement n)
           throws EvalException
Method responsible for traversing node representing if statement (if (...) ...) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a if statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
IfStatement

visit

public void visit(IfElseStatement n)
           throws EvalException
Method responsible for traversing node representing if else statement (if (...) ... else ...) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a if else statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
IfElseStatement

visit

public void visit(WhileStatement n)
           throws EvalException
Method responsible for traversing node representing while statement (while (...) ...) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a while statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
WhileStatement

visit

public void visit(ForStatement n)
           throws EvalException
Method responsible for traversing node representing for statement (for (...; ...; ...) ...) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a for statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ForStatement

visit

public void visit(DoWhileStatement n)
           throws EvalException
Method responsible for traversing node representing do while statement (do ... while (...) ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a do while statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
DoWhileStatement

visit

public void visit(ForEachStatement n)
           throws EvalException
Method responsible for traversing node representing for each statement (for each ... do ...) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a for each statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ForEachStatement

visit

public void visit(DeleteStatement n)
           throws EvalException
Method responsible for traversing node representing delete statement (delet ... ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a delete statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
DeleteStatement

visit

public void visit(RenameToStatement n)
           throws EvalException
Method responsible for traversing node representing rename to statement (rename ... to ... ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a rename to statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
RenameToStatement

visit

public void visit(InsertIntoStatement n)
           throws EvalException
Method responsible for traversing node representing insert into statement (insert ... into ... ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a insert into statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
InsertIntoStatement

visit

public void visit(UpdateToStatement n)
           throws EvalException
Method responsible for traversing node representing update to statement (update ... to ... ;)in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a update to statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
UpdateToStatement

visit

public void visit(EmptyProcedureDeclarationStatement n)
           throws EvalException
Method responsible for traversing node representing empty procedure declaration statement (procedure without parameters) (procedure/function id() { ... }) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a empty procedure declaration statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
EmptyProcedureDeclarationStatement

visit

public void visit(ProcedureDeclarationStatement n)
           throws EvalException
Method responsible for traversing node representing procedure declaration statement (procedure/function id(...) { ... }) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a procedure declaration statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ProcedureDeclarationStatement

visit

public void visit(BreakStatement n)
           throws EvalException
Method responsible for traversing node representing break statement (break ;)in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a break statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
BreakStatement

visit

public void visit(ReturnStatement n)
           throws EvalException
Method responsible for traversing node representing return statement (return ...;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a return statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
ReturnStatement

visit

public void visit(EmptyReturnStatement n)
           throws EvalException
Method responsible for traversing node representing empty return statement (return ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a empty return statement node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
EmptyReturnStatement

visit

public void visit(PairStatementList n)
           throws EvalException
Method responsible for traversing node representing pair statement list (... ; ... ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a pair statement list node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
PairStatementList

visit

public void visit(LastStatementList n)
           throws EvalException
Method responsible for traversing node representing last statement list (... ;) in abstract syntax tree.
Specified by:
visit in interface Visitor
Parameters:
n - is a last statement list node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
LastStatementList

compute

public QueryResult compute(SingleExpression n)
                    throws EvalException
Auxilary method responsible for evaluating single expression nodes.
Parameters:
n - is a certain single expression node in abstract syntax tree.
Throws:
EvalException - if evaluation in this node fails.
See Also:
SingleExpression

compute

public QueryResult compute(ParametricExpression n,
                           QueryResult l,
                           QueryResult r)
                    throws EvalException
Auxilary method responsible for evaluating unary expression nodes.
Parameters:
n - is a certain unary expression node in abstract syntax tree.
l - is a left operand.
r - is a right operand.
Throws:
EvalException - if evaluation in this node fails.
See Also:
UnaryExpression, ParametricExpression, QueryResult

compute

public QueryResult compute(NonParametricExpression n,
                           QueryResult r)
                    throws EvalException
Auxilary method responsible for evaluating unary expression nodes.
Parameters:
n - is a certain unary expression node in abstract syntax tree.
r - is a right operand.
Throws:
EvalException - if evaluation in this node fails.
See Also:
UnaryExpression, NonParametricExpression, QueryResult

compute

public QueryResult compute(AlgebraicExpression n,
                           QueryResult l,
                           QueryResult r)
                    throws EvalException
Auxilary method responsible for evaluating binary expression nodes.
Parameters:
n - is a certain binary expression node in abstract syntax tree.
l - is a left operand.
r - is a right operand.
Throws:
EvalException - if evaluation in this node fails.
See Also:
BinaryExpression, AlgebraicExpression, QueryResult

compute

public QueryResult compute(TernaryExpression n,
                           QueryResult l,
                           QueryResult m,
                           QueryResult r)
                    throws EvalException
Auxilary method responsible for evaluating ternary expression nodes.
Parameters:
n - is a certain ternary expression node in abstract syntax tree.
l - is a left operand.
m - is a middle operand.
r - is a right operand.
Throws:
EvalException - if evaluation in this node fails.
See Also:
TernaryExpression, QueryResult

combine

public QueryResult combine(NonAlgebraicExpression n,
                           QueryResult e,
                           QueryResult tmp)
                    throws EvalException
Auxilary method responsible for evaluating binary non algebraic expression nodes.
Parameters:
n - is a certain binary expression node in abstract syntax tree.
e - is one of the results of the left operand evaluation.
tmp - is a the result of nested(e).
Throws:
EvalException - if evaluation in this node fails.
See Also:
BinaryExpression, NonAlgebraicExpression, QueryResult

merge

public QueryResult merge(NonAlgebraicExpression n,
                         BagValue bag)
                  throws EvalException
Auxilary method responsible for evaluating binary non algebraic expression nodes.
Parameters:
n - is a certain binary expression node in abstract syntax tree.
bag - is the set of all partial results yielded by method combine.
tmp - is a the result of nested(e).
Throws:
EvalException - if evaluation in this node fails.
See Also:
BinaryExpression, NonAlgebraicExpression, BagValue

compareAndReplace

public void compareAndReplace(SequenceValue seq,
                              int i,
                              int j,
                              int z)
                       throws TypeMismatchException
Auxilary method responsible for evaluating binary non algebraic expression node - precisely SortingExpression. Its goal is to compare two elemens with indexes i and j and replace them if there is such need.
Parameters:
bag - is the set of all partial results yielded by method combine.
i - the index of the first element to compare.
j - the index of the second element to compare.
z - the number of the sorting key.
Throws:
TypeMismatchException - if evaluation in this node fails.
See Also:
BinaryExpression, NonAlgebraicExpression, SequenceValue

compare

public boolean compare(QueryResult l,
                       QueryResult r)
                throws TypeMismatchException
Auxilary method responsible for evaluating binary non algebraic expression node - precisely SortingExpression. Its goal is to compare two elements and if they are comparable and the first element is greater than second the result is true, otherwise the result is false.
Parameters:
l - the first element to compare.
r - the second element to compare.
Returns:
the result of comparison.
Throws:
TypeMismatchException - if evaluation in this node fails.
See Also:
BinaryExpression, NonAlgebraicExpression, QueryResult