ptolemy.codegen.rtmaude.kernel
Class RTMaudeParseTreeCodeGenerator

java.lang.Object
  extended by ptolemy.data.expr.AbstractParseTreeVisitor
      extended by ptolemy.codegen.rtmaude.kernel.RTMaudeParseTreeCodeGenerator
All Implemented Interfaces:
ParseTreeCodeGenerator, ParseTreeVisitor

public class RTMaudeParseTreeCodeGenerator
extends AbstractParseTreeVisitor
implements ParseTreeCodeGenerator

Generate RTMaude code for expressions.

Since:
Ptolemy II 8.0
Version:
$Id: RTMaudeParseTreeCodeGenerator.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Kyungmin Bae
Accepted Rating:
Red (kquine)
Proposed Rating:
Red (kquine)*

Field Summary
protected  java.io.PrintWriter _writer
          Used to accumulate generated strings.
private  java.lang.String result
           
 
Constructor Summary
RTMaudeParseTreeCodeGenerator()
          Create a new instance of the RTMaude parse tree code generator.
 
Method Summary
private  void _printChild(ASTPtRootNode node, int index)
          Visits the index-th child of the given node, so that the expression of the child node is generated.
private  void _printChildrenSeparated(ASTPtRootNode node, java.util.List separatorList)
          Visits all children of the given node, and the resulting expression is the list with the given separators.
private  void _printChildrenSeparated(ASTPtRootNode node, java.lang.String string, boolean paran)
          Visits all children of the given node, and the resulting expression is the list with the given separator.
private  java.lang.String _transformLeaf(java.lang.String id)
          Returns a RTMaude term from the given (Leaf) Ptolemy expression.
private static java.lang.String _transformOp(java.lang.String op)
          Returns a RTMaude operator from the given Ptolemy expression operator.
 java.lang.String escapeForTargetLanguage(java.lang.String string)
          Given a string, escape special characters as necessary for the target language.
 Token evaluateParseTree(ASTPtRootNode node, ParserScope scope)
          Evaluate the parse tree with the specified root node using the specified scope to resolve the values of variables.
 java.lang.String generateFireCode()
          Generate code that corresponds with the fire() method.
 void visitArrayConstructNode(ASTPtArrayConstructNode node)
           
 void visitBitwiseNode(ASTPtBitwiseNode node)
           
 void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
           
 void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
           
 void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
           
 void visitLeafNode(ASTPtLeafNode node)
           
 void visitLogicalNode(ASTPtLogicalNode node)
           
 void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
           
 void visitMethodCallNode(ASTPtMethodCallNode node)
           
 void visitPowerNode(ASTPtPowerNode node)
           
 void visitProductNode(ASTPtProductNode node)
           
 void visitRecordConstructNode(ASTPtRecordConstructNode node)
           
 void visitRelationalNode(ASTPtRelationalNode node)
           
 void visitShiftNode(ASTPtShiftNode node)
           
 void visitSumNode(ASTPtSumNode node)
           
 void visitUnaryNode(ASTPtUnaryNode node)
           
 
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode, visitUnionConstructNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_writer

protected java.io.PrintWriter _writer
Used to accumulate generated strings.


result

private java.lang.String result
Constructor Detail

RTMaudeParseTreeCodeGenerator

public RTMaudeParseTreeCodeGenerator()
Create a new instance of the RTMaude parse tree code generator.

Method Detail

evaluateParseTree

public Token evaluateParseTree(ASTPtRootNode node,
                               ParserScope scope)
                        throws IllegalActionException
Description copied from interface: ParseTreeCodeGenerator
Evaluate the parse tree with the specified root node using the specified scope to resolve the values of variables.

Specified by:
evaluateParseTree in interface ParseTreeCodeGenerator
Parameters:
node - The root of the parse tree.
scope - The scope for evaluation.
Returns:
The result of evaluation.
Throws:
IllegalActionException - If an error occurs during evaluation.

generateFireCode

public java.lang.String generateFireCode()
Description copied from interface: ParseTreeCodeGenerator
Generate code that corresponds with the fire() method.

Specified by:
generateFireCode in interface ParseTreeCodeGenerator
Returns:
The generated code.

visitLeafNode

public void visitLeafNode(ASTPtLeafNode node)
                   throws IllegalActionException
Specified by:
visitLeafNode in interface ParseTreeVisitor
Overrides:
visitLeafNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitArrayConstructNode

public void visitArrayConstructNode(ASTPtArrayConstructNode node)
                             throws IllegalActionException
Specified by:
visitArrayConstructNode in interface ParseTreeVisitor
Overrides:
visitArrayConstructNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitLogicalNode

public void visitLogicalNode(ASTPtLogicalNode node)
                      throws IllegalActionException
Specified by:
visitLogicalNode in interface ParseTreeVisitor
Overrides:
visitLogicalNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitBitwiseNode

public void visitBitwiseNode(ASTPtBitwiseNode node)
                      throws IllegalActionException
Specified by:
visitBitwiseNode in interface ParseTreeVisitor
Overrides:
visitBitwiseNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitPowerNode

public void visitPowerNode(ASTPtPowerNode node)
                    throws IllegalActionException
Specified by:
visitPowerNode in interface ParseTreeVisitor
Overrides:
visitPowerNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitProductNode

public void visitProductNode(ASTPtProductNode node)
                      throws IllegalActionException
Specified by:
visitProductNode in interface ParseTreeVisitor
Overrides:
visitProductNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitRelationalNode

public void visitRelationalNode(ASTPtRelationalNode node)
                         throws IllegalActionException
Specified by:
visitRelationalNode in interface ParseTreeVisitor
Overrides:
visitRelationalNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitShiftNode

public void visitShiftNode(ASTPtShiftNode node)
                    throws IllegalActionException
Specified by:
visitShiftNode in interface ParseTreeVisitor
Overrides:
visitShiftNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitSumNode

public void visitSumNode(ASTPtSumNode node)
                  throws IllegalActionException
Specified by:
visitSumNode in interface ParseTreeVisitor
Overrides:
visitSumNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitUnaryNode

public void visitUnaryNode(ASTPtUnaryNode node)
                    throws IllegalActionException
Specified by:
visitUnaryNode in interface ParseTreeVisitor
Overrides:
visitUnaryNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitFunctionalIfNode

public void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
                           throws IllegalActionException
Specified by:
visitFunctionalIfNode in interface ParseTreeVisitor
Overrides:
visitFunctionalIfNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitFunctionApplicationNode

public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
                                  throws IllegalActionException
Specified by:
visitFunctionApplicationNode in interface ParseTreeVisitor
Overrides:
visitFunctionApplicationNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitFunctionDefinitionNode

public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
                                 throws IllegalActionException
Specified by:
visitFunctionDefinitionNode in interface ParseTreeVisitor
Overrides:
visitFunctionDefinitionNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitMatrixConstructNode

public void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
                              throws IllegalActionException
Specified by:
visitMatrixConstructNode in interface ParseTreeVisitor
Overrides:
visitMatrixConstructNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitMethodCallNode

public void visitMethodCallNode(ASTPtMethodCallNode node)
                         throws IllegalActionException
Specified by:
visitMethodCallNode in interface ParseTreeVisitor
Overrides:
visitMethodCallNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

visitRecordConstructNode

public void visitRecordConstructNode(ASTPtRecordConstructNode node)
                              throws IllegalActionException
Specified by:
visitRecordConstructNode in interface ParseTreeVisitor
Overrides:
visitRecordConstructNode in class AbstractParseTreeVisitor
Throws:
IllegalActionException

_printChild

private void _printChild(ASTPtRootNode node,
                         int index)
                  throws IllegalActionException
Visits the index-th child of the given node, so that the expression of the child node is generated.

Parameters:
node - The node
index - The index which will be visited
Throws:
IllegalActionException

_printChildrenSeparated

private void _printChildrenSeparated(ASTPtRootNode node,
                                     java.util.List separatorList)
                              throws IllegalActionException
Visits all children of the given node, and the resulting expression is the list with the given separators.

Parameters:
node - The node
separatorList - The list of separators
Throws:
IllegalActionException

_printChildrenSeparated

private void _printChildrenSeparated(ASTPtRootNode node,
                                     java.lang.String string,
                                     boolean paran)
                              throws IllegalActionException
Visits all children of the given node, and the resulting expression is the list with the given separator.

Parameters:
node - The node
string - The separator
Throws:
IllegalActionException

_transformOp

private static java.lang.String _transformOp(java.lang.String op)
Returns a RTMaude operator from the given Ptolemy expression operator.

Parameters:
op - The given Ptolemy expression operator
Returns:
The RTMaude operator

_transformLeaf

private java.lang.String _transformLeaf(java.lang.String id)
Returns a RTMaude term from the given (Leaf) Ptolemy expression.

Parameters:
id - The given Ptolemy expression.
Returns:
The RTMaude term

escapeForTargetLanguage

public java.lang.String escapeForTargetLanguage(java.lang.String string)
Description copied from interface: ParseTreeCodeGenerator
Given a string, escape special characters as necessary for the target language.

Specified by:
escapeForTargetLanguage in interface ParseTreeCodeGenerator
Parameters:
string - The string to escape.
Returns:
A new string with special characters replaced.