Exemplo n.º 1
0
        public override void 还原_C_源代码(StringBuilder sb)
        {
            sb.Append("for ( ");

            for (int i = 0; i < this.小括号表达式s.Length; i++)
            {
                表达式 express = this.小括号表达式s[i];

                if (express != null)
                {
                    express.还原_C_源代码(sb);
                }

                if (i < 2)
                {
                    sb.Append(";");
                }
            }
            //this.for_表达式.还原_C_源代码(sb);

            sb.Append(" )\r\n{\r\n");

            this.子句.还原_C_源代码(sb);

            sb.Append("}\r\n");
        }
Exemplo n.º 2
0
        public override void Set_作用域(作用域 作用域)
        {
            base.Set_作用域(作用域);

            作用域 小括号作用域 = new 作用域();

            for (int i = 0; i < this.小括号表达式s.Length; i++)
            {
                表达式 express = this.小括号表达式s[i];

                if (express == null)
                {
                    continue;
                }

                变量声明和初始化 变量声明 = express as 变量声明和初始化;

                if (变量声明 != null)
                {
                    小括号作用域.Add_变量定义(变量声明, 变量声明.chars);
                }

                express.Set_作用域(小括号作用域);
            }

            小括号作用域.Set_作用域(作用域);
            this.子句.Set_作用域(小括号作用域);
        }
