Esempio n. 1
0
        private SyntaxTree ParseTree(TokFlow flow)
        {
            while (true)
            {
                flow.SkipNewLines();
                if (flow.IsDoneOrEof())
                {
                    break;
                }

                _attributes        = flow.ReadAttributes();
                _startOfTheLine    = flow.IsStartOfTheLine();
                _exprStartPosition = flow.Current.Start;

                var e = SyntaxNodeReader.ReadNodeOrNull(flow)
                        ?? throw ErrorFactory.UnknownValueAtStartOfExpression(_exprStartPosition, flow.Current);

                if (e is TypedVarDefSyntaxNode typed)
                {
                    if (flow.IsCurrent(TokType.Def))
                    {
                        ReadEquation(typed, typed.Id);
                    }
                    else
                    {
                        ReadInputVariableSpecification(typed);
                    }
                }
                else if (flow.IsCurrent(TokType.Def) || flow.IsCurrent(TokType.Colon))
                {
                    if (e is NamedIdSyntaxNode variable)
                    {
                        ReadEquation(variable, variable.Id);
                    }
                    //Fun call can be used as fun definition
                    else if (e is FunCallSyntaxNode fun && !fun.IsOperator)
                    {
                        ReadUserFunction(fun);
                    }
                    else
                    {
                        throw ErrorFactory.ExpressionBeforeTheDefinition(_exprStartPosition, e, flow.Current);
                    }
                }