Ejemplo n.º 1
0
        private static Lexem ExtractOperatorContent(SourceCodeIterator iterator)
        {
            Lexem lex;
            var   content = iterator.GetContents();

            lex = new Lexem()
            {
                Type    = LexemType.Operator,
                Content = content,
                Token   = LanguageDef.GetToken(content)
            };
            return(lex);
        }
Ejemplo n.º 2
0
        public void All_Tokens()
        {
            Assert.Equal(Token.If, LanguageDef.GetToken("если"));
            Assert.Equal(Token.Then, LanguageDef.GetToken("тогда"));
            Assert.Equal(Token.Else, LanguageDef.GetToken("иначе"));
            Assert.Equal(Token.ElseIf, LanguageDef.GetToken("иначеесли"));
            Assert.Equal(Token.EndIf, LanguageDef.GetToken("конецесли"));
            Assert.Equal(Token.VarDef, LanguageDef.GetToken("перем"));
            Assert.Equal(Token.ByValParam, LanguageDef.GetToken("знач"));
            Assert.Equal(Token.Procedure, LanguageDef.GetToken("процедура"));
            Assert.Equal(Token.EndProcedure, LanguageDef.GetToken("конецпроцедуры"));
            Assert.Equal(Token.Function, LanguageDef.GetToken("функция"));
            Assert.Equal(Token.EndFunction, LanguageDef.GetToken("конецфункции"));
            Assert.Equal(Token.For, LanguageDef.GetToken("для"));
            Assert.Equal(Token.Each, LanguageDef.GetToken("каждого"));
            Assert.Equal(Token.In, LanguageDef.GetToken("из"));
            Assert.Equal(Token.To, LanguageDef.GetToken("по"));
            Assert.Equal(Token.While, LanguageDef.GetToken("пока"));
            Assert.Equal(Token.Loop, LanguageDef.GetToken("цикл"));
            Assert.Equal(Token.EndLoop, LanguageDef.GetToken("конеццикла"));
            Assert.Equal(Token.Return, LanguageDef.GetToken("возврат"));
            Assert.Equal(Token.Continue, LanguageDef.GetToken("продолжить"));
            Assert.Equal(Token.Break, LanguageDef.GetToken("прервать"));
            Assert.Equal(Token.Try, LanguageDef.GetToken("попытка"));
            Assert.Equal(Token.Exception, LanguageDef.GetToken("исключение"));
            Assert.Equal(Token.RaiseException, LanguageDef.GetToken("вызватьисключение"));
            Assert.Equal(Token.EndTry, LanguageDef.GetToken("конецпопытки"));
            Assert.Equal(Token.NewObject, LanguageDef.GetToken("новый"));
            Assert.Equal(Token.Export, LanguageDef.GetToken("экспорт"));

            Assert.Equal(Token.If, LanguageDef.GetToken("if"));
            Assert.Equal(Token.Then, LanguageDef.GetToken("then"));
            Assert.Equal(Token.Else, LanguageDef.GetToken("else"));
            Assert.Equal(Token.ElseIf, LanguageDef.GetToken("elsif"));
            Assert.Equal(Token.EndIf, LanguageDef.GetToken("endif"));
            Assert.Equal(Token.VarDef, LanguageDef.GetToken("var"));
            Assert.Equal(Token.ByValParam, LanguageDef.GetToken("val"));
            Assert.Equal(Token.Procedure, LanguageDef.GetToken("procedure"));
            Assert.Equal(Token.EndProcedure, LanguageDef.GetToken("endprocedure"));
            Assert.Equal(Token.Function, LanguageDef.GetToken("function"));
            Assert.Equal(Token.EndFunction, LanguageDef.GetToken("endfunction"));
            Assert.Equal(Token.For, LanguageDef.GetToken("for"));
            Assert.Equal(Token.Each, LanguageDef.GetToken("each"));
            Assert.Equal(Token.In, LanguageDef.GetToken("in"));
            Assert.Equal(Token.To, LanguageDef.GetToken("to"));
            Assert.Equal(Token.While, LanguageDef.GetToken("while"));
            Assert.Equal(Token.Loop, LanguageDef.GetToken("do"));
            Assert.Equal(Token.EndLoop, LanguageDef.GetToken("enddo"));
            Assert.Equal(Token.Return, LanguageDef.GetToken("return"));
            Assert.Equal(Token.Continue, LanguageDef.GetToken("continue"));
            Assert.Equal(Token.Break, LanguageDef.GetToken("break"));
            Assert.Equal(Token.Try, LanguageDef.GetToken("try"));
            Assert.Equal(Token.Exception, LanguageDef.GetToken("except"));
            Assert.Equal(Token.RaiseException, LanguageDef.GetToken("raise"));
            Assert.Equal(Token.EndTry, LanguageDef.GetToken("endtry"));
            Assert.Equal(Token.NewObject, LanguageDef.GetToken("new"));
            Assert.Equal(Token.Export, LanguageDef.GetToken("export"));

            Assert.Equal(Token.Plus, LanguageDef.GetToken("+"));
            Assert.Equal(Token.Minus, LanguageDef.GetToken("-"));
            Assert.Equal(Token.Multiply, LanguageDef.GetToken("*"));
            Assert.Equal(Token.Division, LanguageDef.GetToken("/"));
            Assert.Equal(Token.LessThan, LanguageDef.GetToken("<"));
            Assert.Equal(Token.LessOrEqual, LanguageDef.GetToken("<="));
            Assert.Equal(Token.MoreThan, LanguageDef.GetToken(">"));
            Assert.Equal(Token.MoreOrEqual, LanguageDef.GetToken(">="));
            Assert.Equal(Token.NotEqual, LanguageDef.GetToken("<>"));
            Assert.Equal(Token.Modulo, LanguageDef.GetToken("%"));
            Assert.Equal(Token.And, LanguageDef.GetToken("и"));
            Assert.Equal(Token.Or, LanguageDef.GetToken("или"));
            Assert.Equal(Token.Not, LanguageDef.GetToken("не"));
            Assert.Equal(Token.OpenPar, LanguageDef.GetToken("("));
            Assert.Equal(Token.ClosePar, LanguageDef.GetToken(")"));
            Assert.Equal(Token.OpenBracket, LanguageDef.GetToken("["));
            Assert.Equal(Token.CloseBracket, LanguageDef.GetToken("]"));
            Assert.Equal(Token.Dot, LanguageDef.GetToken("."));
            Assert.Equal(Token.Comma, LanguageDef.GetToken(","));
            Assert.Equal(Token.Equal, LanguageDef.GetToken("="));
            Assert.Equal(Token.Semicolon, LanguageDef.GetToken(";"));

            Assert.Equal(Token.Question, LanguageDef.GetToken("?"));
            Assert.Equal(Token.Bool, LanguageDef.GetToken("булево"));
            Assert.Equal(Token.Number, LanguageDef.GetToken("число"));
            Assert.Equal(Token.Str, LanguageDef.GetToken("строка"));
            Assert.Equal(Token.Date, LanguageDef.GetToken("дата"));

            Assert.Equal(Token.StrLen, LanguageDef.GetToken("стрдлина"));
            Assert.Equal(Token.TrimL, LanguageDef.GetToken("сокрл"));
            Assert.Equal(Token.TrimR, LanguageDef.GetToken("сокрп"));
            Assert.Equal(Token.TrimLR, LanguageDef.GetToken("сокрлп"));
            Assert.Equal(Token.Left, LanguageDef.GetToken("лев"));
            Assert.Equal(Token.Right, LanguageDef.GetToken("прав"));
            Assert.Equal(Token.Mid, LanguageDef.GetToken("сред"));
            Assert.Equal(Token.StrPos, LanguageDef.GetToken("найти"));
            Assert.Equal(Token.UCase, LanguageDef.GetToken("врег"));
            Assert.Equal(Token.LCase, LanguageDef.GetToken("нрег"));
            Assert.Equal(Token.Chr, LanguageDef.GetToken("символ"));
            Assert.Equal(Token.ChrCode, LanguageDef.GetToken("кодсимвола"));
            Assert.Equal(Token.EmptyStr, LanguageDef.GetToken("пустаястрока"));
            Assert.Equal(Token.StrReplace, LanguageDef.GetToken("стрзаменить"));

            Assert.Equal(Token.Year, LanguageDef.GetToken("год"));
            Assert.Equal(Token.Month, LanguageDef.GetToken("месяц"));
            Assert.Equal(Token.Day, LanguageDef.GetToken("день"));
            Assert.Equal(Token.Hour, LanguageDef.GetToken("час"));
            Assert.Equal(Token.Minute, LanguageDef.GetToken("минута"));
            Assert.Equal(Token.Second, LanguageDef.GetToken("секунда"));
            Assert.Equal(Token.BegOfYear, LanguageDef.GetToken("началогода"));
            Assert.Equal(Token.BegOfMonth, LanguageDef.GetToken("началомесяца"));
            Assert.Equal(Token.BegOfDay, LanguageDef.GetToken("началодня"));
            Assert.Equal(Token.BegOfHour, LanguageDef.GetToken("началочаса"));
            Assert.Equal(Token.BegOfMinute, LanguageDef.GetToken("началоминуты"));
            Assert.Equal(Token.BegOfQuarter, LanguageDef.GetToken("началоквартала"));
            Assert.Equal(Token.EndOfYear, LanguageDef.GetToken("конецгода"));
            Assert.Equal(Token.EndOfMonth, LanguageDef.GetToken("конецмесяца"));
            Assert.Equal(Token.EndOfDay, LanguageDef.GetToken("конецдня"));
            Assert.Equal(Token.EndOfHour, LanguageDef.GetToken("конецчаса"));
            Assert.Equal(Token.EndOfMinute, LanguageDef.GetToken("конецминуты"));
            Assert.Equal(Token.EndOfQuarter, LanguageDef.GetToken("конецквартала"));
            Assert.Equal(Token.WeekOfYear, LanguageDef.GetToken("неделягода"));
            Assert.Equal(Token.DayOfYear, LanguageDef.GetToken("деньгода"));
            Assert.Equal(Token.DayOfWeek, LanguageDef.GetToken("деньнедели"));
            Assert.Equal(Token.AddMonth, LanguageDef.GetToken("добавитьмесяц"));
            Assert.Equal(Token.CurrentDate, LanguageDef.GetToken("текущаядата"));
            Assert.Equal(Token.Integer, LanguageDef.GetToken("цел"));
            Assert.Equal(Token.Round, LanguageDef.GetToken("окр"));
            Assert.Equal(Token.Log, LanguageDef.GetToken("log"));
            Assert.Equal(Token.Log10, LanguageDef.GetToken("log10"));
            Assert.Equal(Token.Sin, LanguageDef.GetToken("sin"));
            Assert.Equal(Token.Cos, LanguageDef.GetToken("cos"));
            Assert.Equal(Token.Tan, LanguageDef.GetToken("tan"));
            Assert.Equal(Token.ASin, LanguageDef.GetToken("aSin"));
            Assert.Equal(Token.ACos, LanguageDef.GetToken("acos"));
            Assert.Equal(Token.ATan, LanguageDef.GetToken("atan"));
            Assert.Equal(Token.Exp, LanguageDef.GetToken("exp"));
            Assert.Equal(Token.Pow, LanguageDef.GetToken("Pow"));
            Assert.Equal(Token.Sqrt, LanguageDef.GetToken("sqrt"));
            Assert.Equal(Token.Min, LanguageDef.GetToken("min"));
            Assert.Equal(Token.Max, LanguageDef.GetToken("max"));
            Assert.Equal(Token.Format, LanguageDef.GetToken("format"));

            Assert.Equal(Token.ExceptionInfo, LanguageDef.GetToken("информацияобошибке"));
            Assert.Equal(Token.ExceptionDescr, LanguageDef.GetToken("описаниеошибки"));
        }
