Example #1
0
 /**
  * Function VisitIdentExpr : it checks if the variable exists in
  * the table (previous declared) and returns its value.
  * Otherwise it throws an error cause it was not declared
  * Param : identifier expression to check
  * Return : the type of the identifier
  */
 public VALTYPE VisitIdentExpr(Expr.Ident expr)
 {
     if (SymbleTypeTable.ContainsKey(expr.Name.Text))
     {
         return(SymbleTypeTable[expr.Name.Text]);
     }
     else
     {
         throw new TypeError(expr.Name, expr.Name.Text + " got referenced before it was declared.");
     }
 }
Example #2
0
 /**
  * Function VisitIdentExpr
  * Param : identifier expression to visit
  * Return : text if environment is null or the value inside the environment
  */
 public string VisitIdentExpr(Expr.Ident expr)
 {
     if (Environment == null)
     {
         return(expr.Name.Text);
     }
     else
     {
         return(expr.Name.Text + "(=" + Environment[expr.Name.Text].Val.ToString() + ")");
     }
 }
Example #3
0
        /**
         * Function VisitIdentExpr : it evaluates an identifier expression
         * Param : identifier expression to evaluate
         * Return : the value of the identifier in the symble table or
         *			throws an error if the var was not previous declared
         */
        public Value VisitIdentExpr(Expr.Ident expr)
        {
            String name = expr.Name.Text;

            if (SymbleTable.ContainsKey(name))
            {
                Value value = SymbleTable[name];
                if (value.Val == null)
                {
                    throw new RuntimeError(expr.Name, name + " is not initialized.");
                }
                return(SymbleTable[name]);
            }
            else
            {
                throw new RuntimeError(expr.Name, "Not declared variable.");
            }
        }