Beispiel #1
0
        private string GenerateSequentialExpression(Expression expression)
        {
            SequentialExpression sequence = expression as SequentialExpression;

            return(this.GenerateExpression(sequence.AtomicExpression) + " " +
                   this.GenerateExpression(sequence.NonAlternativesExpression));
        }
Beispiel #2
0
        private ParseAction ImportSequentialExpression(Expression exp,
                                                       Entity entity,
                                                       ParseAction parent = null,
                                                       bool optional      = false)
        {
            SequentialExpression sequence = ((SequentialExpression)exp);

            ConsumeAll consume = new ConsumeAll()
            {
                Parent = parent
            };

            // SequentialExpression is constructed recusively, unroll it...
            while (true)
            {
                // add first part
                consume.Actions.Add(this.ImportPropertiesAndParseActions(
                                        sequence.AtomicExpression, entity, consume, optional
                                        ));
                // add remaining parts
                if (sequence.NonAlternativesExpression is AtomicExpression)
                {
                    // last part
                    consume.Actions.Add(this.ImportPropertiesAndParseActions(
                                            sequence.NonAlternativesExpression, entity, consume, optional
                                            ));
                    break;
                }
                else
                {
                    // recurse
                    sequence = (SequentialExpression)sequence.NonAlternativesExpression;
                }
            }
            return(consume);
        }
Beispiel #3
0
 /// <summary>
 ///     根据给定的字符串,创建一个计算器结构。
 /// </summary>
 /// <param name="expression_string">要转化为计算器的字符串</param>
 /// <returns>字符串对应的就计算器结构</returns>
 public static CalculatorMachine GetCalculatorMachine(string expression_string)
 {
     return(SequentialExpression.FromString(expression_string).ToPreorderExpression().ToCalculateMachine());
 }