Example #1
0
        private void buildOrPiece(BuildState state, p_OrPiece orPiece)
        {
            var curState = state.nextGoodState++;

            state.PushGoodLocation("endOfOr" + curState);
            state.PushBadLocation("curBad" + curState);

            var itms = Helper.CombineArray(orPiece.RuleExpression1, orPiece.RuleExpressions).ToArray();
            int ind = 0;
            foreach (p_RuleExpression expression in itms)
            {
                var j = state.nextGoodState;
                state.PushBadLocation(string.Format("bottomPiece{0}", j));

                buildRuleExpression(state, expression);

                state.PopBadLocation();
                checkBuilder.AppendLine(string.Format("bottomPiece{0}:", j));

                if (ind++ == itms.Length-1)
                    checkBuilder.AppendLine("goto " + state.BadLocation() + ";");
                else
                    checkBuilder.AppendLine("goto nextPiece" + state.nextGoodState + ";");

            }
            state.PopBadLocation();
            state.PopGoodLocation();

            checkBuilder.AppendLine("curBad" + curState + ": goto " + state.BadLocation(state.nextGoodState) + ";");

            checkBuilder.AppendLine("endOfOr" + curState + ":");
            checkBuilder.AppendLine(string.Format("goto {0};", state.GoodLocation));
        }
Example #2
0
        private void buildOrPiece(BuildState state, p_OrPiece orPiece)
        {
            var curState = state.nextGoodState++;

            state.PushGoodLocation("endOfOr" + curState);
            state.PushBadLocation("curBad" + curState);

            var itms = Helper.CombineArray(orPiece.RuleExpression1, orPiece.RuleExpressions).ToArray();
            int ind  = 0;

            foreach (p_RuleExpression expression in itms)
            {
                var j = state.nextGoodState;
                state.PushBadLocation(string.Format("bottomPiece{0}", j));

                buildRuleExpression(state, expression);

                state.PopBadLocation();
                checkBuilder.AppendLine(string.Format("bottomPiece{0}:", j));

                if (ind++ == itms.Length - 1)
                {
                    checkBuilder.AppendLine("goto " + state.BadLocation() + ";");
                }
                else
                {
                    checkBuilder.AppendLine("goto nextPiece" + state.nextGoodState + ";");
                }
            }
            state.PopBadLocation();
            state.PopGoodLocation();

            checkBuilder.AppendLine("curBad" + curState + ": goto " + state.BadLocation(state.nextGoodState) + ";");



            checkBuilder.AppendLine("endOfOr" + curState + ":");
            checkBuilder.AppendLine(string.Format("goto {0};", state.GoodLocation));
        }