Exemplo n.º 3
0
        //private static List<常量> Get_list_数组维度_Length(数组元素 数组元素, char[] chars)
        //{
        //    List<常量> list_数组维度_Length = new List<常量>();

        //    for (int i = 0; i < 数组元素.list下标.Count; i++)
        //    {
        //        //表达式 维度长度 = 数组元素.list下标[i];

        //        //常量 维度Length = 维度长度 as 常量;

        //        //if (维度Length == null)
        //        //    throw new InnerCException("数组维度长度声明应是常量 。", chars, 维度长度.参考位置_iLeft);

        //        //list_数组维度_Length.Add(维度Length);
        //    }

        //    return list_数组维度_Length;
        //}

        //private static bool Check_变量类型_KeyWord(char[] chars, int beginIndex, int endIndex, string str)
        //{
        //    bool b = 开头一段_Equals(chars, beginIndex, endIndex, str);

        //    if (!b)
        //        return false;

        //    char c = chars[str.Length + 1];

        //    if (StrUtil.IsOneOf(c, Parser._whiteSpaces) || c == '*')
        //        return true;

        //    return false;
        //}

        //private static bool Check_变量声明(char[] chars, int beginIndex, int endIndex, out string type)
        //{

        //    char c = chars[beginIndex];

        //    if (!(StrUtil.isLetter(c) || c == '_'))
        //    {
        //        type = null;
        //        return false;
        //    }


        //    int 空白和星号第一次出现的位置 = -1;

        //    for (int i=beginIndex + 1; i<=endIndex; i++)
        //    {
        //        c = chars[i];

        //        if (StrUtil.IsOneOf(c, _whiteSpaces和星号))
        //        {
        //            空白和星号第一次出现的位置 = i;

        //            break;
        //        }

        //        if (!(StrUtil.isLetter(c) || c == '_'))
        //        {
        //            type = null;
        //            return false;
        //        }
        //    }

        //    if (空白和星号第一次出现的位置 == -1)
        //    {
        //        type = null;
        //        return false;
        //    }

        //    for (int i = 空白和星号第一次出现的位置 + 1; i<=endIndex; i++)
        //    {
        //        c = chars[i];

        //        if (StrUtil.IsOneOf(c, _whiteSpaces和星号))
        //        {
        //            continue;
        //        }

        //        if (StrUtil.isLetter(c) || c == '_')
        //        {
        //            type = new string(chars, beginIndex, 空白和星号第一次出现的位置 - beginIndex);
        //            return true;
        //        }
        //        else
        //        {
        //            type = null;
        //            return false;
        //        }
        //    }

        //    type = null;
        //    return false;

        //}

        //private static bool 开头一段_Equals(char[] chars, int beginIndex, int endIndex, string str)
        //{
        //    if (endIndex - beginIndex >= str.Length)
        //        return false;

        //    int j;

        //    for (int i=0; i<str.Length; i++)
        //    {
        //        j = beginIndex + i;

        //        if (chars[j] != str[i])
        //            return false;
        //    }

        //    return true;
        //}

        //private static 语句 Parse_变量声明和赋值_语句(char[] chars, int beginIndex, int endIndex, string type, out int j, List<变量声明语句> list变量声明)
        //{
        //    int i = StrUtil.FindForwardUntilNot(chars, beginIndex + type.Length + 1, endIndex, _whiteSpaces和星号);

        //    if (i == -1)
        //        throw new InnerCException("未正确结束的 变量声明 语句 。", chars, beginIndex);

        //    StrSpan span = StrUtil.Trim(chars, beginIndex + type.Length, i - 1, Parser._whiteSpaces);

        //    int 星号Count = 0;

        //    for (int p = span.iLeft; p<= span.iRight; p++)
        //    {
        //        星号Count++;
        //    }

        //    j = Parser.Find_单引号对双引号对以外的内容(chars, i, endIndex, ';');

        //    if (j == -1)
        //        throw new InnerCException("未正确结束的 变量声明 语句 。", chars, i);

        //    int q = Parser.Find_单引号对双引号对以外的内容(chars, i, j - 1, '[');

        //    if (q == -1)
        //    {
        //        return Parse_普通变量声明(chars, i, j - 1, type, 星号Count, list变量声明);
        //    }
        //    else
        //    {
        //        return Parse_数组声明(chars, i, j - 1, q, type, 星号Count, list变量声明);
        //    }



        //}

        //private static 语句 Parse_普通变量声明(char[] chars, int beginIndex, int endIndex, string type, int 星号Count, List<变量声明语句>list变量声明)
        //{
        //    StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

        //    if (span.isEmpty)
        //        throw new InnerCException("未结束的变量声明语句 。", chars, beginIndex);

        //    表达式 express = C_Parser_3.Parse_表达式(chars, span.iLeft, span.iRight);

        //    变量 变量 = express as 变量;

        //    if (变量 != null)
        //    {
        //        list变量声明.Add(new 变量声明语句(type, 变量.name, 星号Count, null));
        //        return null;
        //    }

        //    赋值 赋值 = express as 赋值;

        //    if (赋值 != null)
        //    {
        //        list变量声明.Add(new 变量声明语句(type, 赋值.变量.name));
        //        return new 赋值语句(赋值);
        //    }

        //    throw new InnerCException("变量声明语句 的 类型 后应是 变量名 或 变量初始化 。", chars, span.iLeft);


        //}

        //private static 语句 Parse_数组声明(char[] chars, int beginIndex, int endIndex, int 第一个中括号出现位置, string type, int 星号Count, List<变量声明语句> list变量声明)
        //{
        //    StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

        //    if (span.isEmpty)
        //        throw new InnerCException("未结束的数组声明语句 。", chars, beginIndex);

        //    表达式 express = C_Parser_3.Parse_表达式(chars, span.iLeft, span.iRight);

        //    常量_变量_字段_指针字段_数组元素_函数调用_函数指针调用_调用链 express2 = express as 常量_变量_字段_指针字段_数组元素_函数调用_函数指针调用_调用链;

        //    变量声明语句 数组声明;

        //    if (express2 != null)
        //    {
        //        数组声明 = Get_数组声明(type, express2, 星号Count, chars, 第一个中括号出现位置);
        //        //list变量声明.Add(new 变量声明语句(type, 变量.name, 星号Count, null));
        //        list变量声明.Add(数组声明);
        //        return null;
        //    }

        //    赋值 赋值 = express as 赋值;

        //    if (赋值 == null)
        //        throw new InnerCException("无效的数组声明语句 。", chars, 第一个中括号出现位置);

        //    express2 = 赋值.等号左边的表达式 as 常量_变量_字段_指针字段_数组元素_函数调用_函数指针调用_调用链;

        //    if (express2 == null)
        //        throw new InnerCException("无效的数组声明语句 。", chars, 第一个中括号出现位置);

        //    数组声明 = Get_数组声明(type, express2, 星号Count, chars, 第一个中括号出现位置);

        //    list变量声明.Add(数组声明);

        //    return new 赋值语句(new 赋值(new 变量(数组声明.name), 赋值.值));

        //}

        //private static 变量声明语句 Get_数组声明(string type, 常量_变量_字段_指针字段_数组元素_函数调用_函数指针调用_调用链 express, int 星号Count, char[] chars, int 第一个中括号出现位置)
        //{
        //    if (express.list.Count < 2)
        //        throw new InnerCException("无效的数组声明语句 。", chars, 第一个中括号出现位置);

        //    变量 变量 = express.list[0] as 变量;

        //    if (变量 == null)
        //        throw new InnerCException("无效的数组声明语句 。", chars, 第一个中括号出现位置);

        //    数组元素 数组元素 = express.list[1] as 数组元素;

        //    if (数组元素 == null)
        //        throw new InnerCException("无效的数组声明语句 。", chars, 第一个中括号出现位置);

        //    List<常量> list_维度_Length = new List<常量>();

        //    for (int i = 0; i < 数组元素.listIndex.Count; i++)
        //    {
        //        常量 常量 = 数组元素.listIndex[i] as 常量;

        //        if (常量 == null)
        //             throw new InnerCException("数组声明 长度 应是 常量 。", chars, 第一个中括号出现位置);

        //        if (常量.type != "int")
        //            throw new InnerCException("数组声明 长度 应是 正整数 常量 。", chars, 第一个中括号出现位置);

        //        list_维度_Length.Add(常量);
        //    }

        //    return new 变量声明语句(type, 变量.name, 星号Count, list_维度_Length);
        //}

        public static 表达式语句 Parse_表达式语句(char[] chars, int beginIndex, int endIndex, out int 语句结束位置)
        {
            语句结束位置 = -1;

            StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                return(null);
            }

            语句结束位置 = Parser.Find_单引号对双引号对以外的内容(chars, beginIndex, endIndex, ';');

            if (语句结束位置 == -1)
            {
                throw new InnerCException("未结束的语句,缺少分号 \";\" 。", chars, span.iRight);
            }

            span = StrUtil.Trim(chars, span.iLeft, span.iRight, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                return(null);
            }

            表达式 表达式 = 表达式_Parser.Parse(chars, span.iLeft, 语句结束位置 - 1);

            return(new 表达式语句(表达式));
        }
