예제 #1
0
        protected void addToken(int lineNo, Match matcher)
        {
            string m = matcher.Groups[1].ToString();

            if (m != "")
            {
                if (matcher.Groups[2].ToString() == "")
                {
                    Token token;
                    if (matcher.Groups[3].ToString() != "")
                    {
                        token = new NumToken(lineNo, int.Parse(m));
                    }
                    else if (matcher.Groups[4].ToString() != "")
                    {
                        token = new StrToken(lineNo, toStringLiteral(m));
                    }
                    else
                    {
                        token = new IdToken(lineNo, m);
                    }
                    queue.Add(token);
                }
            }
        }
예제 #2
0
파일: Lexer.cs 프로젝트: GY101/Stone.cs
        private void AddToken(int lineNo, Match match)
        {
            var group1 = match.Groups[1];
            var value  = group1.Value;

            if (group1.Success) // if not a space
            {
                if (!match.Groups[2].Success)
                { // if not a comment
                    Token token;
                    if (match.Groups[3].Success)
                    {
                        token = new NumToken(lineNo, int.Parse(value));
                    }
                    else if (match.Groups[4].Success)
                    {
                        token = new StrToken(lineNo, ToStringLiteral(value));
                    }
                    else
                    {
                        token = new IdToken(lineNo, value);
                    }
                    queue.Add(token);
                }
            }
        }
예제 #3
0
        protected void AddToken(int lineNo, Match matcher)
        {
            string id       = matcher.Groups["id"].Value;
            string comments = matcher.Groups["comments"].Value;
            string integer  = matcher.Groups["integer"].Value;
            string str      = matcher.Groups["string"].Value;

            if (id != "")
            {
                if (comments == "")
                {
                    Token token;
                    if (integer != "")
                    {
                        token = new IntegerToken(lineNo, int.Parse(integer));
                    }
                    else if (str != "")
                    {
                        token = new StrToken(lineNo, ToStringLiteral(str));
                    }
                    else
                    {
                        token = new IdToken(lineNo, id);
                    }
                    queue.Enqueue(token);
                }
            }
        }
예제 #4
0
    public static string NormalizeHostNameForSort(string str)
    {
        str = str.Trim();

        if (Domain.IsIPAddress(str) == false)
        {
            StrToken      t    = new StrToken(str, ".");
            List <string> o    = new List <string>();
            string[]      strs = t.Tokens;
            Array.Reverse(strs);

            int    i;
            string ret = "";
            for (i = 0; i < strs.Length; i++)
            {
                ret += strs[i];

                if (i != (strs.Length - 1))
                {
                    ret += ".";
                }
            }

            return(ret);
        }
        else
        {
            return(str);
        }
    }
예제 #5
0
    public Target(string str)
    {
        StrToken t = new StrToken(str);

        if (t.NumTokens >= 1)
        {
            HostName = t[0];

            int numPorts = (int)t.NumTokens - 1;
            int i;

            List <int> ports = new List <int>();

            for (i = 0; i < numPorts; i++)
            {
                string s         = t[(uint)i + 1];
                bool   tcp_check = false;

                if (s.StartsWith("@"))
                {
                    tcp_check = true;
                    s         = s.Substring(1);
                }

                int port = Str.StrToInt(s);

                if (port != 0 && tcp_check)
                {
                    port += 100000;
                }

                ports.Add(port);
            }

            ports.Sort();

            Ports = ports.ToArray();
        }
        else
        {
            throw new FormatException();
        }
    }
예제 #6
0
        private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            this.listView1.Items.Clear();
            StrLanguage l     = (StrLanguage)e.Node.Tag;
            StrItemList items = wrapper.LanguageItems(l);

            if (items == null)
            {
                return;
            }

            for (int i = 0; i < items.Length; i++)
            {
                StrToken s  = items[i];
                string[] ss = new string[3];
                ss[0] = i.ToString();
                ss[1] = s.Title;
                ss[2] = s.Description;
                ListViewItem v = new ListViewItem(ss);
                this.listView1.Items.Add(v);
            }
            currentLang = l;
        }
예제 #7
0
        /// <summary>
        /// 往队列中添加一个Token
        /// </summary>
        /// <param name="lineNumber">Token所在行号</param>
        /// <param name="item">Token源字符串</param>
        private void AddToken(int lineNumber, Match item)
        {
            Token  token    = null;
            string strValue = item.Value.Trim();
            var    groups   = item.Groups;

            if (groups["com"].Success)
            {
                // 注释,忽略掉
            }
            else if (groups["id"].Success)
            {
                // 标识符
                token = new IdToken(lineNumber, strValue);
            }
            else if (groups["num"].Success)
            {
                // 整形字面量
                bool succ = false;
                if (strValue.StartsWith("(-"))
                {
                    // 负数
                    string fixedStrValue = strValue.Substring(2, strValue.Length - 3);
                    if (int.TryParse(fixedStrValue, out int val))
                    {
                        token = new NumToken(lineNumber, -val);
                        succ  = true;
                    }
                }
                else if (int.TryParse(strValue, out int val))
                {
                    token = new NumToken(lineNumber, val);
                    succ  = true;
                }
                if (!succ)
                {
                    // 解析未成功
                    throw new ParseException("解析整形字面量失败");
                }
            }
            else if (groups["str"].Success)
            {
                // 字符串字面量
                token = new StrToken(lineNumber, strValue.Substring(1, strValue.Length - 2));
            }
            else if (groups["pun"].Success)
            {
                // 运算符
                token = new PunToken(lineNumber, strValue);
            }
            else if (groups["key"].Success)
            {
                // 关键字
                token = new KeyToken(lineNumber, strValue);
            }
            else if (groups["sep"].Success)
            {
                // 分号和括号
                token = new SepToken(lineNumber, strValue);
            }
            else if (groups["other"].Success)
            {
                // 不能识别的字符
                throw new ParseException(new StrToken(lineNumber, strValue), "非法字符");
            }
            if (token != null)
            {
                m_tokenQueue.Add(token);
                //Utils.LogInfo("添加了Token: " + token.GetText());
            }
        }