示例#1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            FirstName  = new Dictionary <string, int>();
            SecondName = new Dictionary <string, int>();
            StringBuilder result = new StringBuilder();
            var           file   = ConfigHelper.Path + "name.txt";

            var xCount = ChineseHelper.GetStrokeCount(this.txtFirstName.Text);

            if (xCount == 0)
            {
                ChineseChar chineseChar =
                    new ChineseChar(this.txtFirstName.Text.ToCharArray()[0]);
                xCount = chineseChar.StrokeNumber;
            }
            if (!FileHelper.IsExistFile(file))
            {
                MessageBox.Show("对不起,名字字典不存在,请确保安装目录下存在name.txt文件");
            }
            else
            {
                var names = File.ReadAllLines(file, Encoding.UTF8);
                foreach (var item in names)
                {
                    for (int i = 0; i < item.Length; i++)
                    {
                        var c = item.ToCharArray();
                        if (!string.IsNullOrEmpty(c[i].ToString()) && !string.IsNullOrEmpty(c[i].ToString().Trim()))
                        {
                            var         cc          = c[i].ToString();
                            ChineseChar chineseChar =
                                new ChineseChar(c[i]);
                            var count = chineseChar.StrokeNumber;
                            if (!FirstName.ContainsKey(c[i].ToString()))
                            {
                                FirstName.Add(c[i].ToString(), count);
                                SecondName.Add(c[i].ToString(), count);
                            }
                        }
                    }
                }
                foreach (var fir in FirstName)
                {
                    foreach (var sec in SecondName.Where(x => x.Key != fir.Key).ToList())
                    {
                        var textCount    = fir.Value + sec.Value + xCount;
                        var sourceCounts = txtNameCount.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var sourCount in sourceCounts)
                        {
                            if (object.Equals(textCount, int.Parse(sourCount)))
                            {
                                result.Append(this.txtFirstName.Text + fir.Key + sec.Key + ",");
                            }
                        }
                    }
                }
                this.rtbResult.Text = StringHelper.DelLastComma(result.ToString());
            }
        }
示例#2
0
 static bool is_identifier_part_character(char c)
 {
     return((c >= 'a' && c <= 'z') ||
            (c >= 'A' && c <= 'Z') ||
            (c >= '0' && c <= '9') ||
            ChineseHelper.IsChineseLetter(c)
            );
 }
示例#3
0
 public static string GetAreaEnglish(string area)
 {
     foreach (var a in areas)
     {
         if (a.Area.Contains(area))
         {
             return(a.EN_US);
         }
     }
     return(ChineseHelper.GetPinyin(area));
 }
示例#4
0
 public static string GetCityEnglish(string city)
 {
     foreach (var c in cities)
     {
         if (c.City.Contains(city))
         {
             return(c.EN_US);
         }
     }
     return(ChineseHelper.GetPinyin(city));
 }
示例#5
0
 public static string GetProvinceEnglish(string province)
 {
     foreach (var prov in provinces)
     {
         if (prov.Province.Contains(province))
         {
             return(prov.EN_US);
         }
     }
     return(ChineseHelper.GetPinyin(province));
 }
示例#6
0
        private void myCurrencyTextBox1_TextChanged(object sender, EventArgs e)
        {
            decimal?d = Feng.Utils.ConvertHelper.ToDecimal(myCurrencyTextBox1.Text);

            if (d.HasValue)
            {
                大写金额.SelectedDataValue = ChineseHelper.ConvertToChinese(d.Value);
            }
            else
            {
                大写金额.SelectedDataValue = null;
            }
        }
示例#7
0
        public List <Token> Scan(string code)
        {
            i         = 0;
            line      = 1;
            col       = 1;
            this.code = code;
            tokenList = new List <Token>();

            while (ch != END)
            {
                char nextChar = GetNext();
                //show(ch + " " + nextChar);
                if (ch == ' ' || ch == '\t')
                {
                    SkipWhiteSpace();
                }
                else if (ch == '/' && nextChar == '/')
                {
                    SkipSingleLineComment();
                }
                else if (ch == '/' && nextChar == '*')
                {
                    SkipMutilLineComment();
                }
                else if (ch == '/')
                {
                    Token tok = new Token("/", TokenKind.DIV, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.DIV };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '"' || ch == '“' || ch == '”')
                {
                    var    tempCol = col;
                    string str     = scanString();
                    Token  tok     = new Token(str, TokenKind.LiteralString, line, tempCol, i);// { Col = col - 1, Line = line, Index = i, Text = str, Kind = TokenKind.LiteralString };
                    tokenList.Add(tok);
                }
                else if (ch == '\r' && nextChar == '\n')
                {
                    Next(); Next();
                    col = 1;
                    line++;
                }
                else if (ch == '\n')
                {
                    SkipLine();
                }
                else if (ch == '\r')
                {
                    SkipLine();
                }
                else if ("0123456789".IndexOf(ch) != -1)
                {
                    string str     = scanNumber();
                    var    tempCol = col;
                    if (TextUtil.IsInt(str))
                    {
                        Token tok = new Token(str, TokenKind.LiteralInt, line, tempCol, i);// { Col = temp, Line = line, Index = i, Text = str, Kind = TokenKind.LiteralInt };
                        tokenList.Add(tok);
                    }
                    else if (TextUtil.IsFloat(str))
                    {
                        Token tok = new Token(str, TokenKind.LiteralFloat, line, tempCol, i);// { Col = temp, Line = line, Index = i, Text = str, Kind = TokenKind.LiteralFloat };
                        tokenList.Add(tok);
                    }
                    else
                    {
                        //lexError(str + "不是正确的数字");
                    }
                }
                else if (ch == '+' || ch == '+')
                {
                    Token tok = new Token("+", TokenKind.ADD, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.ADD };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '-' || ch == '-')
                {
                    Token tok = new Token("-", TokenKind.SUB, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.SUB };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch == '=' || ch == '=') && (nextChar == '=' || nextChar == '='))
                {
                    Token tok = new Token("==", TokenKind.EQ, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.EQ };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '=' || ch == '=') && (nextChar == '>'))
                {
                    Token tok = new Token("==", TokenKind.EQ, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.AssignTo };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '=' || ch == '='))
                {
                    Token tok = new Token("=", TokenKind.Assign, line, col, i);// { Col = col, Line = line, Index = i, Kind = TokenKind.Assign };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch == '*'))
                {
                    Token tok = new Token("*", TokenKind.MUL, line, col, i);// { Col = col, Line = line, Kind = TokenKind.MUL };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ',' || ch == ',')
                {
                    Token tok = new Token(",", TokenKind.Comma, line, col, i);// { Col = col, Line = line, Kind = TokenKind.Comma };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ';' || ch == ';')
                {
                    Token tok = new Token(";", TokenKind.Semi, line, col, i);// { Col = col, Line = line, Kind = TokenKind.Semi };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '(' || ch == '(')
                {
                    Token tok = new Token("(", TokenKind.LBS, line, col, i);// { Col = col, Line = line, Kind = TokenKind.LBS };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ')' || ch == ')')
                {
                    Token tok = new Token(")", TokenKind.RBS, line, col, i);// { Col = col, Line = line, Kind = TokenKind.RBS };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '>' && GetNext() == '=')
                {
                    Token tok = new Token(">=", TokenKind.GE, line, col, i);// { Col = col, Line = line, Kind = TokenKind.GE };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if (ch == '>')
                {
                    Token tok = new Token(">", TokenKind.GT, line, col, i);// { Col = col, Line = line, Kind = TokenKind.GT };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '<' && nextChar == '=')
                {
                    Token tok = new Token("<=", TokenKind.LE, line, col, i);// { Col = col, Line = line, Kind = TokenKind.LE };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if (ch == '<')
                {
                    Token tok = new Token("<", TokenKind.LT, line, col, i);// { Col = col, Line = line, Kind = TokenKind.LT };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((nextChar == '!' || nextChar == '!') && (nextChar == '=' || nextChar == '='))
                {
                    Token tok = new Token("!=", TokenKind.NE, line, col, i);// { Col = col, Line = line, Kind = TokenKind.NE };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if (ch == ':' || ch == ':')
                {
                    Token tok = new Token(":", TokenKind.Colon, line, col, i);// { Col = col, Line = line, Kind = TokenKind.Colon };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch >= 'A' && ch <= 'Z') /*|| (ch == '_') */ || (ch >= 'a' && ch <= 'z') || ChineseHelper.IsChineseLetter(ch))
                {
                    var   tempCol  = col;
                    var   tempLine = line;
                    Token t1       = scanKeyIdent();
                    tokenList.Add(t1);
                }
                else if (char.IsControl(ch))
                {
                    while (char.IsControl(ch) && ch != END)
                    {
                        Next();
                        if ((int)ch == 13)
                        {
                            line++;
                            col = 1;
                        }
                    }
                }
                else
                {
                    //lexError("无法识别" + (int)ch + ": '" + ch + "' ");
                    Next();
                }
            }
            return(tokenList);
        }
示例#8
0
        public List <Token> Scan()
        {
            //report("开始");
            tokenList.Clear();
            while (ch != END)
            {
                //report("ch="+ch+" "+(int)ch);
                char nextChar = GetNext();
                if (ch == ' ' || ch == '\t')
                {
                    //report("SkipSpace");
                    SkipWhiteSpace();
                }
                else if (ch == '/' && nextChar == '/')
                {
                    SkipSingleLineComment();
                }
                else if (ch == '/' && nextChar == '*')
                {
                    SkipMutilLineComment();
                }
                else if (ch == '/')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.DIV
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '"' || ch == '“' || ch == '”')
                {
                    string str = scanString();
                    Token  tok = new Token()
                    {
                        Col = col - 1, Line = line, Text = str, Kind = TokenKind.LiteralString
                    };
                    tokenList.Add(tok);
                }
                else if (ch == '\r' && nextChar == '\n')
                {
                    //report("扫描换行符");
                    Next(); Next();
                    col = 1;
                    line++;
                }
                else if (ch == '\n')
                {
                    //report("扫描换行符");
                    SkipLine();
                }
                else if (ch == '\r')
                {
                    //report("扫描换行符");
                    SkipLine();
                }
                else if ("0123456789".IndexOf(ch) != -1)
                {
                    string str  = scanNumber();
                    var    temp = col;
                    if (TextUtil.IsInt(str))
                    {
                        Token tok = new Token()
                        {
                            Col = temp, Line = line, Text = str, Kind = TokenKind.LiteralInt
                        };
                        tokenList.Add(tok);
                    }
                    else if (TextUtil.IsFloat(str))
                    {
                        Token tok = new Token()
                        {
                            Col = temp, Line = line, Text = str, Kind = TokenKind.LiteralFloat
                        };
                        tokenList.Add(tok);
                    }
                    else
                    {
                        lexError(str + "不是正确的数字");
                    }
                }
                else if (ch == '+' || ch == '+')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.ADD
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '-' || ch == '-')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.SUB
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch == '=' || ch == '=') && (nextChar == '=' || nextChar == '='))
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.EQ
                    };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '=' || ch == '=') && (nextChar == '>'))
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.AssignTo
                    };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '=' || ch == '='))
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.Assign
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch == '*'))
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.MUL
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ',' || ch == ',')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.Comma
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ';' || ch == ';')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.Semi
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '(' || ch == '(')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.LBS
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == ')' || ch == ')')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.RBS
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '>' && GetNext() == '=')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.GE
                    };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if (ch == '>')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.GT
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if (ch == '<' && nextChar == '=')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.LE
                    };
                    tokenList.Add(tok);
                    Next(); Next();
                }
                else if (ch == '<')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.LT
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((nextChar == '!' || nextChar == '!') && (nextChar == '=' || nextChar == '='))
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.NE
                    };
                    tokenList.Add(tok);
                    Next(); Next();
                }

                /*else if (ch == ':' && nextChar == ':')
                 * {
                 *  Token tok = new Token() { Col = col, Line = line, Kind = TokenKind.Colond };
                 *  tokenList.Add(tok);
                 *  Next(); Next();
                 * }*/
                else if (ch == ':' || ch == ':')
                {
                    Token tok = new Token()
                    {
                        Col = col, Line = line, Kind = TokenKind.Colon
                    };
                    tokenList.Add(tok);
                    Next();
                }
                else if ((ch >= 'A' && ch <= 'Z') /*|| (ch == '_') */ || (ch >= 'a' && ch <= 'z') || ChineseHelper.IsChineseLetter(ch))
                {
                    var   tempCol  = col;
                    var   tempLine = line;
                    Token t1       = scanKeyIdent();
                    //if (t1.GetText().StartsWith("否则如果") || t1.GetText().StartsWith("否则") || t1.GetText().StartsWith("如果"))
                    //{
                    //    Console.WriteLine("否则如果");
                    //}
                    //tokenList.Add(t1);
                    if (t1.GetText() == "说明")
                    {
//                      char nchar = GetNext();
                        if (ch == ':' || ch == ':')
                        {
                            SkipSingleLineComment();
                            continue;;
                        }
                    }
                    addIdentOrKey(t1);
                }
                else if (char.IsControl(ch))
                {
                    while (char.IsControl(ch) && ch != END)
                    {
                        Next();
                        if ((int)ch == 13)
                        {
                            line++;
                            col = 1;
                        }
                    }
                }
                else
                {
                    lexError("无法识别" + (int)ch + ": '" + ch + "' ");
                    Next();
                }
            }
            return(tokenList);
        }
