当前位置: 首页>>代码示例>>C++>>正文


C++ Lex::getValue方法代码示例

本文整理汇总了C++中Lex::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Lex::getValue方法的具体用法?C++ Lex::getValue怎么用?C++ Lex::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lex的用法示例。


在下文中一共展示了Lex::getValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: start

    void Executer::start() {
        Lex curLex;
        while (curLex.getType() != LEX_FINISH) {
            curLex = getLex();
            switch (curLex.getType()) {
                case LEX_NUMBER:
                case LEX_STRING:
                case LEX_TRUE:
                case LEX_FALSE:
                case POLIZ_ADDRESS:
                    push(curLex);
                    break;
                case LEX_NAME: {
                    std::string value = curLex.getValue();
                    push(data[value]);
                    break;
                }
                case LEX_NOT: {
                    Lex val = pop();
                    push(Lex(LEX_STRING, val.getValue().length() ? "" : "1"));
                    break;
                }
                case LEX_ASSIGN: {
                    Lex val = pop(), address = pop();

                    data[address.getValue()] = val;
                    break;
                }
                case LEX_PLUS: {
                    Lex aStr = pop(), bStr = pop();

                    if (aStr.getType() == LEX_NUMBER && bStr.getType() == LEX_NUMBER) {
                        double a = std::atof(aStr.getValue().c_str()),
                                b = std::atof(bStr.getValue().c_str());

                        push(Lex(LEX_NUMBER, numToStr(a + b)));
                    }
                    else {
                        push(Lex(LEX_STRING, bStr.getValue() + aStr.getValue()));
                    }
                    break;
                }
                case LEX_MINUS: {
                    double a = lexToNum(pop()),
                            b = lexToNum(pop());

                    push(Lex(LEX_NUMBER, numToStr(b - a)));
                    break;
                }
                case LEX_MUL: {
                    double a = lexToNum(pop()),
                            b = lexToNum(pop());

                    push(Lex(LEX_NUMBER, numToStr(a * b)));
                    break;
                }
                case LEX_DIV: {
                    double a = lexToNum(pop()),
                            b = lexToNum(pop());

                    push(Lex(LEX_NUMBER, numToStr(b / a)));
                    break;
                }
                case POLIZ_GO: {
                    int pos = std::atoi(curLex.getValue().c_str());
                    goTo((size_t) pos);
                    break;
                }
                case POLIZ_FALSEGO: {
                    Lex condition = pop();
                    if (condition.getType() == LEX_STRING && condition.getValue() == "") {
                        int pos = std::atoi(curLex.getValue().c_str());
                        goTo((size_t) pos);
                        break;
                    }
                    if (condition.getType() == LEX_NUMBER)
                        if (condition.getValue() == "0") {
                            int pos = std::atoi(curLex.getValue().c_str());
                            goTo((size_t) pos);
                            break;
                        }
                    if (condition.getType() == LEX_FALSE) {
                        int pos = std::atoi(curLex.getValue().c_str());
                        goTo((size_t) pos);
                        break;
                    }
                    break;
                }
                case LEX_WRITE: {
                    std::cout << pop().getValue() << std::endl;
                    break;
                }
                case LEX_MORE: {
                    Lex a = pop(), b = pop();
                    if (a.getType() == LEX_FALSE && b.getType() == LEX_TRUE ||
                            a.getType() == LEX_NUMBER && b.getType() == LEX_NUMBER && lexToNum(a) < lexToNum(b))
                        push(Lex(LEX_TRUE, "1"));
                    else
                        push(Lex(LEX_FALSE, "0"));
                    break;
//.........这里部分代码省略.........
开发者ID:XaveScor,项目名称:Interpreter,代码行数:101,代码来源:Executer.cpp


注:本文中的Lex::getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。