Ejemplo n.º 3
0
        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            bool isEndOfText = false;
            char cs          = '\0';
            int  currentLine = iterator.CurrentLine;

            while (true)
            {
                if (!isEndOfText)
                {
                    cs = iterator.CurrentSymbol;
                }
                if (SpecialChars.IsDelimiter(cs) || isEndOfText)
                {
                    var content = iterator.GetContents();

                    Lexem lex;

                    if (LanguageDef.IsLogicalOperatorString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.Operator,
                            Token      = LanguageDef.GetToken(content),
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsBooleanLiteralString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.BooleanLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsUndefinedString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.UndefinedLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else if (LanguageDef.IsNullString(content))
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.NullLiteral,
                            Content    = content,
                            LineNumber = currentLine
                        };
                    }
                    else
                    {
                        lex = new Lexem()
                        {
                            Type       = LexemType.Identifier,
                            Content    = content,
                            Token      = LanguageDef.GetToken(content),
                            LineNumber = currentLine
                        };

                        if (LanguageDef.IsBuiltInFunction(lex.Token))
                        {
                            iterator.SkipSpaces();
                            if (iterator.CurrentSymbol != '(')
                            {
                                lex.Token = Token.NotAToken;
                            }
                        }
                    }

                    return(lex);
                }

                if (!iterator.MoveNext())
                {
                    isEndOfText = true;
                }
            }
        }