Пример #1
0
 public CodePositionInfo GetPositionInfo(int lineNumber)
 {
     var cp = new CodePositionInfo();
     cp.LineNumber = lineNumber;
     cp.Code = GetCodeLine(lineNumber);
     return cp;
 }
Пример #2
0
        public CodePositionInfo GetPositionInfo(int lineNumber)
        {
            var cp = new CodePositionInfo();

            cp.LineNumber = lineNumber;
            cp.Code       = GetCodeLine(lineNumber);
            return(cp);
        }
        internal static CompilerException AppendCodeInfo(CompilerException exc, CodePositionInfo codePosInfo)
        {
            exc.LineNumber   = codePosInfo.LineNumber;
            exc.ColumnNumber = codePosInfo.LineNumber;
            exc.Code         = codePosInfo.Code;
            exc.ModuleName   = codePosInfo.ModuleName;

            return(exc);
        }
Пример #4
0
        public CodePositionInfo GetPositionInfo()
        {
            var posInfo = new CodePositionInfo()
            {
                LineNumber   = CurrentLine,
                ColumnNumber = CurrentColumn,
                Code         = GetCodeLine(CurrentLine)
            };

            return(posInfo);
        }
Пример #5
0
 internal static CompilerException AppendCodeInfo(CompilerException exc, CodePositionInfo codePosInfo)
 {
     AppendCodeInfo(exc, codePosInfo.LineNumber, codePosInfo.Code);
     return(exc);
 }
Пример #6
0
 internal ExtraClosedParenthesis(CodePositionInfo codePosInfo) : base(Locale.NStr("ru='Ожидается символ: (';en='Expecting symbol: ('"))
 {
     this.LineNumber = codePosInfo.LineNumber;
     this.Code       = codePosInfo.Code;
 }
Пример #7
0
 internal ExtraClosedParenthesis(CodePositionInfo codePosInfo) : base("Ожидается символ: (")
 {
     this.LineNumber = codePosInfo.LineNumber;
     this.Code       = codePosInfo.Code;
 }
Пример #8
0
 internal ParserException(CodePositionInfo posInfo, string message)
     : base(posInfo, message)
 {
 }
Пример #9
0
 private void AppendCodeInfo(int line, CompilerException exc)
 {
     var cp = new CodePositionInfo();
     cp.LineNumber = line;
     cp.Code = _parser.GetCodeLine(line);
     CompilerException.AppendCodeInfo(exc, cp);
 }
Пример #10
0
 internal static CompilerException AppendCodeInfo(CompilerException exc, CodePositionInfo codePosInfo)
 {
     AppendCodeInfo(exc, codePosInfo.LineNumber, codePosInfo.Code);
     return exc;
 }
Пример #11
0
 internal ExtraClosedParenthesis(CodePositionInfo codePosInfo) : base("Ожидается символ: (")
 {
     this.LineNumber = codePosInfo.LineNumber;
     this.Code = codePosInfo.Code;
 }
Пример #12
0
 internal SyntaxErrorException(CodePositionInfo codeInfo, string message) : base(codeInfo, message)
 {
 }
