private static void _GetLevel(Level result, SyntaxTree <EnumTokenTypeLevelCompiler, EnumVTypeLevelCompiler, TreeNodeValueLevelCompiler> syntaxTree) { if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_Level___tail_levelLeave()) { GetTankList(result, syntaxTree.Children[2]); } }
static void Main(string[] args) { var sourceCodes = new string[] { @" level { tank{1 2} | tank{3 4} } " }; foreach (var sourceCode in sourceCodes) { var lex = new LexicalAnalyzerLevelCompiler(); lex.SetSourceCode(sourceCode); var tokens = lex.Analyze(); Console.WriteLine(tokens); var parser = new LL1SyntaxParserLevelCompiler(); parser.SetTokenListSource(tokens); var tree = parser.Parse(); Console.WriteLine(tree); var value = tree.GetValue(); Console.WriteLine(value); } }
private static int GetTankPrefab(SyntaxTree <EnumTokenTypeLevelCompiler, EnumVTypeLevelCompiler, TreeNodeValueLevelCompiler> syntaxTree) { if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_TankPrefab___numberLeave()) { var result = int.Parse(syntaxTree.Children[0].NodeValue.NodeName); return(result); } return(0); }
private static void GetTankList(Level level, SyntaxTree <EnumTokenTypeLevelCompiler, EnumVTypeLevelCompiler, TreeNodeValueLevelCompiler> syntaxTree) { if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_TankList___tail_tankLeave() || syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_TankList___tail_or_Leave()) { var egg = GetTank(syntaxTree.Children[0]); level.Add(egg); GetTankList(level, syntaxTree.Children[1]); } else if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_TankList___tail_rightBrace_Leave()) { //nothing to do } }
private static TankEgg GetTank(SyntaxTree <EnumTokenTypeLevelCompiler, EnumVTypeLevelCompiler, TreeNodeValueLevelCompiler> syntaxTree) { if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_Tank___tail_tankLeave()) { var tankPrefab = GetTankPrefab(syntaxTree.Children[2]); var bornPoint = GetBornPoint(syntaxTree.Children[3]); var result = new TankEgg(tankPrefab, bornPoint); return(result); } else if (syntaxTree.CandidateFunc == LL1SyntaxParserLevelCompiler.GetFuncParsecase_Tank___tail_or_Leave()) { var result = new TankEgg(-1, -1); return(result); } return(null); }
public static Level[] LoadLevels(string[] levels) { if (levels == null) { levels = LevelLoader.levelsSourceCode; } var result = new Level[levels.Length]; for (int i = 0; i < result.Length; i++) { var lexi = new LexicalAnalyzerLevelCompiler(levels[i]); var tokens = lexi.Analyze(); var parser = new LL1SyntaxParserLevelCompiler(tokens); var tree = parser.Parse(); var value = tree.GetValue(); result[i] = value; } return(result); }