Пример #1
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) + ";");
        }
Пример #2
0
        private p_RuleExpression obtainRuleExpression()
        {
            p_RuleExpression ruleExpression = new p_RuleExpression();

            ruleExpression.rulePieces = new List<p_RuleExpression_rulePiece>();
            while (true)
            {

                p_RuleExpression_rulePiece piece = new p_RuleExpression_rulePiece();

                if (piece.HasNamePrefix = resetState(checkNamePrefix))
                {
                    piece.NamePrefix = obtainNamePrefix();
                }

                {

                    if (resetState(checkOrPiece))
                    {
                        piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.OrPiece, obtainOrPiece());
                        goto nextPiece1;
                    }
                }
                if (resetState(checkString))
                {
                    piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.String, obtainString());
                    goto nextPiece1;
                }

                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isIdentifier("tab"))
                    {
                        if (symbolGenerator.Advance().isSymbol("<"))
                        {
                            symbolGenerator.RestoreState();

                            piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.DecreaseTab);
                            goto nextPiece1;
                        }
                    }
                    symbolGenerator.PopState();
                }
                {
                    symbolGenerator.PushState();

                    if (symbolGenerator.Advance().isIdentifier("tab"))
                    {
                        if (symbolGenerator.Advance().isSymbol(">"))
                        {
                            symbolGenerator.RestoreState();
                            piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.IncreaseTab);
                            goto nextPiece1;
                        }
                    }
                    symbolGenerator.PopState();
                }
                if (resetState(checkIdentifier))
                {
                    piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.RulePiece, obtainIdentifier());
                    goto nextPiece1;
                }

                goto goodDone;

            nextPiece1:
                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isSymbol("?"))
                    {
                        symbolGenerator.RestoreState();
                        piece.suffix = p_RuleExpression_rulePiece_suffix.QuestionMark;
                    }
                    else
                        symbolGenerator.PopState();
                }
                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isSymbol("*"))
                    {
                        symbolGenerator.RestoreState();
                        piece.suffix = p_RuleExpression_rulePiece_suffix.Multiply;
                    }
                    else
                        symbolGenerator.PopState();
                }

                ruleExpression.rulePieces.Add(piece);
                continue;
            }
            goodDone:
            return ruleExpression;
        }
Пример #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) + ";");
        }
Пример #4
0
        private p_RuleExpression obtainRuleExpression()
        {
            p_RuleExpression ruleExpression = new p_RuleExpression();

            ruleExpression.rulePieces = new List <p_RuleExpression_rulePiece>();
            while (true)
            {
                p_RuleExpression_rulePiece piece = new p_RuleExpression_rulePiece();

                if (piece.HasNamePrefix = resetState(checkNamePrefix))
                {
                    piece.NamePrefix = obtainNamePrefix();
                }

                {
                    if (resetState(checkOrPiece))
                    {
                        piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.OrPiece, obtainOrPiece());
                        goto nextPiece1;
                    }
                }
                if (resetState(checkString))
                {
                    piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.String, obtainString());
                    goto nextPiece1;
                }


                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isIdentifier("tab"))
                    {
                        if (symbolGenerator.Advance().isSymbol("<"))
                        {
                            symbolGenerator.RestoreState();

                            piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.DecreaseTab);
                            goto nextPiece1;
                        }
                    }
                    symbolGenerator.PopState();
                }
                {
                    symbolGenerator.PushState();

                    if (symbolGenerator.Advance().isIdentifier("tab"))
                    {
                        if (symbolGenerator.Advance().isSymbol(">"))
                        {
                            symbolGenerator.RestoreState();
                            piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.IncreaseTab);
                            goto nextPiece1;
                        }
                    }
                    symbolGenerator.PopState();
                }
                if (resetState(checkIdentifier))
                {
                    piece.rule = new p_RuleExpression_rulePiece_rule(p_RuleExpression_rulePiece_ruleType.RulePiece, obtainIdentifier());
                    goto nextPiece1;
                }

                goto goodDone;

nextPiece1:
                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isSymbol("?"))
                    {
                        symbolGenerator.RestoreState();
                        piece.suffix = p_RuleExpression_rulePiece_suffix.QuestionMark;
                    }
                    else
                    {
                        symbolGenerator.PopState();
                    }
                }
                {
                    symbolGenerator.PushState();
                    if (symbolGenerator.Advance().isSymbol("*"))
                    {
                        symbolGenerator.RestoreState();
                        piece.suffix = p_RuleExpression_rulePiece_suffix.Multiply;
                    }
                    else
                    {
                        symbolGenerator.PopState();
                    }
                }

                ruleExpression.rulePieces.Add(piece);
                continue;
            }
goodDone:
            return(ruleExpression);
        }