getVar() public method

public getVar ( ) : VariableElement,
return VariableElement,
コード例 #1
0
ファイル: InterpreterVisitor_.cs プロジェクト: rkpandya/pinac
        public override void VisitMatrixElement(MatrixVariableDeclaration element)
        {
            string variable_name = element.getVar().getText();
            string type = element.getType();
            if (mVariableMap.Count == 0)
                mVariableMap.Add(variable_name, element);
            else
            {
                if (mVariableMap.Contains(variable_name))
                {
                    Console.Write(" \nSemantic Error.. ");
                    sendres(112, "\nSemantic Error...\n");
                    Console.Write("\n The matrix name you entered is already existing.. try again..");
                    sendres(112, "\n The matrix name you entered is already existing.. try again..");
                    return;
                }
                else
                {
                    mVariableMap.Add(variable_name, element);
                }
            }
            /*int row = int.Parse(element.getRow().getText());
            int col = int.Parse(element.getColumn().getText());
            Console.Write("\n Matrix name : ");
            Console.Write(variable_name);
            Console.Write("\nMatrix Type : ");
            Console.Write(type); Console.Write("\n");
            Console.Write(" Rows : "); Console.Write(row); Console.Write("\n");
            Console.Write(" Columns : "); Console.Write(col);
            string mat_type = element.getType();
            if (mat_type == "int")
            {
                int[,] elements = element.getintValue();
                Console.Write("\nMatrix Elements are : \n");
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        Console.Write(elements[i, j]);
                        Console.Write("\t");
                    }
                    Console.Write("\n");
                }
            }
            else if (mat_type == "double")
            {
                double[,] elemenets = element.getdoubleValue();
                if (elemenets != null)
                {
                    Console.Write("\n Matrix Elements are : \n");
                    for (int i = 0; i < row; i++)
                    {
                        for (int j = 0; j < col; j++)
                        {
                            Console.Write(elemenets[i, j]);
                            Console.Write("\t");
                        }
                        Console.Write("\n");
                    }
                }
            }
            Console.Write("\n");*/

            //throw new NotImplementedException();
        }
コード例 #2
0
ファイル: PrettyPrintVisitor.cs プロジェクト: shranjan/pinac
 public override void VisitMatrixElement(MatrixVariableDeclaration element)
 {
     Console.Write("Matrix<" + element.getType()+">[");
     VisitElement(element.getRow());
     Console.Write("][");
     VisitElement(element.getColumn());
     Console.Write("] ");
     VisitElement(element.getVar());
     Console.Write(" = [");
     List<Element> elem = element.getList();
     for (int i = 0; i < elem.Count; i++)
     {
         VisitElement(elem[i]);
         if (elem.Count > 1 && i!= (elem.Count-1))
         {
             Console.Write(",");
         }
     }
     Console.Write("];\n");
 }
コード例 #3
0
   //-----------<Test Stub>--------
 static void main(string[] args)
 {
     Console.WriteLine("\nTesting the MatrixVariableDeclaration class");
     Console.WriteLine("\n===========================================\n");
     MatrixVariableDeclaration elem_mat = new MatrixVariableDeclaration();
     VariableElement elem_var = new VariableElement();
     IntegerElement elem_int = new IntegerElement();
     //List<Element> elementlist = new List<Element>();
     string var = "matrix";
     string row = "3";
     string column = "2";
     elem_var.setText(var);
     elem_mat.setVar(elem_var);
     elem_int.setText(row);
     elem_mat.setRow(elem_int);
     elem_int.setText(column);
     elem_mat.setColumn(elem_int);
     for (int i = 0; i < (int.Parse(row) * int.Parse(column)); i++)
     {
         elem_int.setText(i.ToString());
         elem_mat.addValue(elem_int);
     }
     string type = "int";
     elem_mat.setType(type);
     elem_mat.setValue();
     int[,] matrix = new int[int.Parse(row), int.Parse(column)];
     matrix = elem_mat.getintValue();
     Console.WriteLine("The name of the Matrix is:{0}", elem_mat.getVar().getText());
     Console.WriteLine("The Row and Column of the Matrix is:{0},{1}", elem_mat.getRow().getText(), elem_mat.getColumn().getText());
     Console.WriteLine("The type of matrix is:{0}", elem_mat.getType());
     for(int i=0;i<int.Parse(row);i++)
     {
         for (int j = 0; j < int.Parse(column); j++)
         {
             Console.WriteLine("The value of matrix is:{0}", matrix[i, j]);
         }
     }
     
 }