Exemplo n.º 4
0
        public 变量声明和初始化(类型 类型, string name, 表达式 初始值, int 变量位置_iLeft)
        {
            this.类型   = 类型;
            this.name = name;
            this.初始值  = 初始值;

            this.变量位置_iLeft = 变量位置_iLeft;
        }
Exemplo n.º 5
0
        public 变量声明和初始化(类型 类型, string name, 表达式 初始值, int 变量名位置, char[] chars, int iLeft) : base(chars, iLeft)
        {
            this.类型   = 类型;
            this.name = name;
            this.初始值  = 初始值;

            this.变量名位置 = 变量名位置;
        }
Exemplo n.º 6
0
        public override void 类型和语法检查(List <语法错误> list语法错误)
        {
            for (int i = 0; i < this.小括号表达式s.Length; i++)
            {
                表达式 express = this.小括号表达式s[i];

                if (express != null)
                {
                    express.类型和语法检查(list语法错误);
                }
            }

            this.子句.类型和语法检查(list语法错误);
        }
        private static 表达式 Parse_指针字段(char[] chars, List <表达式段> list)
        {
            表达式段 段 = list[list.Count - 1];

            if (段.type != 表达式段_Type.普通段)
            {
                return(null);
            }

            string 点或箭头;

            int 点或箭头的位置 = 寻找最右边的点或箭头的位置(chars, 段.iLeft, 段.iRight, out 点或箭头);

            if (点或箭头的位置 == -1)
            {
                return(null);
            }

            if (点或箭头 != "->")
            {
                return(null);
            }

            StrSpan 右边的部分 = StrUtil.Trim(chars, 点或箭头的位置 + 2, 段.iRight, Parser._whiteSpaces);

            if (右边的部分.isEmpty)
            {
                throw new 语法错误_Exception("\".\" 后面缺少 字段名 。", chars, 点或箭头的位置);
            }

            StrSpan 左边的部分 = StrUtil.Trim(chars, 段.iLeft, 点或箭头的位置 - 1, Parser._whiteSpaces);

            if (左边的部分.isEmpty)
            {
                throw new 语法错误_Exception("\".\" 前面缺少 变量 或者 表达式 。", chars, 点或箭头的位置);
            }

            表达式 express = Parse(chars, 左边的部分.iLeft, 左边的部分.iRight);

            //if (!(express is 变量 || express is 指针取值))
            //    throw new InnerCException("\".\" 前面应该是 变量 或者 指针取值 表达式 。", chars, 左边的部分.iRight);

            if (!Util.Check_是否_下划线字母数字_且以_下划线字母_开头(chars, 右边的部分.iLeft, 右边的部分.iRight))
            {
                throw new 语法错误_Exception("无效的字段名 。", chars, 右边的部分.iLeft);
            }

            return(new 指针字段(express, new string(chars, 右边的部分.iLeft, 右边的部分.iRight - 右边的部分.iLeft + 1), chars, 点或箭头的位置));
        }
