예제 #1
0
        public static Either <ParseException, Pair <List <IToken>, SummandNode> > Parse(List <IToken> tokens, IScopedTable <IEntityType, string> parentTypeTable)
        {
            Console.WriteLine("SummandNode");
            var maybePrimary = PrimaryNode.Parse(tokens, parentTypeTable);

            if (maybePrimary.IsRight)
            {
                tokens = maybePrimary.RightToList()[0].First;
                while (tokens.Count > 0)
                {
                    if (tokens[0] is NewLineSymbolToken || tokens[0] is CommentToken)
                    {
                        tokens = tokens.Skip(1).ToList();
                    }
                    else
                    {
                        break;
                    }
                }
                return(new Pair <List <IToken>, SummandNode>(tokens, new SummandNode(maybePrimary.RightToList()[0].Second, parentTypeTable)));
            }


            if (tokens.Count < 1)
            {
                return(NotASummandException);
            }
            if (!(tokens[0] is LeftParenthSymbolToken))
            {
                return(NotASummandException);
            }
            tokens = tokens.Skip(1).ToList();



            var maybeExpression = ExpressionNode.Parse(tokens, parentTypeTable);

            if (maybeExpression.IsLeft)
            {
                return(maybeExpression.LeftToList()[0]);
            }
            tokens = maybeExpression.RightToList()[0].First;



            if (tokens.Count < 1)
            {
                return(NotASummandException);
            }
            if (!(tokens[0] is RightParenthSymbolToken))
            {
                return(NotASummandException);
            }
            tokens = tokens.Skip(1).ToList();

            while (tokens.Count > 0)
            {
                if (tokens[0] is NewLineSymbolToken || tokens[0] is CommentToken)
                {
                    tokens = tokens.Skip(1).ToList();
                }
                else
                {
                    break;
                }
            }



            return(new Pair <List <IToken>, SummandNode>(tokens, new SummandNode(maybeExpression.RightToList()[0].Second, parentTypeTable)));
        }
예제 #2
0
 private SummandNode(PrimaryNode primary, IScopedTable <IEntityType, string> parentTypeTable)
 {
     Primary         = primary;
     ParentTypeTable = parentTypeTable;
 }