示例#1
0
        public override List <GraphNode <SStatement> > BuildGraphNodes(Graph <SStatement> graph,
                                                                       List <GraphNode <SStatement> > previousNodes)
        {
            var currentNode = graph.AddNode(new GraphNode <SStatement>(this));

            foreach (var node in previousNodes)
            {
                graph.AddDirectedEdge(node, currentNode, 1);
            }

            previousNodes = new List <GraphNode <SStatement> > {
                currentNode
            };

            if (_statementList.Length > 0 && _statementList[0] != null)
            {
                previousNodes = _statementList[0].BuildGraphNodes(graph, previousNodes);
            }

            if (NextStatement != null)
            {
                previousNodes = NextStatement.BuildGraphNodes(graph, previousNodes);
            }

            return(previousNodes);
        }
示例#2
0
        public override List <GraphNode <SStatement> > BuildGraphNodes(Graph <SStatement> graph,
                                                                       List <GraphNode <SStatement> > previousNodes)
        {
            var currentNode = graph.AddNode(new GraphNode <SStatement>(this));

            foreach (var node in previousNodes)
            {
                graph.AddDirectedEdge(node, currentNode, 1);
            }

            var currentNodes = new List <GraphNode <SStatement> > {
                currentNode
            };
            var ntrue = IfTrueStatement.BuildGraphNodes(graph, currentNodes);

            if (ElseStatement != null)
            {
                var nfalse = ElseStatement.BuildGraphNodes(graph, currentNodes);
                ntrue.AddRange(nfalse);
            }
            else
            {
                ntrue.Add(currentNode);
            }

            previousNodes = NextStatement != null?NextStatement.BuildGraphNodes(graph, ntrue) : ntrue;

            return(previousNodes);
        }
示例#3
0
 public virtual object Walk(NextStatement node)
 {
     if (Enter(node))
     {
         // Insert code here
     }
     Exit(node);
     return(null);
 }
示例#4
0
        public override string VisitNextStatement(BasicParser.NextStatementContext context)
        {
            var variableName  = context.VARNAME().ToString();
            var nextStatement = new NextStatement(variableName);

            Statements[_currentLineNumber] = nextStatement;

            return(base.VisitNextStatement(context));
        }
示例#5
0
        public NextStatement ParseNextStatement()
        {
            var nextStatement = new NextStatement {
                Token = Next()
            };

            Match(TokenType.Next);
            Match(TokenType.SemiColon);
            return(nextStatement);
        }
示例#6
0
        public override List <GraphNode <SStatement> > BuildGraphNodes(Graph <SStatement> graph,
                                                                       List <GraphNode <SStatement> > previousNodes)
        {
            var currentNodes = new List <GraphNode <SStatement> >();
            var currentNode  = graph.AddNode(new GraphNode <SStatement>(this));

            graph.AddDirectedEdges(previousNodes, currentNode, 1);

            var currentNodeList = new List <GraphNode <SStatement> > {
                currentNode
            };
            var nextNode = new List <GraphNode <SStatement> >();

            if (SwitchStatement != null)
            {
                nextNode.AddRange(SwitchStatement.BuildGraphNodes(graph, currentNodeList));
            }

            foreach (var jumpTarget in jumpTargets)
            {
                var a = FindNodes(graph, jumpTarget.NextStatement);
                if (a != null)
                {
                    foreach (var graphNode in a)
                    {
                        graphNode.Neighbors.Clear();
                        graphNode.Costs.Clear();
                    }
                }

                AddDirectedEdgeToElements(graph, currentNode.Value, jumpTarget.LabeledStatement);
                currentNodes.AddRange(FindNodes(graph, jumpTarget.NextStatement));
            }

            currentNodes.AddRange(nextNode);

            //todo: change default on enum
            if (jumpTargets.Count(q => q.CodeString == "default") == 0)
            {
                currentNodes.Add(currentNode);
            }

            if (NextStatement != null)
            {
                currentNodes = new List <GraphNode <SStatement> >(NextStatement.BuildGraphNodes(graph, currentNodes));
            }

            return(currentNodes);
        }
示例#7
0
        public override List <GraphNode <SStatement> > BuildGraphNodes(Graph <SStatement> graph,
                                                                       List <GraphNode <SStatement> > previousNodes)
        {
            TargetStatement?.AddJumpOrigin(this);

            var currentNode = graph.AddNode(new GraphNode <SStatement>(this));

            foreach (var node in previousNodes)
            {
                graph.AddDirectedEdge(node, currentNode, 1);
            }

            previousNodes = new List <GraphNode <SStatement> > {
                currentNode
            };

            var findedNode = (GraphNode <SStatement>)graph.Nodes.FindByValue(TargetStatement);

            graph.AddDirectedEdge(currentNode, findedNode, 1);

            return(NextStatement != null
                ? NextStatement.BuildGraphNodes(graph, previousNodes)
                : new List <GraphNode <SStatement> >());
        }
 public virtual void Exit(NextStatement node)
 {
 }