Exemplo n.º 8
0
        private static 变量声明和初始化 Parse_数组变量声明(char[] chars, 表达式 表达式, int p, int l, int 星号Count)
        {
            变量 变量;

            //List<常量> list_数组维度_Length;

            数组元素 数组元素 = 表达式 as 数组元素;


            if (数组元素 != null)
            {
                变量 = 数组元素.左边的表达式 as 变量;

                if (变量 != null)
                {
                    //list_数组维度_Length = Get_list_数组维度_Length(数组元素, chars);

                    return(new 变量声明和初始化(new 类型(new string(chars, p, l), 星号Count, 数组元素.list下标), 变量.name, null, 变量.参考位置_iLeft));
                }
            }

            赋值 赋值 = 表达式 as 赋值;

            if (赋值 != null)
            {
                数组元素 = 赋值.左边的表达式 as 数组元素;

                if (数组元素 != null)
                {
                    变量 = 数组元素.左边的表达式 as 变量;

                    if (变量 != null)
                    {
                        //list_数组维度_Length = Get_list_数组维度_Length(数组元素, chars);

                        //常量 常量 = 赋值.右边的表达式 as 常量;

                        //if (常量 == null)
                        //    throw new InnerCException("只能用常量对数组初始化 。", chars, p);

                        return(new 变量声明和初始化(new 类型(new string(chars, p, l), 星号Count, 数组元素.list下标), 变量.name, 赋值.右边的表达式, 变量.参考位置_iLeft));
                    }
                }
            }

            return(null);
        }
