Beispiel #1
0
        void InterpretGlobal(CleanupAstNodeStates cleanStates)
        {
            for (var advancePosition = 0; advancePosition < cleanStates.Count; advancePosition++)
            {
                var currentNode = cleanStates[advancePosition];
                var tokenKind = currentNode.GetTokenKind();
                switch (tokenKind)
                {
                    case TokenKind.TypeName:
                        var isVariableDeclaration = CheckIfTypeDefinesVariable(advancePosition,
                                                                               cleanStates.MappedNodes);
                        if (isVariableDeclaration)
                            cleanStates.ShiftVariableDeclaration(advancePosition);
                        else
                        {
                            cleanStates.ShiftFunctionDeclaration(advancePosition);
                            var blockStates = cleanStates[advancePosition].States[3].States;
                            InterpretBlock(blockStates);
                        }

                        break;
                    case TokenKind.SharpDefine:
                        cleanStates.ShiftSharpDefineDeclaration(advancePosition);
                        break;

                    case TokenKind.SharpImport:
                        cleanStates.ShiftSharpImports(advancePosition);
                        break;
                    case TokenKind.SharpProperty:
                        break;
                    case TokenKind.Static:
                        ShiftStaticDefinition(cleanStates, advancePosition);
                        break;
                    case TokenKind.Extern:
                        ShiftExternDefinition(cleanStates, advancePosition);

                        break;

                    case TokenKind.Input:
                        cleanStates.ShiftInputs(advancePosition);
                        break;
                    default:
                        throw new InvalidDataException("Input type not handled");
                }
            }
        }
Beispiel #2
0
        void InterpretBlock(CleanupAstNodeStates cleanStates)
        {
            if (cleanStates[0].Token != TokenKind.OpenCurly)
                return;
            for (var advancePosition = 1; advancePosition < cleanStates.Count - 1; advancePosition++)
            {
                var currentNode = cleanStates.MappedNodes[advancePosition];
                var tokenKind = currentNode.GetTokenKind();
                switch (tokenKind)
                {
                    case TokenKind.TypeName:
                        cleanStates.ShiftVariableDeclaration(advancePosition);
                        break;

                    case TokenKind.Identifier:
                        cleanStates.ShiftInstructionDeclaration(advancePosition);
                        break;
                    case TokenKind.SharpDefine:
                        break;

                    case TokenKind.SharpImport:
                        cleanStates.ShiftSharpImports(advancePosition);
                        break;
                    case TokenKind.SharpProperty:
                    case TokenKind.CloseCurly:
                        break;
                    case TokenKind.None:
                        switch (currentNode.Rule)
                        {
                            case RuleKind.BlockCode:
                                var blockStates = currentNode.States;
                                InterpretBlock(blockStates);
                                break;
                        }
                        break;

                    case TokenKind.Break:
                        cleanStates.ShiftBreak(advancePosition);
                        break;
                    case TokenKind.Continue:
                        cleanStates.ShiftContinue(advancePosition);
                        break;

                    case TokenKind.If:
                    case TokenKind.For:
                    case TokenKind.While:
                        InterpretIf(cleanStates, advancePosition);
                        break;
                    case TokenKind.Switch:
                        InterpretIf(cleanStates, advancePosition);
                        break;
                    case TokenKind.Default:
                        InterpretCase(cleanStates, advancePosition);
                        break;
                    case TokenKind.Case:
                        InterpretCase(cleanStates, advancePosition);
                        break;
                    case TokenKind.Else:
                        InterpretElseWhile(cleanStates, advancePosition);
                        break;
                    case TokenKind.Static:
                        ShiftStaticDefinition(cleanStates, advancePosition);
                        break;
                    case TokenKind.Extern:
                        ShiftExternDefinition(cleanStates, advancePosition);
                        break;
                    case TokenKind.Return:
                        ShiftReturn(cleanStates, advancePosition);
                        break;
                    default:
                        throw new InvalidDataException("Input type not handled");
                }
            }
        }