示例#1
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);
        }
示例#2
0
 void putValueOfLex(int num, string name)
 {
     tableId.putValueOfLex(num, name);
 }