Exemplo n.º 9
0
        private static 表达式[] Parse_小括号(char[] chars, int 左小括号位置, int 右小括号位置)
        {
            //作用域 形参列表 = new 作用域();

            表达式[] 小括号表达式s = new 表达式[3];

            StrSpan span = StrUtil.Trim(chars, 左小括号位置 + 1, 右小括号位置 - 1, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                throw new 语法错误_Exception("for() 小括号内应是两个分号 。", chars, 左小括号位置);
            }
            //return exppressArr;

            List <StrSpan> list = Parser.在_单引号双引号_以外_Split(chars, span.iLeft, span.iRight, ';');

            if (list.Count != 3)
            {
                throw new 语法错误_Exception("for() 小括号内应是两个分号 。", chars, 左小括号位置);
            }

            StrSpan spanExpress;

            for (int i = 0; i < list.Count; i++)
            {
                spanExpress = list[i];

                变量声明和初始化 变量声明 = 语句_Parser.Parse_变量声明(chars, spanExpress.iLeft, spanExpress.iRight);

                if (变量声明 != null)
                {
                    小括号表达式s[i] = 变量声明;
                    continue;
                }

                表达式 表达式 = 表达式_Parser.Parse(chars, spanExpress.iLeft, spanExpress.iRight);

                小括号表达式s[i] = 表达式;
            }

            return(小括号表达式s);
        }
        private static 表达式 Parse_函数调用(char[] chars, List <表达式段> list)
        {
            if (list.Count < 2)
            {
                return(null);
            }

            表达式段 段 = list[list.Count - 1];

            if (段.type != 表达式段_Type.小括号段)
            {
                return(null);
            }

            表达式 左边的表达式 = Parse(chars, list[0].iLeft, 段.iLeft - 1);

            变量 函数名 = 左边的表达式 as 变量;

            if (函数名 != null)
            {
                List <表达式> list实参 = Parse_实参(chars, 段);

                return(new 函数调用(函数名.name, list实参, chars, 段.iLeft));
            }

            指针取值 指针取值 = 左边的表达式 as 指针取值;

            if (指针取值 != null)
            {
                List <表达式> list实参 = Parse_实参(chars, 段);

                return(new 函数指针调用(指针取值, list实参, chars, 段.iLeft));
            }

            throw new 语法错误_Exception("函数调用 左边应该是 函数名 或者 指针取值 表达式 如 (* p) 。", chars, 段.iLeft);
            //if (指针取值 == null)
            //    return null;


            //return new 函数调用(左边的表达式, list实参);
        }
Exemplo n.º 11
0
        private static 变量声明和初始化 Parse_普通变量声明(char[] chars, 表达式 表达式, int p, int l, int 星号Count)
        {
            变量 变量 = 表达式 as 变量;

            if (变量 != null)
            {
                return(new 变量声明和初始化(new 类型(new string(chars, p, l), 星号Count, null), 变量.name, null, 变量.参考位置_iLeft));
            }

            赋值 赋值 = 表达式 as 赋值;

            if (赋值 != null)
            {
                变量 = 赋值.左边的表达式 as 变量;

                if (变量 != null)
                {
                    return(new 变量声明和初始化(new 类型(new string(chars, p, l), 星号Count, null), 变量.name, 赋值.右边的表达式, 变量.参考位置_iLeft));
                }
            }

            return(null);
        }
Exemplo n.º 12
0
 protected 二元表达式(表达式 左边的表达式, 表达式 右边的表达式, char[] chars, int iLeft) : base(chars, iLeft)
 {
     this.左边的表达式 = 左边的表达式;
     this.右边的表达式 = 右边的表达式;
 }
Exemplo n.º 13
0
 public 指针取值(表达式 指针表达式)
 {
     this.指针表达式 = 指针表达式;
 }
 public 指针字段(表达式 左边的表达式, string 字段名, char[] chars, int iLeft) : base(chars, iLeft)
 {
     this.左边的表达式 = 左边的表达式;
     this.字段名    = 字段名;
 }
 public 数组元素(表达式 左边的表达式, List <表达式> list下标, char[] chars, int iLeft) : base(chars, iLeft)
 {
     this.左边的表达式 = 左边的表达式;
     this.list下标 = list下标;
 }
Exemplo n.º 16
0
 public 形参(类型 类型, string name, 表达式 初始值, int 变量名位置, char[] chars, int iLeft)
     : base(类型, name, 初始值, 变量名位置, chars, iLeft)
 {
 }
