⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expressionreader.cs

📁 编译原理语法分析和词法分析综合实验: 源程序、可执行程序、测试程序文件、程序运行说明文件、实验报告。
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace syn
{
    class ExpressionReader
    {
        private string expression = null;
        private int curPos = 0; // Indicate where is the beginning of reading block
        private int movPos = 0; // Indicate where is the ending of reading block

        public ExpressionReader(string expression)
        {
            this.expression = expression;
        }

        public void ResetPointer()
        {
            this.curPos = this.movPos = 0;
        }

        

        public ExpressAtom NextAtom()
        {
            ExpressAtom atom = null;
            
            while (movPos < expression.Length)
            {
                // Here, I suppose all operands are single char, otherwise change it to the Number style below
                if (Operator.IsOperator(expression[movPos]))
                {
                    atom = new ExpressAtom(new Operator( expression[movPos]));
                  
                    break;

                }
                if(Operand.IsOperand(expression[movPos]))
                {
                    curPos = movPos;
                    do
                    {
                        movPos++;
                        if(movPos>=expression.Length)
                            break;
                    } while ( Operand.IsOperand(expression[movPos]));
                    atom = new ExpressAtom(new Operand( expression.Substring(curPos, movPos - curPos)));
                    movPos--;
                    break;
                }


                movPos++;
                curPos = movPos;
            }
            // adjust posision pointer
            movPos++;
            curPos = movPos;

            return atom;
        }



        

        

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -