Classes | Functions

nodes.h File Reference

#include <list>
#include <sstream>
#include <vector>

Go to the source code of this file.

Classes

class  SyntaxNode
 This is a node in the operator tree. More...
class  StageNodeNode
class  SyntaxNodeIx
 A node on the operator tree representing an indexing expression. More...
class  ValueNodeBase
class  IDNode
 A node on the tree representing a user identifier (ie variable name). More...
class  SyntaxNodeIDREF
 A node on the tree representing a reference to a ModelComp. More...
class  ValueNode< T >
 Represents a value. More...
class  ListNode
 Represents a comma separated list of SyntaxNodes. More...
class  OpNode
 Represents an operator. More...

Functions

ListNodeaddItemToListOrCreate (int oc, ListNode *list, SyntaxNode *newitem)
 A 'List' is a SyntaxNode of opCode COMMA or ' ' with a variable number of arguments.
std::string print_SyntaxNodesymb (const SyntaxNode *node)
std::ostream & operator<< (std::ostream &s, const SyntaxNode &node)
std::ostream & operator<< (std::ostream &s, const SyntaxNode *node)
 Recursively prints the expression rooted at the current node in the expression tree.
SyntaxNodefindKeywordinTree (SyntaxNode *root, int oc)
 Traverses down the tree and returns the topmost reference to the keyword in the Tree.
SyntaxNodefind_var_ref_in_context (AmplModel *context, SyntaxNode *ref)
 This routine does the work of putting together dot'd variable names 'root' is a SyntaxNode of type ID that points to the left hand part of the dot'd expression parsed so far.
SyntaxNodefind_var_ref_in_indexing (const std::string &name)
 Scan through the current set of active indexing expressions and see if any of them defines the dummy variable given by 'name'.

Function Documentation

ListNode* addItemToListOrCreate ( int  oc,
ListNode list,
SyntaxNode newitem 
)

A 'List' is a SyntaxNode of opCode COMMA or ' ' with a variable number of arguments.

This function takes (a possibly existing) list and adds an item to it.

Both the list and the item can be NULL:

  • if the item is NULL then the old list is simply returned;
  • if the list is NULL then a list with opCode 'oc' is created from the single item that is passed.

References COMMA, SyntaxNode::getOpCode(), and SyntaxNode::push_back().

Referenced by yyparse().

SyntaxNode* find_var_ref_in_context ( AmplModel context,
SyntaxNode ref 
)

This routine does the work of putting together dot'd variable names 'root' is a SyntaxNode of type ID that points to the left hand part of the dot'd expression parsed so far.

'ref' is the new part that should be added.

Parameters:
context A pointer to the current AmplModel that defines the scope in which the ID expressions should be resolved.
ref A pointer to an expression that evaluates to a ModelComp: this can be given by an ID, a dotted expression ID.ID or a reference to a parent stage (in StochProg) such as ID(-1;...). It can also carry an indexing expressinon ID[.,.,.] in which case the indexing is attached to the returned IDREF node.
Returns:
A SyntaxNode of type IDREF that points to the correct ModelComp.
Bug:
Should return a SyntaxNodeIDREF*.

A SyntaxNode of type IDREF looks like this ->opCode = IDREF; ->nval = # of arguments ->values[0] = pointer to entity in model list ->values[1 - n] = arguments

References SyntaxNode::begin(), AmplModel::find_var_ref_in_context(), find_var_ref_in_indexing(), SyntaxNode::getOpCode(), IDNode::getStochParent(), IDNode::id(), GlobalVariables::logParseModel, LSBRACKET, SyntaxNode::push_back(), and SyntaxNodeIDREF::setStochParent().

Referenced by yyparse().

SyntaxNode* find_var_ref_in_indexing ( const string &  name  ) 

Scan through the current set of active indexing expressions and see if any of them defines the dummy variable given by 'name'.

Parameters:
name The name of identifier to look for.

int n_indexing the currently active indexing expressions SyntaxNode *list_of_indexing

Returns:
The Indexing expression in which the name occurs (or NULL if there is no match).

References SyntaxNodeIx::hasDummyVar(), list_of_indexing, n_indexing, and SyntaxNodeIx::splitExpression().

Referenced by find_var_ref_in_context().

SyntaxNode* findKeywordinTree ( SyntaxNode root,
int  oc 
)

Traverses down the tree and returns the topmost reference to the keyword in the Tree.

References SyntaxNode::begin(), SyntaxNode::end(), findKeywordinTree(), and SyntaxNode::getOpCode().

Referenced by findKeywordinTree(), and SyntaxNodeIx::splitExpression().

std::ostream& operator<< ( ostream &  s,
const SyntaxNode node 
)

Recursively prints the expression rooted at the current node in the expression tree.

Note:
use_global_names influences how nodes of type IDREF are printed.

References SyntaxNode::put().

std::ostream& operator<< ( std::ostream &  s,
const SyntaxNode node 
)

References SyntaxNode::put().

std::string print_SyntaxNodesymb ( const SyntaxNode node  )