示例#9
0
        //factory method that takes a line of input and creates a statement
        //object
        public static Statement CreateStatement(Scanner s)
        {
            //Remember what line we started on in case the
            //statement spans lines.

            int  line    = s.LineNumber;
            bool please  = false;
            bool enabled = true;
            int  percent = 100;

            Statement retval = null;
            string    Label  = null;


            try
            {
                //First we look to see if there is a label...

                if (s.Current.Groups["label"].Success)
                {
                    Label = Statement.ReadGroupValue(s, "label");
                    s.MoveNext();
                }

                bool validPrefix = false;



                //Next we expect either DO, PLEASE, or PLEASE DO
                if (s.Current.Value == "PLEASE")
                {
                    validPrefix = true;
                    please      = true;
                    s.MoveNext();
                }

                //If they've said PLEASE then they don't *have* to
                //use DO.  Unless they plan on doing a DON'T or DO NOT
                if (s.Current.Value == "DO")
                {
                    validPrefix = true;
                    s.MoveNext();

                    if (s.Current.Value == "NOT" ||
                        s.Current.Value == "N'T")
                    {
                        enabled = false;
                        s.MoveNext();
                    }
                }


                //Finally the user might put a %50 here.  Note that
                //even if the statement is disabled we need to remember
                //the % on the off chance that the statement gets enabled
                //later.
                if (s.Current.Value == "%")
                {
                    s.MoveNext();
                    string p = Statement.ReadGroupValue(s, "digits");
                    percent = Int32.Parse(p);
                    s.MoveNext();
                }


                //Here we parse out the statement prefix.  Easier to
                //do it here than break out a separate function.

                while (s.Current.Groups["prefix"].Success)
                {
                    switch (s.Current.Value)
                    {
                    case "DO":
                        validPrefix = true;
                        break;

                    case "PLEASE":
                        validPrefix = true;
                        please      = true;
                        break;

                    case "NOT":
                    case "N'T":
                        enabled = false;
                        break;

                    case "%":
                        s.MoveNext();
                        string p = Statement.ReadGroupValue(s, "digits");
                        percent = Int32.Parse(p);
                        break;
                    }
                    s.MoveNext();
                }


                if (!validPrefix)
                {
                    throw new ParseException(String.Format(Messages.E017, s.LineNumber + 1));
                }

                if (s.Current.Groups["statement"].Success)
                {
                    //We are looking at the beginning of a statement
                    switch (s.Current.Value)
                    {
                    case "ABSTAIN FROM": retval = new AbstainStatement(s);   break;

                    case "READ OUT":        retval = new ReadOutStatement(s);       break;

                    case "WRITE IN":        retval = new WriteInStatement(s);       break;

                    case "COME FROM":       retval = new ComeFromStatement(s);      break;

                    case "REINSTATE":       retval = new ReinstateStatement(s);     break;

                    case "STASH":           retval = new StashStatement(s);         break;

                    case "RESUME":          retval = new ResumeStatement(s);        break;

                    case "FORGET":          retval = new ForgetStatement(s);        break;

                    case "IGNORE":          retval = new IgnoreStatement(s);        break;

                    case "REMEMBER":        retval = new RememberStatement(s);      break;

                    case "RETRIEVE":        retval = new RetrieveStatement(s);      break;

                    case "GIVE UP":         retval = new GiveUpStatement(s);        break;
                    }
                }
                else if (s.Current.Groups["label"].Success)
                {
                    retval = new NextStatement(s);
                }
                else if (s.Current.Groups["var"].Success)
                {
                    retval = new CalculateStatement(s);
                }
                else
                {
                    throw new ParseException(String.Format(Messages.E017, s.LineNumber + 1));
                }


                //Move on to what should be the beginning of the next statement
                s.MoveNext();
            }
            catch (ParseException)
            {
                //Console.WriteLine(p.Message);

                if (retval != null)
                {
                    retval.Splatted = true;
                }

                else
                {
                    retval = new NonsenseStatement(s);
                }

                s.Panic();
            }

            //Note that even badly formed statements get their labels set. This way
            //you can still jump to them (though that will cause an exception).
            if (Label != null)
            {
                retval.Label = Label;
            }

            retval.LineNumber = line;
            retval.bEnabled   = enabled;
            retval.bPlease    = please;
            retval.Percent    = percent;

            return(retval);
        }
 public virtual bool Enter(NextStatement node)
 {
     return(true);
 }
示例#11
0
文件: Parser.cs 项目: buunguyen/bike
 public NextStatement ParseNextStatement()
 {
     var nextStatement = new NextStatement { Token = Next() };
     Match(TokenType.Next);
     Match(TokenType.SemiColon);
     return nextStatement;
 }
示例#12
0
 public override object Walk(NextStatement node)
 {
     throw new Next();
 }
示例#13
0
 public override void Exit(NextStatement node)
 {
     level--;
 }
示例#14
0
 public virtual object Walk(NextStatement node)
 {
     if (Enter(node))
     {
         // Insert code here
     }
     Exit(node);
     return null;
 }
示例#15
0
 public override bool Enter(NextStatement node)
 {
     Print("NextStatement");
     level++;
     return true;
 }
示例#16
0
 public virtual bool Enter(NextStatement node)
 {
     return true;
 }
示例#17
0
 protected override void visitNextStatement(NextStatement statement)
 {
     appendExitOrNextStatement(statement, KeywordEnum.NEXT, statement.Loop, statement.Condition);
 }
示例#18
0
 public virtual void Exit(NextStatement node)
 {
 }
示例#19
0
 public override object Walk(NextStatement node)
 {
     throw new Next();
 }
示例#20
0
 public override void Exit(NextStatement node)
 {
     level--;
 }
示例#21
0
 public override bool Enter(NextStatement node)
 {
     Print("NextStatement");
     level++;
     return(true);
 }