Exemplo n.º 1
0
        public ActionExpression(string toParse, int index)
        {
            type = ExpressionType.DoNothing;
            next = null;
            ActionsReader.State s  = ActionsReader.State.Start;
            StringBuilder       sb = new StringBuilder();

            for (int i = index; i < toParse.Length; i++)
            {
                s = ActionsReader.NextState(s, toParse[i]);
                switch (s)
                {
                case ActionsReader.State.ReadPrint:
                    type = ExpressionType.Print;
                    next = new ActionExpression(toParse, i + 1);
                    goto loopEnd;

                case ActionsReader.State.ReadSet:
                    type = ExpressionType.Set;
                    break;

                case ActionsReader.State.ReadLet:
                    type = ExpressionType.Let;
                    break;

                case ActionsReader.State.ReadingFieldName:
                case ActionsReader.State.ReadingFieldValue:
                case ActionsReader.State.ReadingVarName:
                case ActionsReader.State.ReadingVarValue:
                    sb.Append(toParse[i]);
                    break;

                case ActionsReader.State.ReadFieldName:
                case ActionsReader.State.ReadVarName:
                    fieldName = sb.ToString();
                    sb        = new StringBuilder();
                    break;

                case ActionsReader.State.ReadFieldValue:
                case ActionsReader.State.ReadVarValue:
                    fieldValue = sb.ToString();
                    next       = new ActionExpression(toParse, i + 1);
                    goto loopEnd;
                }
            }
            loopEnd :;
        }
Exemplo n.º 2
0
        public Program(string programSource)
        {
            string queryString = "", tAction = "", fAction = "";

            ProgramReader.State s  = ProgramReader.State.Start;
            StringBuilder       sb = null;

            foreach (char c in programSource)
            {
                s = ProgramReader.NextState(s, c);
                switch (s)
                {
                case ProgramReader.State.StartQueryRead:
                case ProgramReader.State.StartTActionRead:
                case ProgramReader.State.StartFActionRead:
                    sb = new StringBuilder();
                    break;

                case ProgramReader.State.ReadingQuery:
                case ProgramReader.State.ReadingTAction:
                case ProgramReader.State.ReadingFAction:
                    sb.Append(c);
                    break;

                case ProgramReader.State.ReadQuery:
                    queryString = sb.ToString();
                    break;

                case ProgramReader.State.ReadTAction:
                    tAction = sb.ToString();
                    break;

                case ProgramReader.State.ReadFAction:
                    fAction = sb.ToString();
                    break;

                case ProgramReader.State.InvalidSyntax:
                    throw new Exception("Invalid Syntax!");
                }
            }
            query       = new Expression(queryString.Trim());
            trueAction  = new ActionExpression(tAction.Trim(), 0);
            falseAction = new ActionExpression(fAction.Trim(), 0);
        }