Exemplo n.º 1
0
        public static KirinProgram ParseReport(FiMReport report, string content)
        {
            var program = new KirinProgram(-1, -1);

            var lines = FindAllLines(content);
            var nodes = new List <KirinNode>();

            foreach (var line in lines)
            {
                var node = ParseLine(report, content, line.Start, line.End - line.Start);
                nodes.Add(node);
            }

            if (nodes.FindIndex(n => n.NodeType == "KirinProgramStart") != 0)
            {
                throw new Exception("Start of report must be the first line");
            }
            if (nodes.FindIndex(n => n.NodeType == "KirinProgramEnd") == -1)
            {
                throw new Exception("Cannot find end of report");
            }
            if (nodes.FindIndex(n => n.NodeType == "KirinProgramEnd") < nodes.Count - 1)
            {
                for (int i = nodes.FindIndex(n => n.NodeType == "KirinProgramEnd") + 1; i < nodes.Count; i++)
                {
                    if (nodes[i].NodeType != "KirinPostScript")
                    {
                        throw new Exception($"Expected EOR at line {FiMHelper.GetIndexPair(content, (nodes[i] as KirinNode).Start).Line}");
                    }
                }
            }

            var startIndex = nodes.FindIndex(n => n.NodeType == "KirinProgramStart");
            var endIndex   = nodes.FindIndex(n => n.NodeType == "KirinProgramEnd");

            ParseClass(
                report,
                nodes.GetRange(startIndex + 1, endIndex - (startIndex + 1)).ToArray(),
                content
                );

            var startNode = nodes[startIndex] as KirinProgramStart;
            var endNode   = nodes[endIndex] as KirinProgramEnd;

            report.Info = new FiMReportInfo(startNode.Start, startNode.Length)
            {
                Recipient = startNode.ProgramRecipient,
                Name      = startNode.ProgramName
            };
            report.Author = new FiMReportAuthor(endNode.Start, endNode.Length)
            {
                Role = endNode.AuthorRole,
                Name = endNode.AuthorName
            };

            return(program);
        }
Exemplo n.º 2
0
        public FiMClass(string name, bool main = false, FiMClass parent = null, FiMReport report = null)
        {
            this.Variables  = new FiMVariableList();
            this.Paragraphs = new Stack <FiMParagraph>();
            this.Classes    = new Stack <FiMClass>();

            this.Name = name;

            this.IsMain = main;
            if (this.IsMain)
            {
                this.Report = report;
                this.Parent = parent;
            }
        }
Exemplo n.º 3
0
        private static KirinNode ParseLine(FiMReport report, string content, int start, int length)
        {
            string subContent = content.Substring(start, length - 1);             // Remove punctuation

            if (KirinPostScript.TryParse(subContent, start, length, out KirinNode node))
            {
                return(node);
            }

            if (KirinProgramStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinProgramEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }

#if DEBUG
            if (KirinClassStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinClassEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinClassConstructorStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinClassConstructorEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
#endif

            if (KirinFunctionStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinFunctionEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            ;

            if (KirinForInLoop.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinForToLoop.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinWhileLoop.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinSwitchStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinSwitchCase.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinSwitchCaseDefault.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinLoopEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }

            if (KirinIfStatementStart.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinElseIfStatement.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinIfStatementEnd.TryParse(subContent, start, length, out node))
            {
                return(node);
            }

            if (KirinPrint.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinInput.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinFunctionCall.TryParse(subContent, report, start, length, out node))
            {
                return(node);
            }
            if (KirinVariableDeclaration.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinListModify.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinVariableModify.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinUnary.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinReturn.TryParse(subContent, start, length, out node))
            {
                return(node);
            }
            if (KirinDebugger.TryParse(subContent, start, length, out node))
            {
                return(node);
            }

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                System.Diagnostics.Debugger.Break();
            }
            else
            {
                Console.WriteLine("Unhandled node: " + subContent);
            }
#endif

            return(new KirinNode(start, length));
        }