示例#9
0
        public List <LineTokenCollection> Scan(SourceReader sr, ContextFile fileContext, int startLine)
        {
            Reset(sr, fileContext);
            line    = startLine;
            curToks = new LineTokenCollection();
            //report("开始");
            //InitLineFirst();

            while (ch != END)
            {
                //report("ch="+ch+" "+(int)ch);
                //if (line == 33  )// ch == '控' && line == 18)
                //{
                //    //report("col:" + col);
                //    Widther.IsDebug = true;
                //}
                //else if (  line == 34)// ch == '控' && line == 18)
                //{
                //    Widther.IsDebug = true;
                //}
                //else
                //{
                //    Widther.IsDebug = false;
                //}

                char nextChar = GetNext();
                if (ch == ' ' || ch == '\t')
                {
                    //report("SkipSpace");
                    SkipWhiteSpace();
                }
                else if (ch == '/' && nextChar == '/')
                {
                    SkipSingleLineComment();
                }
                else if (ch == '/' && nextChar == '*')
                {
                    SkipMutilLineComment();
                }
                else if (ch == '/')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.DIV);// { Col = col, Line = line, };
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == '"' || ch == '“' || ch == '”')
                {
                    string          str = scanString();
                    LexTokenLiteral tok = new LexTokenLiteral(line, col - 1, TokenKindLiteral.LiteralString, str);// { Col = col - 1, Line = line, Text = str, Kind = TokenKindSymbol.LiteralString };
                    curToks.Add(tok);
                }
                else if (ch == '\r' && nextChar == '\n')
                {
                    Next(); Next();
                    AddLineToken();//lineTokens.Add(curToks);
                    curToks = new LineTokenCollection();
                    ScanNewLine();
                }
                else if (ch == '\n' || ch == '\r')
                {
                    Next();
                    AddLineToken(); //lineTokens.Add(curToks);
                    curToks = new LineTokenCollection();
                    ScanNewLine();
                }
                else if ("0123456789".IndexOf(ch) != -1)
                {
                    string str  = scanNumber();
                    var    temp = col;
                    if (StringHelper.IsInt(str))
                    {
                        LexTokenLiteral tok = new LexTokenLiteral(line, temp, TokenKindLiteral.LiteralInt, str);
                        curToks.Add(tok);
                    }
                    else if (StringHelper.IsFloat(str))
                    {
                        LexTokenLiteral tok = new LexTokenLiteral(line, temp, TokenKindLiteral.LiteralFloat, str);
                        curToks.Add(tok);
                    }
                    else
                    {
                        lexError(str + "不是正确的数字");
                    }
                }
                else if (ch == '+')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.ADD);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == '-')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.SUB);
                    curToks.Add(tok);
                    Next();
                }
                else if ((ch == '=') && (nextChar == '='))
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.EQ);
                    curToks.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '=') && (nextChar == '>'))
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.AssignTo);
                    curToks.Add(tok);
                    Next(); Next();
                }
                else if ((ch == '='))
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.Assign);
                    curToks.Add(tok);
                    Next();
                }
                else if ((ch == '*'))
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.MUL);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == ',' || ch == ',')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.Comma);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == ';' || ch == ';')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.Semi);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == '(' || ch == '(')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.LBS);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == ')' || ch == ')')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.RBS);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == '>' && GetNext() == '=')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.GE);
                    curToks.Add(tok);
                    Next(); Next();
                }
                else if (ch == '>')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.GT);
                    curToks.Add(tok);
                    Next();
                }
                else if (ch == '<' && nextChar == '=')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.LE);
                    curToks.Add(tok);
                    Next(); Next();
                }
                else if (ch == '<')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.LT);
                    curToks.Add(tok);
                    Next();
                }
                else if ((nextChar == '!' || nextChar == '!') && (nextChar == '=' || nextChar == '='))
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.NE);
                    curToks.Add(tok);
                    Next(); Next();
                }
                else if (ch == ':' || ch == ':')
                {
                    LexTokenSymbol tok = new LexTokenSymbol(line, col, TokenKindSymbol.Colon);// { Col = col, Line = line, Kind = TokenKindSymbol.Colon };
                    curToks.Add(tok);
                    Next();
                }
                else if ((ch >= 'A' && ch <= 'Z') /*|| (ch == '_') */ || (ch >= 'a' && ch <= 'z') || ChineseHelper.IsChineseLetter(ch))
                {
                    var      tempCol  = col;
                    var      tempLine = line;
                    LexToken t1       = scanIdentToken();
                    if (t1.Text == "说明")
                    {
                        if (ch == ':' || ch == ':')
                        {
                            SkipSingleLineComment();
                            continue;;
                        }
                    }
                    addIdentOrKey(t1);
                }
                else if (char.IsControl(ch))
                {
                    while (char.IsControl(ch) && ch != END)
                    {
                        Next();
                        if ((int)ch == 13)
                        {
                            ScanNewLine();
                        }
                    }
                }
                else
                {
                    lexError("无法识别" + (int)ch + ": '" + ch + "' ");
                    Next();
                }
            }
            if (curToks != null && curToks.Count > 0)
            {
                AddLineToken();
            }
            return(lineTokens);
        }