コード例 #1
0
        public void _unary()
        {
            switch (curLex.get_type())
            {
            case Type_of_lex.LEX_openRoundBracket:
                getLex();
                expression();
                if (curLex.get_type() != Type_of_lex.LEX_closeRoundBracket)
                {
                    throw new SystemException(curLex.ToString());
                }
                else
                {
                    getLex();
                }
                break;

            case Type_of_lex.LEX_plusPlus:
                push(curLex);
                getLex();
                lvalue();
                check_unary_left_op();
                break;

            case Type_of_lex.LEX_minusMinus:
                push(curLex);
                getLex();
                lvalue();
                check_unary_left_op();
                break;

            case Type_of_lex.LEX_id:
                Lexem hlp = curLex;
                getLex();
                putBufLexem(hlp);
                //если это вызов функции, причем описанной в коде, не встроенной
                if (curLex.get_type() == Type_of_lex.LEX_openRoundBracket)
                {
                    chngBufANDcurLexem();
                    checkId(false);
                    function_call();
                }
                else
                {
                    chngBufANDcurLexem();
                    lvalue();
                    if (curLex.get_type() == Type_of_lex.LEX_plusPlus)
                    {
                        push(curLex);
                        check_unary_right_op();
                        getLex();
                    }
                    if (curLex.get_type() == Type_of_lex.LEX_minusMinus)
                    {
                        push(curLex);
                        check_unary_right_op();
                        getLex();
                    }
                }

                break;

            default:
                if (is_internal_function())
                {
                    internal_functions();
                }
                else
                {
                    _const();
                }
                break;
            }
        }
コード例 #2
0
 void putBufLexem(Lexem ar)
 {
     bufLexem = ar;
 }
コード例 #3
0
        //--------------------встроенные функции конец

        //"foreach" "(" identifier "in" identifier ")" block
        public void _foreach()
        {
            List <Lexem> lex_list = new List <Lexem>(3);
            Lexem        lex_iter;
            string       iterator_name = "";

            getLex();
            if (curLex.get_type() == Type_of_lex.LEX_openRoundBracket)
            {
                for (int i = 0; i < 3; i++)
                {
                    getLex();
                    lex_list.Add(new Lexem(curLex));
                }
                if (lex_list[1].get_type() != Type_of_lex.LEX_in || lex_list[0].get_type() != Type_of_lex.LEX_id ||
                    lex_list[2].get_type() != Type_of_lex.LEX_id)
                {
                    throw new SystemException(curLex.ToString());
                }
                getLex();
                if (curLex.get_type() != Type_of_lex.LEX_closeRoundBracket)
                {
                    throw new SystemException(curLex.ToString());
                }
                getLex();
            }
            else
            {
                throw new SystemException(curLex.ToString());
            }
            //аналог condition
            int pl0, pl1;

            iterator_name = add_new_uniq_lexId(Type_of_lex._int, null, null);
            lex_iter      = new Lexem(Type_of_lex._int, iterator_name);
            //tableId.putValueOfLex(lex_iter, "0");
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_ADDR, tableId.getNumOfLex(lex_iter).ToString()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex._int, "0"));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_assign));


            tableId.addId(new LexID(new Lexem(Type_of_lex._htmlelement, lex_list[0].getName()), null, null));
            tableId.putValueOfLex(new Lexem(Type_of_lex._htmlelement, lex_list[0].getName()), lex_list[0].getName());

            pl0 = tableId.poliz_get_free();
            //condition start
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_id, iterator_name));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_id, lex_list[2].getName()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_ElCcnt));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_less));
            //condition end
            pl1 = tableId.poliz_get_free();
            tableId.poliz_blank();
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_FGO));
            //---------block start
            //в начале блока надо сделать elem = elemCollect[i]
            //tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_ADDR, tableId.getNumOfLex(lex_list[0]).ToString()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_id, lex_list[0].getName()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_id, lex_list[2].getName()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_id, iterator_name));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_ElCbyNum));
            //tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_assign));
            block();
            //реализует i++ в while
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_ADDR, tableId.getNumOfLex(lex_iter).ToString()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.LEX_plusPlus));
            //в конце i++
            //---------block end
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_LABEL, pl0.ToString()));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_GO));
            tableId.poliz_put_lex(new Lexem(Type_of_lex.POLIZ_LABEL, tableId.poliz_get_free().ToString()), pl1);
        }