Exemplo n.º 17
0
        public static while_语句 Parse(char[] chars, int beginIndex, int endIndex, out int 语句结束位置)
        {
            语句结束位置 = -1;

            StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                return(null);
            }

            if (!Parser.开头一段_Equals(chars, span.iLeft, span.iRight, "while"))
            {
                return(null);
            }

            int 左小括号位置 = StrUtil.FindForwardUntilNot(chars, span.iLeft + 5, span.iRight, Parser._whiteSpaces);

            if (左小括号位置 == -1)
            {
                throw new 语法错误_Exception("未结束的 while 语句 。", chars, span.iLeft + 1);
            }

            char c = chars[左小括号位置];

            if (c != '(')
            {
                throw new 语法错误_Exception("while 语句 缺少条件判断 左小括号 。", chars, 左小括号位置);
            }

            int 右小括号位置 = Parser.Find_小括号_右(chars, 左小括号位置 + 1, span.iRight);

            if (右小括号位置 == -1)
            {
                throw new 语法错误_Exception("while 语句 缺少条件判断 右小括号 。", chars, 左小括号位置 + 1);
            }


            StrSpan span判断 = StrUtil.Trim(chars, 左小括号位置 + 1, 右小括号位置 - 1, Parser._whiteSpaces);

            if (span判断.isEmpty)
            {
                throw new 语法错误_Exception("while 语句 缺少判断表达式 。", chars, 左小括号位置);
            }

            表达式 while_条件 = 表达式_Parser.Parse(chars, 左小括号位置 + 1, 右小括号位置 - 1);


            StrSpan span子句 = StrUtil.Trim(chars, 右小括号位置 + 1, span.iRight, Parser._whiteSpaces);

            if (span子句.isEmpty)
            {
                throw new 语法错误_Exception("while 语句 缺少子句 。", chars, 右小括号位置 + 1);
            }

            块作用域 子句 = Parse_子句(chars, span子句.iLeft, span子句.iRight, out 语句结束位置);

            //j = span子句.iRight;

            return(new while_语句(while_条件, 子句));
        }
Exemplo n.º 18
0
 protected 一元表达式(表达式 子表达式, char[] chars, int iLeft) : base(chars, iLeft)
 {
     this.子表达式 = 子表达式;
 }
