Exemplo n.º 1
0
  // FUNC: This function builds the map between LET-var names and
  // LET-expressions
  //
  //1. if the Let-var is already defined in the LET scope, then the
  //1. function returns an error.
  //
  //2. if the Let-var is already declared variable in the input, then
  //2. the function returns an error
  //
  //3. otherwise add the <var,letExpr> pair to the _letid_expr table.
  void LETMgr::LetExprMgr(const ASTNode& var, const ASTNode& letExpr) 
  {
    string name = var.GetName();
    MapType::iterator it;
    if(((it = _letid_expr_map->find(name)) != _letid_expr_map->end()))
    {
    FatalError("LetExprMgr:The LET-var v has already been defined"\
               "in this LET scope: v =", var);
    }

    if(_parser_symbol_table.find(var) != _parser_symbol_table.end())
    {
    FatalError("LetExprMgr:This var is already declared. "\
               "cannot redeclare as a letvar: v =", var);
    }

    LetExprMgr(var.GetName(),letExpr);
  }//end of LetExprMgr()
Exemplo n.º 2
0
  //this function looks up the "var to letexpr map" and returns the
  //corresponding letexpr. if there is no letexpr, then it simply
  //returns the var.
  ASTNode LETMgr::ResolveID(const ASTNode& v) 
  {
    if (v.GetKind() != SYMBOL) {
      return v;
    }

    if(_parser_symbol_table.find(v) != _parser_symbol_table.end()) {
      return v;
    }

    MapType::iterator it;
    if((it =_letid_expr_map->find(v.GetName())) != _letid_expr_map->end())
      {
        return it->second;
      }

    return v;    
  }//End of ResolveID()