コード例 #4
0
 void push(Lexem lex)
 {
     tableId.push(lex);
 }
コード例 #5
0
 void getBufLexem()
 {
     curLex   = bufLexem;
     bufLexem = null;
 }
コード例 #6
0
ファイル: Lexem.cs プロジェクト: yudov-maksim/web-scraping
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="lex">Инициализирует экземпляр класса существующей лексемой</param>
 public Lexem(Lexem lex)
 {
     t_lex = lex.get_type();
     name  = lex.getName();
 }
コード例 #7
0
ファイル: Executer.cs プロジェクト: yudov-maksim/web-scraping
        /// <summary>
        /// Реализует выполнение ПОЛИЗа
        /// </summary>
        public void execute()
        {
            Lexem       lex, lex1, lex2;
            bool        b;
            string      val, hlp_str;
            int         i, j, size = prog.get_free(), num;
            Type_of_lex t;

            if (wb.exit_run > 0)
            {
                wb.exit_run--;
                cur_step_poliz++;
            }
            while (cur_step_poliz < size)
            {
                curLex = prog.arr[cur_step_poliz];
                switch (curLex.get_type())
                {
                case Type_of_lex._int:
                case Type_of_lex._double:
                case Type_of_lex._string:
                case Type_of_lex._bool:
                case Type_of_lex.POLIZ_ADDR:
                case Type_of_lex.POLIZ_LABEL:
                    args.Push(curLex);
                    break;

                case Type_of_lex.LEX_id:
                    //Проверили, не вызов ли функции
                    if (!id_is_func(curLex))
                    {
                        lex = new Lexem(tableId.get_type_of_lex(curLex.getName()), tableId.get_value_of_lex(curLex.getName()));
                        args.Push(lex);
                    }
                    else
                    {
                        if (tableId.getNumOfFunc(curLex.getName()) < tableId.get_inet_func_num())
                        {
                            bool need_exit_in_wait_loop = run_inet_func(curLex.getName());

                            if (need_exit_in_wait_loop)
                            {
                                system_print(">>>exit in main wait loop<<<");
                                wb.exit_run--;
                                cur_step_poliz++;
                                return;
                            }
                        }
                        else
                        {
                            run_func(curLex.getName());
                        }
                    }
                    break;

                case Type_of_lex.LEX_ElCcnt:
                    lex = args.Pop();
                    args.Push(new Lexem(Type_of_lex._int, tableId.get_htmlElemCollect_of_lex(lex.getName()).Count.ToString()));
                    break;

                case Type_of_lex.LEX_ElCbyNum:
                    lex  = args.Pop();   //iterator
                    lex1 = args.Pop();   //elem_collection
                    lex2 = args.Pop();   //elem

                    HtmlElement hc = tableId.get_htmlElemCollect_of_lex(lex1.getName())[Convert.ToInt32(lex.getName())];
                    tableId.putHtmlElemValueOfLex(tableId.getNumOfLex(lex2), hc);
                    break;

                case Type_of_lex.LEX_WRITE:
                    //System.Console.WriteLine(args.Pop().getName());
                    system_print(args.Pop().getName());
                    break;

                case Type_of_lex.LEX_READ:
                    lex = args.Pop();
                    //val = System.Console.ReadLine();
                    val = system_read();
                    tableId.putValueOfLex(Convert.ToInt32(lex.getName()), val);
                    break;

                case Type_of_lex.LEX_not:
                    lex = args.Pop();
                    args.Push(new Lexem(lex.get_type(), getValueFromBool(!getBoolFromValue(lex))));
                    break;

                case Type_of_lex.LEX_or:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    b    = getBoolFromValue(lex1) || getBoolFromValue(lex2);
                    args.Push(new Lexem(Type_of_lex._bool, getValueFromBool(b)));
                    break;

                case Type_of_lex.LEX_and:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    b    = getBoolFromValue(lex1) && getBoolFromValue(lex2);
                    args.Push(new Lexem(Type_of_lex._bool, getValueFromBool(b)));
                    break;

                case Type_of_lex.POLIZ_GO:
                    cur_step_poliz = Convert.ToInt32(args.Pop().getName()) - 1;
                    break;

                case Type_of_lex.POLIZ_FGO:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    if (!getBoolFromValue(lex2))
                    {
                        cur_step_poliz = Convert.ToInt32(lex1.getName()) - 1;
                    }
                    break;

                case Type_of_lex.LEX_UPLUS:
                    break;

                case Type_of_lex.LEX_UMINUS:
                    lex1 = args.Pop();
                    val  = "-" + lex1.getName();
                    args.Push(new Lexem(lex1.get_type(), val));
                    break;

                case Type_of_lex.LEX_minusMinus:
                case Type_of_lex.LEX_MINUSMINUSright:
                    lex1    = args.Pop();
                    num     = Convert.ToInt32(lex1.getName());
                    t       = tableId.getTypeofLex(num);
                    hlp_str = tableId.get_value_of_lex(num);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = hlp_str.Remove(hlp_str.Length - 1);
                        break;

                    case Type_of_lex._bool:
                        bool a1 = getBoolFromValue(new Lexem(Type_of_lex._bool, hlp_str));
                        b   = !a1;
                        val = getValueFromBool(b);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(hlp_str) - 1).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(hlp_str) - 1).ToString();
                        break;

                    default:
                        val = hlp_str.Remove(hlp_str.Length - 1);
                        break;
                    }
                    tableId.putValueOfLex(Convert.ToInt32(lex1.getName()), val);
                    if (curLex.get_type() == Type_of_lex.LEX_minusMinus)
                    {
                        args.Push(new Lexem(t, val));
                    }
                    else
                    {
                        args.Push(new Lexem(t, hlp_str));
                    }
                    break;

                case Type_of_lex.LEX_plusPlus:
                case Type_of_lex.LEX_PLUSPLUSright:
                    lex1    = args.Pop();
                    num     = Convert.ToInt32(lex1.getName());
                    t       = tableId.getTypeofLex(num);
                    hlp_str = tableId.get_value_of_lex(num);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = hlp_str + " ";
                        break;

                    case Type_of_lex._bool:
                        bool a1 = getBoolFromValue(new Lexem(Type_of_lex._bool, hlp_str));
                        b   = !a1;
                        val = getValueFromBool(b);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(hlp_str) + 1).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(hlp_str) + 1).ToString();
                        break;

                    default:
                        val = hlp_str + " ";
                        break;
                    }
                    tableId.putValueOfLex(Convert.ToInt32(lex1.getName()), val);
                    if (curLex.get_type() == Type_of_lex.LEX_plusPlus)
                    {
                        args.Push(new Lexem(t, val));
                    }
                    else
                    {
                        args.Push(new Lexem(t, hlp_str));
                    }
                    break;

                case Type_of_lex.LEX_plus:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = lex1.getName() + lex2.getName();
                        break;

                    case Type_of_lex._bool:
                        bool a1 = getBoolFromValue(lex1), a2 = getBoolFromValue(lex2);
                        b   = !a1 && a2 || a1 && !a2;
                        val = getValueFromBool(b);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex1.getName()) + Convert.ToDouble(lex2.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex1.getName()) + Convert.ToInt32(lex2.getName())).ToString();
                        break;

                    default:
                        val = lex1.getName() + lex2.getName();
                        break;
                    }
                    args.Push(new Lexem(t, val));
                    break;

                case Type_of_lex.LEX_mul:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = lex1.getName() + lex2.getName();
                        break;

                    case Type_of_lex._bool:
                        bool a1 = getBoolFromValue(lex1), a2 = getBoolFromValue(lex2);
                        b   = a1 && a2;
                        val = getValueFromBool(b);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex1.getName()) * Convert.ToDouble(lex2.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex1.getName()) * Convert.ToInt32(lex2.getName())).ToString();
                        break;

                    default:
                        val = lex1.getName() + lex2.getName();
                        break;
                    }
                    args.Push(new Lexem(t, val));
                    break;

                case Type_of_lex.LEX_minus:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = "";
                        break;

                    case Type_of_lex._bool:
                        bool a1 = getBoolFromValue(lex1), a2 = getBoolFromValue(lex2);
                        b   = !a1 && a2 || a1 && !a2;
                        val = getValueFromBool(b);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) - Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) - Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    default:
                        val = "";
                        break;
                    }
                    args.Push(new Lexem(t, val));
                    break;

                case Type_of_lex.LEX_slash:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._string:
                        val = "";
                        break;

                    case Type_of_lex._bool:
                        val = getValueFromBool(false);
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) / Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) / Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    default:
                        val = "";
                        break;
                    }
                    args.Push(new Lexem(t, val));
                    break;

                case Type_of_lex.LEX_less:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._bool:
                        val = "";
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) < Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) < Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._string:
                    default:
                        i = String.Compare(lex2.getName(), lex1.getName());
                        if (i < 0)
                        {
                            val = "true";
                        }
                        else
                        {
                            val = "false";
                        }
                        break;
                    }
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_bigger:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._bool:
                        val = "";
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) > Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) > Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._string:
                    default:
                        i = String.Compare(lex2.getName(), lex1.getName());
                        if (i > 0)
                        {
                            val = "true";
                        }
                        else
                        {
                            val = "false";
                        }
                        break;
                    }
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_lessEq:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._bool:
                        val = "";
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) <= Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) <= Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._string:
                    default:
                        i = String.Compare(lex2.getName(), lex1.getName());
                        if (i <= 0)
                        {
                            val = "true";
                        }
                        else
                        {
                            val = "false";
                        }
                        break;
                    }
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_biggerEq:
                    lex1 = args.Pop();
                    lex2 = args.Pop();
                    t    = get_real_type(lex1, lex2);
                    switch (t)
                    {
                    case Type_of_lex._bool:
                        val = "";
                        break;

                    case Type_of_lex._double:
                        val = (Convert.ToDouble(lex2.getName()) >= Convert.ToDouble(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._int:
                        val = (Convert.ToInt32(lex2.getName()) >= Convert.ToInt32(lex1.getName())).ToString();
                        break;

                    case Type_of_lex._string:
                    default:
                        i = String.Compare(lex2.getName(), lex1.getName());
                        if (i >= 0)
                        {
                            val = "true";
                        }
                        else
                        {
                            val = "false";
                        }
                        break;
                    }
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_neq:
                    val = (args.Pop().getName() != args.Pop().getName()).ToString();
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_eq:
                    val = (args.Pop().getName() == args.Pop().getName()).ToString();
                    args.Push(new Lexem(Type_of_lex._bool, val));
                    break;

                case Type_of_lex.LEX_assign:
                    lex1 = args.Pop();    //что присваиваем
                    lex2 = args.Pop();    //куда присваиваем
                    val  = lex1.getName();
                    if (lex1.get_type() != Type_of_lex._htmlelement && lex1.get_type() != Type_of_lex._htmlelementcollect)
                    {
                        tableId.putValueOfLex(Convert.ToInt32(lex2.getName()), val);
                    }
                    //в вычислителе лежало имя, а реальное значение надо взять из таблицы идентификаторов
                    else
                    {
                        tableId.putValueOfLex(Convert.ToInt32(lex2.getName()), val, true);
                    }
                    break;
                }
                cur_step_poliz++;
            }//end of while
            if (cur_step_poliz >= size)
            {
                if (wb.isConsoleVersion)
                {
                    Application.Exit();
                }
            }
        }
