private static void Assignment() { Grammar.Add(new GrammarReplaceRule(TokenEnum.UnlabeledStatement, new CompositeToken { TokenEnum.Id(), TokenEnum.String("="), TokenEnum.Expression1 })); }
private static void Loop() { Grammar.Add(new GrammarReplaceRule(TokenEnum.UnlabeledStatement, new CompositeToken { TokenEnum.String("do"), TokenEnum.Id(), TokenEnum.String("="), TokenEnum.Expression1, TokenEnum.String("to"), TokenEnum.Expression2, TokenEnum.StatementList1, TokenEnum.String("next") })); }
private static void IdList() { Grammar.Add(new GrammarReplaceRule(TokenEnum.IdList1, new CompositeToken { TokenEnum.IdList })); Grammar.Add(new GrammarReplaceRule(TokenEnum.IdList, new CompositeToken { TokenEnum.String(","), TokenEnum.Id() })); Grammar.Add(new GrammarReplaceRule(TokenEnum.IdList, new CompositeToken { TokenEnum.IdList, TokenEnum.String(","), TokenEnum.Id() })); Grammar.Add(new GrammarReplaceRule(TokenEnum.ProgramName, new CompositeToken { TokenEnum.String("program"), TokenEnum.Id() })); }
private static void FillExpression() { Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression, new CompositeToken { TokenEnum.Term1 })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression1, new CompositeToken { TokenEnum.Expression })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression2, new CompositeToken { TokenEnum.Expression1 })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression, new CompositeToken { TokenEnum.Expression, TokenEnum.String("+"), TokenEnum.Term1 }) { OnReplaceAction = (stack, list) => list.Add(new StringToken("+")) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression, new CompositeToken { TokenEnum.Expression, TokenEnum.String("-"), TokenEnum.Term1 }) { OnReplaceAction = (stack, list) => list.Add(new StringToken("-")) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Expression, new CompositeToken { TokenEnum.String("-"), TokenEnum.Term1 }) { OnReplaceAction = (stack, list) => list.Add(new StringToken("@")) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Term1, new CompositeToken { TokenEnum.Term })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Term, new CompositeToken { TokenEnum.Mult })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Term, new CompositeToken { TokenEnum.Term, TokenEnum.String("*"), TokenEnum.Mult }) { OnReplaceAction = (stack, list) => list.Add(new StringToken("*")) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Term, new CompositeToken { TokenEnum.Term, TokenEnum.String("/"), TokenEnum.Mult }) { OnReplaceAction = (stack, list) => list.Add(new StringToken("/")) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Mult, new CompositeToken { TokenEnum.String("("), TokenEnum.Expression1, TokenEnum.String(")") })); Grammar.Add(new GrammarReplaceRule(TokenEnum.Mult, new CompositeToken { TokenEnum.Id() }) { OnReplaceAction = (popped, list) => list.Add(popped.Last()) }); Grammar.Add(new GrammarReplaceRule(TokenEnum.Mult, new CompositeToken { TokenEnum.Const() }) { OnReplaceAction = (popped, list) => list.Add(popped.Last()) }); }