Exemplo n.º 1
0
            private LexType GetLexType(string lex)
            {
                if (keyWords.Contains(lex))
                {
                    return(LexType.KeyWord);
                }

                if (lex == "=")
                {
                    return(LexType.AssignmentSymbol);
                }

                if (operations.Contains(lex[0]))
                {
                    return(LexType.AssignmentSymbol);
                }

                if (LogicalOperations.Contains(lex))
                {
                    return(LexType.LogicOperator);
                }

                if (Int32.TryParse(lex, out _))
                {
                    return(LexType.Constant);
                }

                return(LexType.Identifier);
            }
Exemplo n.º 2
0
        static void SetTable(string line, List <Token> lexems)
        {
            string tmp      = "";
            string logicTmp = "";

            foreach (var c in line)
            {
                if (separators.Contains(c))
                {
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        lexems.Add(new Token(tmp));
                        tmp = "";
                    }

                    if (!string.IsNullOrEmpty(logicTmp))
                    {
                        lexems.Add(new Token(logicTmp));
                        logicTmp = "";
                    }

                    continue;
                }

                if (operations.Contains(c))
                {
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        lexems.Add(new Token(tmp));
                        tmp = "";
                    }

                    logicTmp = "";
                }

                if (Logic.Contains(c))
                {
                    logicTmp += c;
                    continue;
                }

                if (LogicalOperations.Contains(logicTmp) || logicTmp == "=")
                {
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        lexems.Add(new Token(tmp));
                        lexems.Add(new Token(logicTmp));
                        logicTmp = "";
                        tmp      = "";
                    }
                    else
                    {
                        throw new Exception("Косяк в логике");
                    }
                }

                tmp += c;
            }

            if (!string.IsNullOrEmpty(tmp))
            {
                throw new Exception("Что-то не так в условии, либо не хватает ;");
            }
        }