Exemplo n.º 19
0
        private static if_分句 Parse_if_分句(char[] chars, int beginIndex, int endIndex, out int j)
        {
            j = -1;

            StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                return(null);
            }

            bool b = Parser.开头一段_Equals(chars, span.iLeft, span.iRight, "if");

            if (!b)
            {
                return(null);
            }

            int 左小括号位置 = StrUtil.FindForwardUntilNot(chars, span.iLeft + 2, span.iRight, Parser._whiteSpaces);

            if (左小括号位置 == -1)
            {
                throw new InnerCException("未结束的 if 语句 。", chars, span.iLeft + 1);
            }

            char c = chars[左小括号位置];

            if (c != '(')
            {
                throw new InnerCException("if 语句 缺少条件判断 左小括号 。", chars, 左小括号位置);
            }

            int 右小括号位置 = Parser.Find_小括号_右(chars, 左小括号位置 + 1, span.iRight);

            if (右小括号位置 == -1)
            {
                throw new InnerCException("if 语句 缺少条件判断 右小括号 。", chars, 左小括号位置 + 1);
            }


            StrSpan span判断 = StrUtil.Trim(chars, 左小括号位置 + 1, 右小括号位置 - 1, Parser._whiteSpaces);

            if (span判断.isEmpty)
            {
                throw new InnerCException("if 语句 缺少判断表达式 。", chars, 左小括号位置);
            }

            表达式 if_判断 = 表达式_Parser.Parse(chars, 左小括号位置 + 1, 右小括号位置 - 1);


            StrSpan span子句 = StrUtil.Trim(chars, 右小括号位置 + 1, span.iRight, Parser._whiteSpaces);

            if (span子句.isEmpty)
            {
                throw new InnerCException("if 语句 缺少子句 。", chars, 右小括号位置 + 1);
            }

            块作用域 子句 = Parse_子句(chars, span子句.iLeft, span子句.iRight, out j);

            //j = span子句.iRight;

            return(new if_分句(if_判断, 子句));
        }
        private static 表达式 Parse_数组元素(char[] chars, List <表达式段> list)
        {
            表达式段 段;

            List <表达式段> list右边连续的中括号段 = new List <表达式段>();

            int p = -1;

            for (int i = list.Count - 1; i >= 0; i--)
            {
                段 = list[i];

                if (段.type != 表达式段_Type.中括号段)
                {
                    break;
                }

                p = i;
                //list右边连续的中括号段.Add(段);
            }

            if (p != -1)
            {
                for (int i = p; i < list.Count; i++)
                {
                    段 = list[i];

                    list右边连续的中括号段.Add(段);
                }
            }

            if (list右边连续的中括号段.Count == 0)
            {
                return(null);
            }

            表达式 express;

            List <表达式> list下标 = new List <表达式>();

            for (int i = 0; i < list右边连续的中括号段.Count; i++)
            {
                段 = list右边连续的中括号段[i];

                StrSpan span下标 = StrUtil.Trim(chars, 段.iLeft + 1, 段.iRight - 1, Parser._whiteSpaces);

                if (span下标.isEmpty)
                {
                    list下标.Add(null);
                    continue;
                }

                express = 表达式_Parser.Parse(chars, span下标.iLeft, span下标.iRight);

                //express.参考位置_iLeft = 段.iLeft;

                list下标.Add(express);
            }

            StrSpan 左边的部分 = StrUtil.Trim(chars, list[0].iLeft, list右边连续的中括号段[0].iLeft - 1, Parser._whiteSpaces);

            if (左边的部分.isEmpty)
            {
                throw new 语法错误_Exception("\"[ ]\" 前面缺少 数组变量 或者 可以返回一个数组指针的表达式 。", chars, list[0].iLeft);
            }

            表达式 左边的表达式 = Parse(chars, 左边的部分.iLeft, 左边的部分.iRight);

            return(new 数组元素(左边的表达式, list下标, chars, 左边的部分.iLeft));
        }
Exemplo n.º 21
0
 public 指针字段(表达式 左边的表达式, string 字段名)
 {
     this.左边的表达式 = 左边的表达式;
     this.字段名    = 字段名;
 }