コード例 #8
0
ファイル: Executer.cs プロジェクト: yudov-maksim/web-scraping
        /// <summary>
        /// Реализует выполнение описанных пользователем функций
        /// </summary>
        /// <param name="func_name"></param>
        public void run_func(string func_name)
        {
            int                old_curFunc = tableId.get_curFunc();
            int                num_of_func = tableId.getNumOfFunc(func_name);
            int                num_params  = tableId.get_num_of_param(func_name);
            int                old_csp     = cur_step_poliz;
            HtmlElement        helem;
            List <HtmlElement> helemCollect, collect_to_run_func;

            Lexem[] lex_arr = new Lexem[num_params];
            //в массиве лежат либо константы, либо переменные

            //создать новый экземпляр класса executer и вызвать из него выполнение проги
            setCurFunc(num_of_func);
            //Да, ничего не скопирует, но рекурсия станет возможной
            Executer func_exec = new Executer(tableId, in_stream, out_stream, wb);

            //передача параметров в вызываемую функцию
            for (int i = num_params - 1; i >= 0; i--)
            {
                lex_arr[i] = args.Pop();
            }
            //обнуление всех переменных внутри функции
            //func_exec.tableId.initialize_all_vars();
            for (int i = 0; i < num_params; i++)
            {
                if (lex_arr[i].get_type() == Type_of_lex._htmlelement || lex_arr[i].get_type() == Type_of_lex._htmlelementcollect)
                {
                    //func_exec.tableId.putValueOfLex(i, lex_arr[i].getName(), true);
                    setCurFunc(old_curFunc);
                    if (lex_arr[i].get_type() == Type_of_lex._htmlelement)
                    {
                        helem = func_exec.tableId.get_htmlElem_of_lex(lex_arr[i].getName());
                        setCurFunc(num_of_func);
                        func_exec.tableId.putHtmlElemValueOfLex(i, helem);
                    }
                    else
                    {
                        helemCollect = tableId.get_htmlElemCollect_of_lex(lex_arr[i].getName());
                        setCurFunc(num_of_func);

                        collect_to_run_func = new List <HtmlElement>(helemCollect.Count);
                        for (int j = 0; j < helemCollect.Count; j++)
                        {
                            collect_to_run_func.Add(helemCollect[j]);
                        }
                        //тут нужно передать не ссылку, а новый список
                        func_exec.tableId.putHtmlElemCollectValueOfLex(i, collect_to_run_func);
                    }
                }
                else
                {
                    func_exec.tableId.putValueOfLex(i, lex_arr[i].getName());
                }
                if (lex_arr[i].get_type() != Type_of_lex._undefined)
                {
                    func_exec.putTypeofLex(i, lex_arr[i].get_type());
                }
            }
            func_exec.execute();
            Lexem lex = null;

            if (func_exec.args.Count > 0)
            {
                lex = func_exec.args_pop();
            }

            //для добавления вспомогательной переменной
            if (lex != null)
            {
                Type_of_lex type = tableId.getTypeOfFunc(func_name);
                if (type == Type_of_lex._htmlelement || type == Type_of_lex._htmlelementcollect)
                {
                    string             res_name        = "";
                    HtmlElement        htmlElem        = null;
                    List <HtmlElement> htmlElemCollect = null;
                    if (type == Type_of_lex._htmlelement)
                    {
                        htmlElem        = tableId.get_htmlElem_of_lex(lex.getName());
                        htmlElemCollect = null;
                    }
                    else
                    {
                        htmlElemCollect = tableId.get_htmlElemCollect_of_lex(lex.getName());
                        htmlElem        = null;
                    }
                    setCurFunc(old_curFunc);
                    res_name = add_new_uniq_lexId(type, htmlElem, htmlElemCollect);
                    lex.putName(res_name);
                }
                args.Push(lex);
            }
            setCurFunc(old_curFunc);
            cur_step_poliz = old_csp;
        }
