pl.edu.pjwstk.yaod.yaql
Class Interpreter

java.lang.Object
  |
  +--pl.edu.pjwstk.yaod.yaql.Interpreter

public class Interpreter
extends java.lang.Object

The Interpreter class represents the main code responsible for program interpretation. It consists of environmental stack, query result stack, abstract syntax tree and a link to the data store.

Author:
Jakub Trzetrzelewski, jakub_trzetrzelewski@yahoo.com
See Also:
EnvironmentalStack, QueryResultStack, AbstractSyntaxTree, SVRP

Constructor Summary
Interpreter(SVRP sp)
          Creates a new interpreter with specified sp, which is a server process of the data store.
 
Method Summary
 Result convertToProtocolResult(QueryResult r)
          The method takes the query/program result as an argument and converts it into the form which is suitable for serialization (used for passing the results through network).
 javax.swing.tree.DefaultMutableTreeNode dumpAST()
          Returns the structure of abstract syntax tree suitable for displaying it on graphic panel in tree form.
 void dumpAST(AbstractSyntaxTree AST, javax.swing.tree.DefaultMutableTreeNode parentNode)
          The dumpAST is the recursive method which prepares the abstract syntax tree structure for being displayed on graphic interface.
 javax.swing.tree.DefaultMutableTreeNode dumpDB()
          Returns the structure of object store suitable for displaying it on graphic interface in the tree form.
 javax.swing.tree.DefaultMutableTreeNode dumpENVS()
          Returns the structure of environmental stack suitable for displaying it on graphic panel in tree form.
 void dumpENVS(javax.swing.tree.DefaultMutableTreeNode parentNode)
          The dumpENVS is the recursive method which prepares the environmental stack structure for being displayed on graphic interface.
 AbstractSyntaxTree getAST()
          Returns the abstract syntax tree.
 ObjectID getEntry()
          Returns the entry of the object store.
 EnvironmentalStack getENVS()
          Returns the environmental stack.
 java.io.PrintWriter getPW()
          Returns the print writer which is an object responsible for displaying results.
 QueryResultStack getQRES()
          Returns the query result stack.
 SVRP getSP()
          Returns the server process.
 void initializeENVS()
          The method responsible for initializing environmental stack.
 void setPW(java.io.PrintWriter PW)
          Sets the print writer which is an object responsible for displaying results.
 java.util.Vector start(java.lang.String str)
          The main method responsible for program interpretation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter(SVRP sp)
Creates a new interpreter with specified sp, which is a server process of the data store. It also initilizes properly the environmental stack.
Parameters:
sp - a link to data store (server process).
See Also:
SVRP, EnvironmentalStack
Method Detail

getENVS

public EnvironmentalStack getENVS()
Returns the environmental stack.
Returns:
the object representing the environmental stack.
See Also:
EnvironmentalStack

getQRES

public QueryResultStack getQRES()
Returns the query result stack.
Returns:
the object representing the query result stack.
See Also:
QueryResultStack

getAST

public AbstractSyntaxTree getAST()
Returns the abstract syntax tree.
Returns:
the object representing the abstract syntax tree.
See Also:
AbstractSyntaxTree

getSP

public SVRP getSP()
Returns the server process.
Returns:
the object representing the server process.
See Also:
SVRP

getPW

public java.io.PrintWriter getPW()
Returns the print writer which is an object responsible for displaying results.
Returns:
the object representing the print writer.

setPW

public void setPW(java.io.PrintWriter PW)
Sets the print writer which is an object responsible for displaying results.
Parameters:
PW - the object representing the print writer.

getEntry

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

start

public java.util.Vector start(java.lang.String str)
                       throws SBQLException
The main method responsible for program interpretation. First it takes the string query and converts it into stream (StringReader). Then the lexing/parsing process takes the part, which yields in the abstract syntax tree form of the source program. Then the evaluation process starts and at the end, the results of such evaluation, are returned as an vector object (Vector).
Parameters:
str - a string representation of a query/program.
Returns:
the vector object with the results of a query/program.
Throws:
SBQLException - if interpretation (lexing/parsing/evaluating) process fails.

convertToProtocolResult

public Result convertToProtocolResult(QueryResult r)
The method takes the query/program result as an argument and converts it into the form which is suitable for serialization (used for passing the results through network).
Parameters:
r - the possible result of the program interpretation.
Returns:
the converted result.
See Also:
QueryResult, Result

initializeENVS

public void initializeENVS()
The method responsible for initializing environmental stack. The initializing process puts the identifiers of root objects from data store at the lowest section (activation record) of the environmental stack. The identifiers are formed into binders.
See Also:
EnvironmentalStack, ActivationRecord, IdentifierValue, BinderValue

dumpENVS

public javax.swing.tree.DefaultMutableTreeNode dumpENVS()
Returns the structure of environmental stack suitable for displaying it on graphic panel in tree form.
Returns:
environmental stack structure suitable form displaying it on graphic panel.
See Also:
EnvironmentalStack

dumpENVS

public void dumpENVS(javax.swing.tree.DefaultMutableTreeNode parentNode)
The dumpENVS is the recursive method which prepares the environmental stack structure for being displayed on graphic interface.
Parameters:
parentNode - is the node representing the parent of the actual node, in the tree hierarchy.

dumpAST

public javax.swing.tree.DefaultMutableTreeNode dumpAST()
Returns the structure of abstract syntax tree suitable for displaying it on graphic panel in tree form.
Returns:
abstract syntax tree structure suitable form displaying it on graphic panel.
See Also:
AbstractSyntaxTree

dumpAST

public void dumpAST(AbstractSyntaxTree AST,
                    javax.swing.tree.DefaultMutableTreeNode parentNode)
The dumpAST is the recursive method which prepares the abstract syntax tree structure for being displayed on graphic interface.
Parameters:
AST - is the abstract syntax tree node representing the actual node.
parentNode - is the node representing the parent of the actual node, in the tree hierarchy.

dumpDB

public javax.swing.tree.DefaultMutableTreeNode dumpDB()
Returns the structure of object store suitable for displaying it on graphic interface in the tree form.
Returns:
object store structure suitable form displaying it on graphic panel.