/// <summary>
 /// Parse string to syntax tree
 /// </summary>
 /// Parses the input string into a Penn Treebank syntax tree
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='input'>
 /// Input string
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PostOKResponse> PostAsync(this IParseString operations, string input, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostWithHttpMessagesAsync(input, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #2
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (!ps.HasChar())
            {
                if (context.GetCurrentConj() != null)
                {
                    ChangeState(new AddConjunctionState(GetParent()));
                    return;
                }
                else if (context.GetRoot() == null)
                {
                    GetParent().SetError("Unexpected } of line at position" + ps.GetPosition().ToString());
                    ChangeState(new ErrorState(GetParent()));
                }
                return;
            }
            switch (ps.GetChar())
            {
            case 'X':
                ChangeState(new StartTermState(GetParent()));
                break;

            case '+':
                if (context.GetCurrentConj() != null)
                {
                    ChangeState(new AddConjunctionState(GetParent()));
                    return;
                }
                else
                {
                    GetParent().SetError("Unexpected char position " + ps.GetPosition().ToString());
                    ChangeState(new ErrorState(GetParent()));
                }
                break;

            case '(':
                ChangeState(new StartExprState(GetParent()));
                break;

            case ')':
                ChangeState(new EndExprState(GetParent()));
                break;

            default:
                GetParent().SetError("Unexpected char at position " + (ps.GetPosition() - 1).ToString());
                ChangeState(new ErrorState(GetParent()));
                break;
            }
        }
コード例 #3
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (ps.HasChar())
            {
                if (Char.IsDigit(ps.PeekChar()))
                {
                    ps.CollectTerm();
                    ChangeState(new CollectTermState(GetParent()));
                    return;
                }
            }
            ChangeState(new AddTermState(GetParent()));
        }
コード例 #4
0
ファイル: FindOperationState.cs プロジェクト: IrinaLen/SAT
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (ps.HasChar())
            {
                switch (ps.GetChar())
                {
                case 'X':
                    ChangeState(new StartTermState(GetParent()));
                    break;

                case '+':
                    if (!ps.HasChar() || ps.PeekChar() != 'X' && ps.PeekChar() != '(')
                    {
                        GetParent().SetError("second term isn't found at position " + ps.GetPosition().ToString());
                        ChangeState(new ErrorState(GetParent()));
                    }
                    else
                    {
                        ChangeState(new AddConjunctionState(GetParent()));
                    }
                    break;

                case '(':
                    ChangeState(new StartExprState(GetParent()));
                    break;

                case ')':
                    ChangeState(new EndExprState(GetParent()));
                    break;

                default:

                    GetParent().SetError("Unexpected char at position " + (ps.GetPosition() - 1).ToString());
                    ChangeState(new ErrorState(GetParent()));
                    break;
                }
            }
            else
            {
                ChangeState(new AddConjunctionState(GetParent()));
            }
        }
コード例 #5
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (context.GetRoot() != null)
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(new Tree.OrNode((Tree.Node)context.GetRoot(), (Tree.Node)context.GetCurrentConj()));
                }
            }
            else
            {
                context.SetRoot(context.GetCurrentConj());
            }
            context.SetCurrentConj(null);
            if (ps.HasChar())
            {
                ChangeState(new InitState(GetParent()));
            }
        }
コード例 #6
0
ファイル: AddTermState.cs プロジェクト: IrinaLen/SAT
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();
            Tree         v  = new Tree(ps.GetVarNum());

            if (ps.HasChar() && ps.PeekChar() == '"')
            {
                ps.GetChar();
                v.AddNot();
            }
            if (context.GetCurrentConj() == null)
            {
                context.SetCurrentConj(v.ReturnRoot());
            }
            else
            {
                context.SetCurrentConj(new Tree.AndNode((Tree.Node)context.GetCurrentConj(),
                                                        (Tree.Node)v.ReturnRoot()));
            }
            ps.ClearTerm();
            ChangeState(new FindOperationState(GetParent()));
        }
コード例 #7
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (!ps.HasChar())
            {
                GetParent().SetError("Missed number of variable at } of expression'");
                ChangeState(new ErrorState(GetParent()));
                return;
            }
            if (Char.IsDigit(ps.PeekChar()))
            {
                ps.ClearTerm();
                ps.CollectTerm();
                ChangeState(new CollectTermState(GetParent()));
            }
            else
            {
                GetParent().SetError("Unexpected char at position " + ps.GetPosition().ToString());
                ChangeState(new ErrorState(GetParent()));
            }
        }
コード例 #8
0
        public override void ProcessState(IStateContext context)
        {
            IParseString  ps         = context.GetParseString();
            IStateContext oldcontext = context.GetPrevousContext();

            if (oldcontext == null)
            {
                GetParent().SetError("Unexpected closing parenthesis at pos  " + (ps.GetPosition() - 1).ToString());
                ChangeState(new ErrorState(GetParent()));
                return;
            }
            if (context.GetRoot() == null)
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(context.GetCurrentConj()); // êîíåö êîíúþíêöèè
                }
                else
                {
                    GetParent()
                    .SetError("Empty expression between parenthesis at pos " + ((ps.GetPosition() - 1).ToString()));
                    ChangeState(new ErrorState(GetParent()));
                    return;
                }
            }
            else
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(
                        new Tree.OrNode((Tree.Node)context.GetRoot(), (Tree.Node)context.GetCurrentConj()));
                }
            }
            context.SetCurrentConj(null);
            if (ps.HasChar() && ps.PeekChar() == '"')
            {
                ps.GetChar();
                if (context.GetRoot() != null)
                {
                    context.SetRoot(new Tree.NotNode((Tree.Node)context.GetRoot()));
                }
            }
            if (oldcontext.GetCurrentConj() != null)
            {
                oldcontext.SetCurrentConj(new Tree.AndNode((Tree.Node)oldcontext.GetCurrentConj(),
                                                           (Tree.Node)context.GetRoot()));
            }
            else
            {
                oldcontext.SetCurrentConj(context.GetRoot());
            }

            GetParent().ChangeContext(oldcontext);
            if (!ps.HasChar() && oldcontext.GetPrevousContext() != null)
            {
                GetParent().SetError("Not found close bracket at pos " + ((ps.GetPosition() - 1).ToString()));
                ChangeState(new ErrorState(GetParent()));
            }
            else
            {
                ChangeState(new InitState(GetParent()));
            }
        }
 /// <summary>
 /// Parse string to syntax tree
 /// </summary>
 /// Parses the input string into a Penn Treebank syntax tree
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='input'>
 /// Input string
 /// </param>
 public static PostOKResponse Post(this IParseString operations, string input)
 {
     return(Task.Factory.StartNew(s => ((IParseString)s).PostAsync(input), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
コード例 #10
0
 public StateContext(IParseString parseStr, IStateContext prev)
 {
     _parseStr    = parseStr;
     _prevContext = prev;
 }