コード例 #9
0
ファイル: Executer.cs プロジェクト: yudov-maksim/web-scraping
        /// <summary>
        /// Реализует выполнение встроенных функций
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool run_inet_func(string name)
        {
            HtmlElement        htmlElem      = null;
            List <HtmlElement> htmlElem_list = null;
            string             res           = "";
            bool bl;

            int num_params = tableId.get_num_of_param(name);

            Lexem[] lex_arr = new Lexem[num_params];
            //в массиве лежат либо константы, либо переменные

            for (int i = num_params - 1; i >= 0; i--)
            {
                lex_arr[i] = args.Pop();
            }

            //switch по функциям
            switch (name)
            {
            case "click_by_id":
                wb.click_by_id(lex_arr[0].getName());
                break;

            case "check_by_id":
                bl  = wb.check_by_id(lex_arr[0].getName());
                res = getValueFromBool(bl);
                break;

            case "input_by_id":
                wb.input_by_id(lex_arr[0].getName(), lex_arr[1].getName());
                break;

            case "go":
                wb.go(lex_arr[0].getName());
                break;

            case "check_by_text":
                bl  = wb.check_by_text(lex_arr[0].getName());
                res = getValueFromBool(bl);
                break;

            case "set_options":
                wb.set_options(lex_arr[0].getName());
                break;

            case "click_href":
                wb.click_href(lex_arr[0].getName());
                break;

            case "click_by_text":
                wb.click_by_text(lex_arr[0].getName());
                break;

            case "set_check_box_flag":
                wb.set_check_box_flag(lex_arr[0].getName(), getBoolFromValue(lex_arr[1]));
                break;

            case "click_check_box_flag":
                wb.click_check_box_flag(lex_arr[0].getName());
                break;

            case "click_elem":
                wb.click_elem(tableId.get_htmlElem_of_lex(lex_arr[0].getName()));
                break;

            //----------------------
            case "get_tree":
                htmlElem_list = wb.get_tree(lex_arr[0].getName());
                break;

            case "get_elements_by_tag":
                htmlElem_list = wb.get_elements_by_tag(lex_arr[0].getName());
                break;

            case "get_elements_by_attr_value":
                htmlElem_list = wb.get_elements_by_attr_value(lex_arr[0].getName(), lex_arr[1].getName());

                break;

            case "save":
                htmlElem = tableId.get_htmlElem_of_lex(lex_arr[0].getName());
                //res = wb.save(htmlElem, lex_arr[1].getName());
                wb.save(htmlElem, lex_arr[1].getName());
                break;

            case "saveHTML":
                htmlElem = tableId.get_htmlElem_of_lex(lex_arr[0].getName());
                //res = wb.saveHTML(htmlElem, lex_arr[1].getName());
                wb.saveHTML(htmlElem, lex_arr[1].getName());
                break;

            case "save_images":
                htmlElem = tableId.get_htmlElem_of_lex(lex_arr[0].getName());
                wb.save_images(htmlElem, lex_arr[0].getName());
                break;

            //-------------------------
            case "get_element_with_num":
                htmlElem = tableId.get_htmlElemCollect_of_lex(lex_arr[0].getName())[Convert.ToInt32(lex_arr[1].getName())];
                break;

            case "get_length":
                res = tableId.get_htmlElemCollect_of_lex(lex_arr[0].getName()).Count.ToString();
                break;

            case "input_elem":
                wb.input_elem(tableId.get_htmlElem_of_lex(lex_arr[0].getName()), lex_arr[1].getName());
                break;

            case "set_check_box_elem":
                wb.set_check_box_elem(tableId.get_htmlElem_of_lex(lex_arr[0].getName()), getBoolFromValue(lex_arr[1]));
                break;

            case "set_options_elem":
                wb.set_options_elem(tableId.get_htmlElem_of_lex(lex_arr[0].getName()), lex_arr[1].getName());
                break;

            case "wait":
                wb.wait(Convert.ToInt32(lex_arr[0].getName()));
                break;

            case "go_back":
                wb.go_back();
                break;

            default:
                break;
            }
            Type_of_lex type = tableId.getTypeOfFunc(name);

            if (type != Type_of_lex._void)
            {
                if (type == Type_of_lex._htmlelement || type == Type_of_lex._htmlelementcollect)
                {
                    res = add_new_uniq_lexId(type, htmlElem, htmlElem_list);
                }
                args.Push(new Lexem(type, res));
            }
            //cur_step_poliz++;
            return(tableId.get_has_event_func(name));
        }