Example #3
0
        private void buildRuleExpression(BuildState state, p_RuleExpression ruleExpression)
        {
            foreach (var pRuleExpressionRulePiece in ruleExpression.rulePieces)
            {
                var myLoc = state.nextGoodState;
                checkBuilder.AppendLine("  nextPiece" + state.nextGoodState++ + ":");
                checkBuilder.AppendLine("symbolGenerator.PushState(); ");


                state.PushCurrentName(null);
                state.PushNotNeeded(false);

                state.PushBadLocation("nextPiece" + state.nextGoodState);

                if (pRuleExpressionRulePiece.HasNamePrefix)
                {
                    state.SetCurrentName(pRuleExpressionRulePiece.NamePrefix.name);
                }

                switch (pRuleExpressionRulePiece.suffix)
                {
                case p_RuleExpression_rulePiece_suffix.QuestionMark:
                    state.SetNotNeeded(true);

                    break;

                case p_RuleExpression_rulePiece_suffix.Multiply:
                    state.PushInLoop(true);

                    state.PushBadLocation("loopBad" + myLoc);

                    break;

                default:

                    break;
                }


                switch (pRuleExpressionRulePiece.rule.ruleType)
                {
                case p_RuleExpression_rulePiece_ruleType.OrPiece:
                    buildOrPiece(state, pRuleExpressionRulePiece.rule.OrPiece);
                    break;

                case p_RuleExpression_rulePiece_ruleType.String:
                    checkBuilder.AppendFormat(
                        @"

                                    if (checkSymbol(""{0}""))
                                    {{
                                        symbolGenerator.RestoreState();
                                        goto {1};
                                    }} else {{ 
                                        symbolGenerator.PopState();
                                        goto {2};
                                    }}
                  
                                ",
                        pRuleExpressionRulePiece.rule.String,
                        state.GoodLocation,
                        state.NotNeeded ? state.GoodLocation : state.BadLocation(state.nextGoodState));



                    break;

                case p_RuleExpression_rulePiece_ruleType.DecreaseTab:
                    break;

                case p_RuleExpression_rulePiece_ruleType.IncreaseTab:
                    break;

                case p_RuleExpression_rulePiece_ruleType.RulePiece:

                    checkBuilder.AppendFormat(
                        @"{{
                                    symbolGenerator.PushState();

                                    if (check{0}())
                                    {{
                                        symbolGenerator.RestoreState();
                                       goto  {1};
                                    }} else {{ 
                                        symbolGenerator.PopState();
                                       goto  {2};
                                    }} 
                                }}",
                        pRuleExpressionRulePiece.rule.String, state.GoodLocation,
                        state.NotNeeded ? state.GoodLocation : state.BadLocation(state.nextGoodState));


                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }


                if (pRuleExpressionRulePiece.suffix == p_RuleExpression_rulePiece_suffix.Multiply)
                {
                    state.PopBadLocation();

                    checkBuilder.AppendLine(string.Format(@"nextPiece{0}: 
                        symbolGenerator.RestoreState();
                        goto topOfLoop{1};", state.nextGoodState++, myLoc));

                    checkBuilder.AppendLine(string.Format(@"loopBad{0}: 
                        symbolGenerator.PopState();
                        goto {1};", myLoc++, state.BadLocation(state.nextGoodState)));

                    state.PopInLoop();
                }

                state.PopCurrentName();
                state.PopNotNeeded();
                state.PopBadLocation();
            }


            checkBuilder.AppendLine("nextPiece" + state.nextGoodState++ + ": goto " + state.BadLocation(state.nextGoodState) + ";");
        }
Example #4
0
        private void buildRuleExpression(BuildState state, p_RuleExpression ruleExpression)
        {
            foreach (var pRuleExpressionRulePiece in ruleExpression.rulePieces)
            {
                var myLoc = state.nextGoodState;
                checkBuilder.AppendLine("  nextPiece" + state.nextGoodState++ + ":");
                checkBuilder.AppendLine("symbolGenerator.PushState(); ");

                state.PushCurrentName(null);
                state.PushNotNeeded(false);

                state.PushBadLocation("nextPiece" + state.nextGoodState);

                if (pRuleExpressionRulePiece.HasNamePrefix)
                {
                    state.SetCurrentName(pRuleExpressionRulePiece.NamePrefix.name);
                }

                switch (pRuleExpressionRulePiece.suffix)
                {
                    case p_RuleExpression_rulePiece_suffix.QuestionMark:
                        state.SetNotNeeded(true);

                        break;
                    case p_RuleExpression_rulePiece_suffix.Multiply:
                        state.PushInLoop(true);

                        state.PushBadLocation("loopBad" + myLoc);

                        break;
                    default:

                        break;
                }

                switch (pRuleExpressionRulePiece.rule.ruleType)
                {
                    case p_RuleExpression_rulePiece_ruleType.OrPiece:
                        buildOrPiece(state, pRuleExpressionRulePiece.rule.OrPiece);
                        break;
                    case p_RuleExpression_rulePiece_ruleType.String:
                        checkBuilder.AppendFormat(
                            @"

                                    if (checkSymbol(""{0}""))
                                    {{
                                        symbolGenerator.RestoreState();
                                        goto {1};
                                    }} else {{
                                        symbolGenerator.PopState();
                                        goto {2};
                                    }}

                                ",
                            pRuleExpressionRulePiece.rule.String,
                            state.GoodLocation,
                            state.NotNeeded ? state.GoodLocation : state.BadLocation(state.nextGoodState));

                        break;
                    case p_RuleExpression_rulePiece_ruleType.DecreaseTab:
                        break;
                    case p_RuleExpression_rulePiece_ruleType.IncreaseTab:
                        break;
                    case p_RuleExpression_rulePiece_ruleType.RulePiece:

                        checkBuilder.AppendFormat(
                            @"{{
                                    symbolGenerator.PushState();

                                    if (check{0}())
                                    {{
                                        symbolGenerator.RestoreState();
                                       goto  {1};
                                    }} else {{
                                        symbolGenerator.PopState();
                                       goto  {2};
                                    }}
                                }}",
                            pRuleExpressionRulePiece.rule.String, state.GoodLocation,
                            state.NotNeeded ? state.GoodLocation : state.BadLocation(state.nextGoodState));

                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                if (pRuleExpressionRulePiece.suffix == p_RuleExpression_rulePiece_suffix.Multiply)
                {
                    state.PopBadLocation();

                    checkBuilder.AppendLine(string.Format(@"nextPiece{0}:
                        symbolGenerator.RestoreState();
                        goto topOfLoop{1};", state.nextGoodState++, myLoc));

                    checkBuilder.AppendLine(string.Format(@"loopBad{0}:
                        symbolGenerator.PopState();
                        goto {1};", myLoc++, state.BadLocation(state.nextGoodState)));

                    state.PopInLoop();
                }

                state.PopCurrentName();
                state.PopNotNeeded();
                state.PopBadLocation();
            }

                checkBuilder.AppendLine("nextPiece" + state.nextGoodState++ + ": goto " + state.BadLocation(state.nextGoodState) + ";");
        }