Пример #13
0
            public void Build(Token stopToken)
            {
                const int STATE_UNDEF             = 0;
                const int STATE_OPERAND_EXPECTED  = 1;
                const int STATE_FUNC_WAIT         = 2;
                const int STATE_OPERATOR_EXPECTED = 3;

                _operators = new Stack <Token>();

                int    currentState      = STATE_UNDEF;
                string waitingIdentifier = null;
                int    parCount          = 0;

                while (true)
                {
                    bool success = false;

                    if (_compiler._lastExtractedLexem.Token == stopToken)
                    {
                        if (currentState == STATE_FUNC_WAIT)
                        {
                            _compiler.BuildPushVariable(waitingIdentifier);
                        }
                        else if (currentState != STATE_OPERATOR_EXPECTED)
                        {
                            throw CompilerException.ExpressionSyntax();
                        }
                        break;
                    }

                    switch (currentState)
                    {
                    case STATE_UNDEF:
                    case STATE_OPERAND_EXPECTED:
                        if (_compiler.IsLiteral(ref _compiler._lastExtractedLexem))
                        {
                            _compiler.BuildPushConstant();
                            currentState = STATE_OPERATOR_EXPECTED;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Type == LexemType.Identifier)
                        {
                            if (_compiler._lastExtractedLexem.Token == Token.NotAToken)
                            {
                                waitingIdentifier = _compiler._lastExtractedLexem.Content;
                                currentState      = STATE_FUNC_WAIT;
                                success           = true;
                            }
                            else if (LanguageDef.IsBuiltInFunction(_compiler._lastExtractedLexem.Token))
                            {
                                _compiler.BuildBuiltinFunction();
                                currentState = STATE_OPERATOR_EXPECTED;
                                success      = true;
                            }
                            else if (_compiler._lastExtractedLexem.Token == Token.NewObject)
                            {
                                _compiler.BuildNewObjectCreation();
                                currentState = STATE_OPERATOR_EXPECTED;
                                success      = true;
                            }
                            else
                            {
                                throw CompilerException.TokenExpected(stopToken);
                            }
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.Minus)
                        {
                            PushOperator(Token.UnaryMinus);
                            currentState = STATE_OPERAND_EXPECTED;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.OpenPar)
                        {
                            PushOperator(Token.OpenPar);
                            parCount++;
                            currentState = STATE_UNDEF;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.Not)
                        {
                            PushOperator(Token.Not);
                            currentState = STATE_OPERAND_EXPECTED;
                            success      = true;
                        }

                        break;

                    case STATE_FUNC_WAIT:
                        if (_compiler._lastExtractedLexem.Token == Token.OpenPar)
                        {
                            _compiler.BuildFunctionCall(waitingIdentifier);
                            if (_compiler._lastExtractedLexem.Token == Token.ClosePar)
                            {
                                currentState = STATE_OPERATOR_EXPECTED;
                                success      = true;
                            }
                            else if (_compiler._lastExtractedLexem.Type == LexemType.Operator)
                            {
                                currentState = STATE_OPERATOR_EXPECTED;
                                continue;
                            }
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.OpenBracket)
                        {
                            _compiler.BuildIndexedAccess(waitingIdentifier);
                            currentState = STATE_OPERATOR_EXPECTED;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.Dot)
                        {
                            _compiler.BuildPushVariable(waitingIdentifier);
                            int identifier;
                            _compiler.BuildResolveChain(out identifier);
                            _compiler.ProcessResolvedItem(identifier, stopToken);

                            if (_compiler._lastExtractedLexem.Type == LexemType.Operator || _compiler._lastExtractedLexem.Token == stopToken)
                            {
                                currentState = STATE_OPERATOR_EXPECTED;
                                continue;
                            }
                        }
                        else if (_compiler._lastExtractedLexem.Type == LexemType.Operator && IsBinaryOperator(_compiler._lastExtractedLexem.Token))
                        {
                            _compiler.BuildPushVariable(waitingIdentifier);
                            currentState = STATE_OPERATOR_EXPECTED;
                            continue;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.ClosePar)
                        {
                            _compiler.BuildPushVariable(waitingIdentifier);
                            currentState = STATE_OPERATOR_EXPECTED;
                            continue;
                        }

                        break;

                    case STATE_OPERATOR_EXPECTED:
                        if (_compiler._lastExtractedLexem.Type == LexemType.Operator && IsBinaryOperator(_compiler._lastExtractedLexem.Token))
                        {
                            ProcessExpressionOperator();
                            currentState = STATE_OPERAND_EXPECTED;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.ClosePar)
                        {
                            Token current;
                            parCount--;
                            if (parCount < 0)
                            {
                                UnwindOperators();
                                var cp = new CodePositionInfo();
                                cp.LineNumber = _compiler._parser.CurrentLine;
                                cp.Code       = _compiler._parser.GetCodeLine(cp.LineNumber);
                                throw new ExtraClosedParenthesis(cp);
                            }

                            if (_operators.Count > 0)
                            {
                                while ((current = PopOperator()) != Token.OpenPar)
                                {
                                    AddCommandForToken(current);
                                    if (_operators.Count == 0)
                                    {
                                        throw CompilerException.TokenExpected(Token.OpenPar);
                                    }
                                }

                                currentState = STATE_OPERATOR_EXPECTED;
                                success      = true;
                            }
                            else
                            {
                                throw CompilerException.TokenExpected(Token.OpenPar);
                            }
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.OpenBracket)
                        {
                            _compiler.NextToken();
                            _compiler.BuildExpression(Token.CloseBracket);
                            _compiler.AddCommand(OperationCode.PushIndexed, 0);
                            currentState = STATE_OPERATOR_EXPECTED;
                            success      = true;
                        }
                        else if (_compiler._lastExtractedLexem.Token == Token.Dot)
                        {
                            int identifier;
                            _compiler.BuildResolveChain(out identifier);
                            _compiler.ProcessResolvedItem(identifier, stopToken);

                            if (_compiler._lastExtractedLexem.Type == LexemType.Operator || _compiler._lastExtractedLexem.Token == stopToken)
                            {
                                currentState = STATE_OPERATOR_EXPECTED;
                                continue;
                            }
                        }
                        else if (_compiler._lastExtractedLexem.Token != stopToken)
                        {
                            throw CompilerException.TokenExpected(stopToken);
                        }
                        break;
                    }

                    if (success)
                    {
                        if (_compiler._lastExtractedLexem.Token != stopToken)
                        {
                            _compiler.NextToken();
                        }
                    }
                    else
                    {
                        throw CompilerException.ExpressionSyntax();
                    }
                }

                UnwindOperators();
            }
Пример #14
0
 internal ParserException(CodePositionInfo posInfo, string message)
     :base(posInfo, message)
 {
 }