Exemplo n.º 22
0
 public 数组元素(表达式 左边的表达式, List <表达式> list下标)
 {
     this.左边的表达式 = 左边的表达式;
     this.list下标 = list下标;
 }
        public static 表达式 Parse(char[] chars, int beginIndex, int endIndex)
        {
            StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                throw new 语法错误_Exception("无效的表达式 。 缺少内容 。", chars, beginIndex);
            }


            List <表达式段> list = Parser._小括号中括号单引号双引号_分段(chars, span.iLeft, span.iRight);

            list = Parser.去掉空白段(chars, list);


            表达式 express = Parse_变量(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_常量(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_小括号表达式(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_字段(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_指针字段(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_数组元素(chars, list);

            if (express != null)
            {
                return(express);
            }

            express = Parse_函数调用(chars, list);

            if (express != null)
            {
                return(express);
            }

            //express = Parse_函数指针调用(chars, list);

            //if (express != null)
            //    return express;

            throw new 语法错误_Exception("无效的表达式 。", chars, span.iLeft);
        }
Exemplo n.º 24
0
 public 非(表达式 右边的表达式)
 {
     this.右边的表达式 = 右边的表达式;
 }
Exemplo n.º 25
0
 public 取地址(表达式 变量)
 {
     this.变量 = 变量;
 }
Exemplo n.º 26
0
        //private 表达式 右边的表达式;

        //public 非(表达式 右边的表达式, char[] chars, int iLeft) : base(chars, iLeft)
        //{
        //    this.右边的表达式 = 右边的表达式;
        //}

        public 非(表达式 子表达式, char[] chars, int iLeft) : base(子表达式, chars, iLeft)
        {
        }
Exemplo n.º 27
0
        public static 表达式 Parse(char[] chars, int beginIndex, int endIndex)
        {
            StrSpan span = StrUtil.Trim(chars, beginIndex, endIndex, Parser._whiteSpaces);

            if (span.isEmpty)
            {
                throw new InnerCException("无效的表达式 。 缺少内容 。", chars, beginIndex);
            }


            //List<表达式段> list = 按_小括号中括号双引号单引号_分段(chars, span.iLeft, span.iRight);

            运算符 op = Get_优先级最小的左右结合运算符和右结合运算符(chars, span.iLeft, span.iRight);

            if (op == null)
            {
                return(常量_变量_字段_指针字段_数组元素_函数调用_函数指针调用_调用链_Parser.Parse(chars, span.iLeft, span.iRight));
            }

            表达式 op_左边的表达式 = null;
            表达式 op_右边的表达式;

            if (op.op == "!" || op.type == 运算符_Type.Cast || op.type == 运算符_Type.指针取值 || op.type == 运算符_Type.取地址)
            {
                StrSpan 左边的内容 = StrUtil.Trim(chars, span.iLeft, op.iLeft - 1, Parser._whiteSpaces);

                if (!左边的内容.isEmpty)
                {
                    throw new InnerCException("无效的内容,缺少运算符 。", chars, 左边的内容.iRight);
                }

                op_右边的表达式 = Parse(chars, op.iRight + 1, endIndex);
            }
            else
            {
                op_左边的表达式 = Parse(chars, span.iLeft, op.iLeft - 1);
                op_右边的表达式 = Parse(chars, op.iRight + 1, endIndex);
            }


            if (op.type == 运算符_Type.Cast)
            {
                return(new Cast(op.castType, op_右边的表达式));
            }
            if (op.type == 运算符_Type.指针取值)
            {
                return(new 指针取值(op_右边的表达式));
            }
            if (op.type == 运算符_Type.取地址)
            {
                return(new 取地址(op_右边的表达式));
            }

            if (op.op == "+")
            {
                return(new 加(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "-")
            {
                return(new 减(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "*")
            {
                return(new 乘(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "/")
            {
                return(new 除(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "==")
            {
                return(new 等于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == ">")
            {
                return(new 大于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "<")
            {
                return(new 小于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == ">=")
            {
                return(new 大于等于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "<=")
            {
                return(new 小于等于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "!=")
            {
                return(new  等于(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "&&")
            {
                return(new 与(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "||")
            {
                return(new 或(op_左边的表达式, op_右边的表达式));
            }
            else if (op.op == "!")
            {
                return(new 非(op_右边的表达式));
            }
            else if (op.op == "=")
            {
                return(new 赋值(op_左边的表达式, op_右边的表达式));
            }

            throw new InnerCException("无效的运算符 \"" + op.op + "\" 。", chars, op.iLeft);
        }
Exemplo n.º 28
0
 public 等于(表达式 左边的表达式, 表达式 右边的表达式)
 {
     this.左边的表达式 = 左边的表达式;
     this.右边的表达式 = 右边的表达式;
 }
Exemplo n.º 29
0
        //private 表达式 左边的表达式;
        //private 表达式 右边的表达式;

        //public 大于等于(表达式 左边的表达式, 表达式 右边的表达式, char[] chars, int iLeft) : base(chars, iLeft)
        //{
        //    this.左边的表达式 = 左边的表达式;
        //    this.右边的表达式 = 右边的表达式;
        //}

        public 大于等于(表达式 左边的表达式, 表达式 右边的表达式, char[] chars, int iLeft) : base(左边的表达式, 右边的表达式, chars, iLeft)
        {
        }
Exemplo n.º 30
0
 public if_分句(表达式 if_判断, 块作用域 子句)
 {
     this.if_判断 = if_判断;
     this.子句    = 子句;
 }