コード例 #10
0
ファイル: Scanner.cs プロジェクト: yudov-maksim/web-scraping
        /// <summary>
        /// Возвращает лексему
        /// </summary>
        /// <returns></returns>
        public Lexem get_lex()
        {
            string numb_value = "";

            curState = State.H;
            int   num_in_tables = 0;
            Lexem resLex        = new Lexem();

            do
            {
                switch (curState)
                {
                case State.H:
                    if (curSymb == ' ' || curSymb == '\n' || curSymb == '\r' || curSymb == '\t')
                    {
                        gc();
                    }
                    else if (Char.IsLetter(curSymb))
                    {
                        clear();
                        add();
                        gc();
                        curState = State.IDENT;
                    }
                    else if (Char.IsDigit(curSymb))
                    {
                        //numb_value += curSymb;
                        curState = State.NUMB;
                    }
                    else if (curSymb == '>' || curSymb == '<' || curSymb == '!' || curSymb == '=')
                    {
                        clear();
                        add();
                        gc();
                        curState = State.CMP_2_SYMB;
                    }
                    else if (curSymb == '"')
                    {
                        clear();
                        gc();
                        curState = State.STRING;
                    }
                    else if (curSymb == '&' || curSymb == '|')
                    {
                        clear();
                        add();
                        gc();
                        curState = State.AND_OR;
                    }
                    else if (curSymb == '+' || curSymb == '-')
                    {
                        clear();
                        add();
                        gc();
                        curState = State.PLUSPLUS_MINUSMINUS;
                    }
                    else if (file.Peek() == -1)
                    {
                        file.Close();
                        return(new Lexem(Type_of_lex.LEX_fin));
                    }
                    else
                    {
                        curState = State.DELIM;
                    }
                    break;

                case State.IDENT:
                    if (Char.IsLetterOrDigit(curSymb) || curSymb == '_')
                    {
                        add();
                        gc();
                    }
                    else if ((num_in_tables = look(word, keyWordsNamesTable)) != -1)        //ключевое слово
                    {
                        return(new Lexem(keyWordsTable[num_in_tables], word));
                    }
                    else
                    {
                        return(new Lexem(Type_of_lex.LEX_id, word));   //идентификатор
                    }
                    break;

                case State.NUMB:
                    if (Char.IsDigit(curSymb))
                    {
                        //d = d * 10 + (c - '0');
                        numb_value += curSymb;
                        gc();
                    }
                    else
                    {
                        return(new Lexem(Type_of_lex.LEX_num, numb_value));
                    }
                    break;

                case State.STRING:
                    if (curSymb == '"')
                    {
                        gc();
                        curState = State.H;
                        return(new Lexem(Type_of_lex.LEX_string, word));
                    }
                    else
                    {
                        add();
                        gc();
                    }
                    break;

                case State.CMP_2_SYMB:
                    if (curSymb == '=')
                    {
                        add();
                        gc();
                        num_in_tables = look(word, delimNamesTable);
                        return(new Lexem(delimTable[num_in_tables]));
                    }
                    else
                    {
                        num_in_tables = look(word, delimNamesTable);
                        return(new Lexem(delimTable[num_in_tables]));
                    }

                //break;
                case State.AND_OR:
                    if (curSymb == word[0])
                    {
                        add();
                        gc();
                        num_in_tables = look(word, delimNamesTable);
                        return(new Lexem(delimTable[num_in_tables]));
                    }
                    else
                    {
                        throw new SystemException(curSymb.ToString());
                    }

                //break;
                case State.PLUSPLUS_MINUSMINUS:
                    if (curSymb == word[0])
                    {
                        add();
                        gc();
                        num_in_tables = look(word, delimNamesTable);
                        return(new Lexem(delimTable[num_in_tables]));
                    }
                    else
                    {
                        num_in_tables = look(word, delimNamesTable);
                        return(new Lexem(delimTable[num_in_tables]));
                    }

                //break;
                case State.DELIM:
                    clear();
                    add();
                    if ((num_in_tables = look(word, delimNamesTable)) != -1)
                    {
                        gc();
                        return(new Lexem(delimTable[num_in_tables]));
                    }
                    else
                    {
                        throw new SystemException(curSymb.ToString());    //event описать
                    }

                //break;
                default:
                    return(new Lexem(Type_of_lex.LEX_NULL));
                }
            } while (true);
        }