Пример #1
0
    public static NeuKeyword?GetDeclarationKindKeyword(
        this NeuVarDecl varDecl)
    {
        foreach (var child in varDecl.Children)
        {
            switch (child)
            {
            case NeuKeyword k when k.KeywordType == NeuKeywordType.Let:

                return(k);

            ///

            case NeuKeyword k when k.KeywordType == NeuKeywordType.Var:

                return(k);

            ///

            default:

                return(null);
            }
        }

        ///

        return(null);
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuVarDecl varDecl)
    {
        // TODO: Change this so it's non-function scoped stack

        var inGlobalScope = interpreter.Stack.Count() == 0;

        ///

        var lastValue = NeuOperation.Void;

        ///

        var kind = varDecl.GetDeclarationKindKeyword();

        if (kind == null)
        {
            throw new Exception();
        }

        ///

        var patternBindingList = varDecl.GetPatternBindingList();

        if (patternBindingList == null)
        {
            throw new Exception();
        }

        ///

        foreach (var c in patternBindingList.Children)
        {
            switch (c)
            {
            case NeuPatternBinding patternBinding:

                lastValue = interpreter.Execute(inGlobalScope, kind, patternBinding);

                break;

            ///

            default:

                throw new Exception();
            }
        }

        ///

        return(lastValue);
    }
Пример #3
0
    ///

    public static NeuPatternBindingList?GetPatternBindingList(
        this NeuVarDecl varDecl)
    {
        foreach (var child in varDecl.Children)
        {
            switch (child)
            {
            case NeuPatternBindingList l:

                return(l);

            ///

            default:

                break;
            }
        }

        ///

        return(null);
    }