Exemplo n.º 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");
                }
            }
        }
Exemplo n.º 2
0
        public override void OnVisitMatch(ParseNode node)
        {
            if (!node.Parent.NodeMatchesRule(RuleKind.FunctionDeclaration))
                return;
            var cleanStates = new CleanupAstNodeStates(node.Children);
            var advancePosition = 1;
            while (advancePosition < cleanStates.Count - 1)
            {
                var currentNode = cleanStates.MappedNodes[advancePosition];
                var tokenKind = currentNode.GetTokenKind();
                switch (tokenKind)
                {
                    case TokenKind.TypeName:
                        cleanStates.ShiftVariableDeclaration(advancePosition);
                        break;

                    case TokenKind.Static:
                        cleanStates.ShiftStaticVariableDeclaration(advancePosition);
                        break;
                    case TokenKind.Identifier:
                        var isAssignment = CheckIsAssignment(cleanStates, advancePosition);
                        if (isAssignment)
                        {
                            cleanStates.ShiftAssignment(advancePosition);
                        }
                        else
                        {
                            cleanStates.ShiftCall(advancePosition);
                        }
                        break;
                    case TokenKind.CloseCurly:
                        throw new InvalidDataException("Unmatched closed curly");
                    case TokenKind.None:
                        break;
                    default:
                        throw new InvalidDataException("Input type not handled");
                }
                advancePosition++;
            }
        }
Exemplo n.º 3
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");
                }
            }
        }
Exemplo n.º 4
0
 static void ShiftStaticDefinition(CleanupAstNodeStates cleanStates, int advancePosition)
 {
     cleanStates.ShiftVariableDeclaration(advancePosition + 1);
     cleanStates.ReduceRangeOfTokensAsParent(advancePosition, advancePosition + 1, RuleKind.Static);
 }