예제 #1
0
        private bool ParseLabeledStatement(ParseTreeNode node, Block block, out Block.StatementElement res)
        {
            List <Label>  labelList     = new List <Label>();
            ParseTreeNode statementNode = node;

            while (true)
            {
                if (statementNode.ChildNodes.Count == 1)
                { //statement
                    statementNode = statementNode.ChildNodes[0];
                    break;
                }
                else if (statementNode.ChildNodes.Count == 2)
                { //label + labeledstatement
                    ParseTreeNode lblNode = statementNode.ChildNodes[0];
                    Label         lbl     = new Label()
                    {
                        AssemblePosition = new Assemble.AssemblePosition(this.ParsingFilePath, lblNode),
                        Name             = lblNode.ChildNodes[0].Token.Text,
                        DefinedBlock     = block
                    };
                    labelList.Add(lbl);

                    statementNode = statementNode.ChildNodes[1];
                }
            }

            if (!ParseStatement(statementNode, block, labelList, out res))
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        private bool ParseStatement(ParseTreeNode node, Block block, List <Label> labels, out Block.StatementElement res)
        {
            res = new Block.StatementElement();

            if (node.ChildNodes[0].Term.Name == "instruction")
            {
                Instruction instr;
                if (!ParseInstruction(node.ChildNodes[0], block, labels, out instr))
                {
                    return(false);
                }

                res.Type        = Block.enumStatementType.Instruction;
                res.Instruction = instr;
                return(true);
            }
            else if (node.ChildNodes[0].Term.Name == "macrocall")
            {
                Macrocall mcrocall;
                if (!ParseMacrocall(node.ChildNodes[0], block, labels, out mcrocall))
                {
                    return(false);
                }

                res.Type      = Block.enumStatementType.Macrocall;
                res.Macrocall = mcrocall;
                return(true);
            }

            ReportError("Statement", "Unknown statement type.", node.ChildNodes[0]);
            return(false);
        }
예제 #3
0
        private bool ParseBlockContents(ParseTreeNode node, ref Block res)
        {
            { //Contents
                ParseTreeNode contents = node;
                foreach (var e in contents.ChildNodes)
                {
                    if (e.ChildNodes[0].Term.Name == "labeled-statement")
                    {
                        Block.StatementElement stmt;
                        if (!ParseLabeledStatement(e.ChildNodes[0], res, out stmt))
                        {
                            return(false);
                        }

                        res.Statements.Add(stmt);
                    }
                    else if (e.ChildNodes[0].Term.Name == "blockdef")
                    {
                        Block.StatementElement stmt;
                        Block subBlock;
                        if (!ParseBlock(e.ChildNodes[0], res, out subBlock))
                        {
                            return(false);
                        }

                        stmt = new Block.StatementElement()
                        {
                            Type  = Block.enumStatementType.Block,
                            Block = subBlock
                        };
                        res.Statements.Add(stmt);
                    }
                    else if (e.ChildNodes[0].Term.Name == "macrodef")
                    {
                        MacroDefinition mcrodef;
                        if (!ParseMacroDefinition(e.ChildNodes[0], res, out mcrodef))
                        {
                            return(false);
                        }

                        res.MacroDefinitions.Add(mcrodef);
                    }
                    else if (e.ChildNodes[0].Term.Name == "variabledef")
                    {
                        Variable varb;
                        if (!ParseVariable(e.ChildNodes[0], res, out varb))
                        {
                            return(false);
                        }

                        res.Variables.Add(varb);
                    }
                    else if (e.ChildNodes[0].Term.Name == "constantdef")
                    {
                        Variable varb;
                        if (!ParseConstant(e.ChildNodes[0], res, out varb))
                        {
                            return(false);
                        }

                        res.Variables.Add(varb);
                    }
                    else if (e.ChildNodes[0].Term.Name == "symboldef")
                    {
                        Symbol symbl;
                        if (!ParseSymbol(e.ChildNodes[0], res, out symbl))
                        {
                            return(false);
                        }

                        res.Symbols.Add(symbl);
                    }
                }
            }

            return(true);
        }