コード例 #1
0
        private Expression ReadQuotedOutput()
        {
            Expression expression = null;

            while (Peek() != '"')
            {
                var b = Read();

                if (b == '\\')
                {
                    b = Read();
                }

                var io = new Expression.IO {
                    Byte = b, In = false, Out = true
                };

                if (expression == null)
                {
                    expression = io;
                }
                else
                {
                    expression = new Expression.Concat
                    {
                        Left  = expression,
                        Right = io,
                    };
                }
            }

            _codeIndex++;

            return(expression);
        }
コード例 #2
0
        private Expression ParseToParenOrEnd()
        {
            Expression unionTree  = null;
            Expression concatTree = null;

            while (_codeIndex < _code.Length && _code[_codeIndex] != ')' && _code[_codeIndex] != '}')
            {
                if (_code[_codeIndex] == '|')
                {
                    _codeIndex++;

                    concatTree = concatTree ?? new Expression.Empty();

                    if (unionTree == null)
                    {
                        unionTree = concatTree;
                    }
                    else
                    {
                        unionTree = new Expression.Union {
                            Left = unionTree, Right = concatTree
                        };
                    }

                    concatTree = null;

                    continue;
                }
                else
                {
                    var term = ParseTerm();

                    if (concatTree == null)
                    {
                        concatTree = term;
                    }
                    else
                    {
                        concatTree = new Expression.Concat {
                            Left = concatTree, Right = term
                        };
                    }
                }
            }

            concatTree = concatTree ?? new Expression.Empty();

            if (unionTree == null)
            {
                return(concatTree);
            }

            unionTree = new Expression.Union {
                Left = unionTree, Right = concatTree
            };

            return(unionTree);
        }
コード例 #3
0
        private Expression ParseTerm()
        {
            Expression curTree = ParseUnstarredTerm();

            bool shouldContinue = true;

            while (_codeIndex < _code.Length)
            {
                switch (_code[_codeIndex])
                {
                case (byte)'*':
                    curTree = new Expression.Star {
                        Sub = curTree
                    };
                    break;

                case (byte)'+':
                    curTree = new Expression.Concat
                    {
                        Left  = curTree,
                        Right = new Expression.Star {
                            Sub = curTree
                        },
                    };
                    break;

                case (byte)'?':
                    curTree = new Expression.Union
                    {
                        Left  = new Expression.Empty(),
                        Right = curTree,
                    };
                    break;

                default:
                    shouldContinue = false;
                    break;
                }

                if (!shouldContinue)
                {
                    break;
                }

                _codeIndex++;
            }

            return(curTree);
        }