public static GATNode _declaration(this LL1Processor ll1) { var node = new GATNode(); var offset = 2; // node.name = "global"; CodeGenerator.AddLabel("global", 0); // switch (WordContainer.GetWordType(offset)) { case WordType.SEMICOLON: { var varDeclaration = ll1._varDeclaration(); node.AddChild(varDeclaration); node.generator = Declaration1; break; } case WordType.BRACKET_L: { var funDeclaration = ll1._funDeclaration(); node.AddChild(funDeclaration); node.generator = Declaration2; break; } default: { throw new BNFException(); } } return(node); }
public static GATNode _localDeclarations(this LL1Processor ll1) { var node = new GATNode(); var offset = 1; var next = WordContainer.GetWordType(offset); while (next == WordType.ID) { var varDeclaration = ll1._varDeclaration(); node.AddChild(varDeclaration); next = WordContainer.GetWordType(offset); } if (node.ChildCount() == 0) { node.generator = LocalDeclarations2; } else { node.generator = LocalDeclarations1; } return(node); }
public static GATNode _typeSpecifier(this LL1Processor ll1) { var node = new GATNode(); var next = WordContainer.GetWordType(); switch (next) { case WordType.INT: { var INT = WordContainer.Advance(); node.AddChild(INT); node.generator = typeSpecifier1; break; } case WordType.VOID: { var VOID = WordContainer.Advance(); node.AddChild(VOID); node.generator = typeSpecifier2; break; } default: { throw new BNFException(); } } return node; }
public static GATNode _selectionStmt(this LL1Processor ll1) { var node = new GATNode(); node.generator = SelectionStmt; WordContainer.Advance(WordType.IF); WordContainer.Advance(WordType.BRACKET_L); var expression = ll1._expression(); WordContainer.Advance(WordType.BRACKET_R); var statement = ll1._statement(); node.AddChild(expression); //0 node.AddChild(GATNode.CodeNode()); //1 node.AddChild(statement); //2 var next = WordContainer.GetWordType(); if (next == WordType.ELSE) { WordContainer.Advance(WordType.ELSE); var elseStatement = ll1._statement(); node.AddChild(GATNode.CodeNode()); //3 node.AddChild(GATNode.LabelNode()); //4 node.AddChild(elseStatement); //5 } node.AddChild(GATNode.LabelNode()); //3-6 return(node); }
public void SetCurrentContainer(WordContainer container) { if (selectedContainer != null) { selectedContainer.ClearSelection(); } selectedContainer = container; }
public void GenerateWords() { ClearWords(); for (int i = 0; i < numberToGenerate; i++) { int rand = Random.Range(0, Words.Count); WordContainer container = Instantiate(Words[rand], this.transform).GetComponent <WordContainer>(); } }
// Use this for initialization void Start() { wordsListed = new List <wordOutput>(); firstSpawn(); GridScript.scoreVisual = scoreOutput; GridScript.scoreText = scoreOutput.GetComponent <Text>(); levelOutput.GetComponent <Text>().text = level.ToString(); wordCollection = WordContainer.Load(Path.Combine(Application.dataPath, "Resources/WordList.xml")); newWord(); }
public static GATNode _statement(this LL1Processor ll1) { var node = new GATNode(); var next = WordContainer.GetWordType(); if (ExpressionStmtProc.first.Contains(next)) { var expressionStmt = ll1._expressionStmt(); node.AddChild(expressionStmt); node.generator = Statement1; return(node); } var offset = 0; switch (WordContainer.GetWordType(offset)) { case WordType.BRACE_L: { var compoundStmt = ll1._compoundStmt(); node.AddChild(compoundStmt); node.generator = Statement2; break; } case WordType.IF: { var selectionStmt = ll1._selectionStmt(); node.AddChild(selectionStmt); node.generator = Statement3; break; } case WordType.WHILE: { var iterationStmt = ll1._iterationStmt(); node.AddChild(iterationStmt); node.generator = Statement4; break; } case WordType.RETURN: { var returnStmt = ll1._returnStmt(); node.AddChild(returnStmt); node.generator = Statement5; break; } default: { throw new BNFException(); } } return(node); }
private void GenerateWords(IDictionaryRequest request, PartitionInfo partitionInfo) { var partitionedWords = new ConcurrentQueue <IDictionary <int, IGeneratedWord> >(); var useNoise = dictionaryConfiguration.UseNoise; var startTime = DateTime.Now; maxValue = dictionary.WordList.Count; FireGenerateChanged(new ProgressChangedEventArgs(10, String.Empty)); // Multi-Threaded block var tasks = new Task[partitionInfo.NumberOfPartitions]; var index = 0; for (; index < partitionInfo.NumberOfPartitions; index++) { tasks[index] = Task.Run(() => { var iterations = index == partitionInfo.NumberOfPartitions - 1 ? partitionInfo.LastPartitionSize : partitionInfo.FullPartitionSize; var wordsPartition = useNoise ? GeneratePartitionedWordsWithNoise(iterations) : GeneratePartitionedWords(iterations); partitionedWords.Enqueue(wordsPartition); }); } try { Task.WaitAll(tasks); var words = new WordContainer(dictionaryConfiguration.UseNoise) { PartitionedWords = partitionedWords }; var endTime = DateTime.Now; var duration = endTime - startTime; var result = new DictionaryResult(request, duration, words) { Words = words }; FireGenerateChanged(new ProgressChangedEventArgs(100, null)); FireGenerateCompleted(new DictionaryEventArgs(null, false, null, result)); } catch (AggregateException ae) { FireGenerateCompleted(new DictionaryEventArgs(ae.Flatten(), false, ae, null)); } }
public static GATNode _program(this LL1Processor ll1) { var node = new GATNode(); node.generator = program; var declarationList = ll1._declarationList(); node.AddChild(GATNode.CodeNode()); //0 node.AddChild(declarationList); //1 WordContainer.Advance(WordType.HASHTAG); return(node); }
public static GATNode _factor(this LL1Processor ll1) { var node = new GATNode(); var offset = 0; switch (WordContainer.GetWordType(offset)) { case WordType.BRACKET_L: { WordContainer.Advance(WordType.BRACKET_L); var expression = ll1._expression(); node.AddChild(expression); node.generator = Factor1; WordContainer.Advance(WordType.BRACKET_R); break; } case WordType.ID: { offset = 1; if (WordContainer.GetWordType(offset) == WordType.BRACKET_L) { var CALL = ll1._call(); node.AddChild(CALL); node.generator = Factor2; } else { var VAR = ll1._var(); node.AddChild(VAR); node.generator = Factor3; } break; } case WordType.NUM: { var num = WordContainer.Advance(WordType.NUM); node.AddChild(num); node.generator = Factor4; break; } default: { throw new BNFException(); } } return(node); }
public static GATNode _call(this LL1Processor ll1) { var node = new GATNode(); node.generator = Call; var id = WordContainer.Advance(WordType.ID); node.AddChild(id);//0 WordContainer.Advance(WordType.BRACKET_L); var args = ll1._args(); node.AddChild(args);//1 WordContainer.Advance(WordType.BRACKET_R); return(node); }
public static GATNode _returnStmt(this LL1Processor ll1) { var node = new GATNode(); node.generator = ReturnStmt; WordContainer.Advance(WordType.RETURN); var next = WordContainer.GetWordType(); if (ExpressionProc.first.Contains(next)) { var expression = ll1._expression(); node.AddChild(expression); } WordContainer.Advance(WordType.SEMICOLON); return(node); }
public static GATNode _compoundStmt(this LL1Processor ll1) { var node = new GATNode(); node.generator = CompoundStmt; WordContainer.Advance(WordType.BRACE_L); var localDeclarations = ll1._localDeclarations(); var statementList = ll1._statementList(); WordContainer.Advance(WordType.BRACE_R); node.AddChild(localDeclarations); node.AddChild(statementList); return(node); }
public static GATNode _statementList(this LL1Processor ll1) { var node = new GATNode(); node.generator = StatmentList; var next = WordContainer.GetWordType(); while (StatementProc.first.Contains(next)) { var statement = ll1._statement(); node.AddChild(statement); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _params(this LL1Processor ll1) { var node = new GATNode(); var offset = 1; if (WordContainer.GetWordType(offset) == WordType.BRACKET_R) { WordContainer.Advance(WordType.VOID); } else { var paramList = ll1._paramList(); node.AddChild(paramList); node.generator = Params; } return(node); }
public static GATNode _declarationList(this LL1Processor ll1) { var node = new GATNode(); node.generator = DeclarationList; var declaration = ll1._declaration(); node.AddChild(declaration); var next = WordContainer.GetWordType(); while (DeclarationProc.first.Contains(next)) { declaration = ll1._declaration(); node.AddChild(declaration); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _var(this LL1Processor ll1) { var node = new GATNode(); node.generator = Var; var id = WordContainer.Advance(WordType.ID); node.AddChild(id); var next = WordContainer.GetWordType(); if (next == WordType.SQUARE_BRACKET_L) { WordContainer.Advance(WordType.SQUARE_BRACKET_L); var expression = ll1._expression(); node.AddChild(expression); WordContainer.Advance(WordType.SQUARE_BRACKET_R); } return(node); }
public static GATNode _iterationStmt(this LL1Processor ll1) { var node = new GATNode(); node.generator = IterationStmt; WordContainer.Advance(WordType.WHILE); WordContainer.Advance(WordType.BRACKET_L); node.AddChild(GATNode.LabelNode());//0 var expression = ll1._expression(); node.AddChild(expression); //1 node.AddChild(GATNode.CodeNode()); //2 WordContainer.Advance(WordType.BRACKET_R); var statement = ll1._statement(); node.AddChild(statement); //3 node.AddChild(GATNode.CodeNode()); //4 node.AddChild(GATNode.LabelNode()); //5 return(node); }
public static GATNode _argList(this LL1Processor ll1) { var node = new GATNode(); node.generator = ArgList; var expression1 = ll1._expression(); node.AddChild(expression1); var next = WordContainer.GetWordType(); while (next == WordType.COMMA) { WordContainer.Advance(WordType.COMMA); var expression2 = ll1._expression(); node.AddChild(expression2); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _simpleExpression(this LL1Processor ll1) { var node = new GATNode(); node.generator = SimpleExpression; var additiveExpression1 = ll1._additiveExpression(); node.AddChild(additiveExpression1); var next = WordContainer.GetWordType(); while (next == WordType.RELOP) { var relop = WordContainer.Advance(WordType.RELOP); node.AddChild(relop); var additiveExpression2 = ll1._additiveExpression(); node.AddChild(additiveExpression2); next = WordContainer.GetWordType(); } return(node); }
private static void CommandsInit(List <ICustomCommand> commands, IAppSettings appSettings) { IOutput outPut = new ConsoleOutput(); ICoder coder = new AesCoder(); IWordContainer wordContainer = new WordContainer(); IFileAction fileActions = new CommonFileAction(); commands.Add(new HelpCommand(outPut, commands)); commands.Add(new AddCommand(wordContainer, coder, appSettings)); //commands.Add(new FileDecoderCommand(outPut, wordContainer, coder, appSettings)); commands.Add(new FileLoaderCommand(wordContainer, fileActions, coder, appSettings)); commands.Add(new RemoveCommand(outPut, wordContainer)); commands.Add(new SaveCommand(wordContainer, coder, appSettings, fileActions)); commands.Add(new LoginCommand(appSettings)); commands.Add(new ShowCommand(outPut, wordContainer)); commands.Add(new GetCommand(outPut, wordContainer, coder, appSettings)); commands.Add(new ClearCommand(outPut, wordContainer, appSettings)); commands.Add(new FastDecoderCommand(outPut, coder)); commands.Add(new FastEncoderCommand(outPut, coder)); }
public static GATNode _term(this LL1Processor ll1) { var node = new GATNode(); node.generator = Term; var factor1 = ll1._factor(); node.AddChild(factor1); var next = WordContainer.GetWordType(); while (next == WordType.MULOP) { var mulop = WordContainer.Advance(WordType.MULOP); node.AddChild(mulop); var factor2 = ll1._factor(); node.AddChild(factor2); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _additiveExpression(this LL1Processor ll1) { var node = new GATNode(); node.generator = AdditiveExpression; var term1 = ll1._term(); node.AddChild(term1); var next = WordContainer.GetWordType(); while (next == WordType.ADDOP) { var addop = WordContainer.Advance(WordType.ADDOP); node.AddChild(addop); var term2 = ll1._term(); node.AddChild(term2); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _args(this LL1Processor ll1) { var node = new GATNode(); var next = WordContainer.GetWordType(); if (ArgListProc.first.Contains(next)) { var argList = ll1._argList(); node.AddChild(argList); } if (node.ChildCount() == 0) { node.generator = Args2; } else { node.generator = Args1; } return(node); }
public static GATNode _param(this LL1Processor ll1) { var node = new GATNode(); node.generator = Param; var typeSpecifier = ll1._typeSpecifier(); var id = WordContainer.Advance(WordType.ID); node.AddChild(typeSpecifier); node.AddChild(id); var next = WordContainer.GetWordType(); if (next == WordType.SQUARE_BRACKET_L) { WordContainer.Advance(WordType.SQUARE_BRACKET_L); //TODO:也许要对数组特别处理 WordContainer.Advance(WordType.SQUARE_BRACKET_R); } return(node); }
public static GATNode _varDeclaration(this LL1Processor ll1) { var node = new GATNode(); node.generator = varDeclaration; var typeSpecifier = ll1._typeSpecifier(); var id = WordContainer.Advance(WordType.ID); node.AddChild(typeSpecifier); node.AddChild(id); if (WordContainer.GetWordType() == WordType.SQUARE_BRACKET_L) { WordContainer.Advance(WordType.SQUARE_BRACKET_L); var num = WordContainer.Advance(WordType.NUM); WordContainer.Advance(WordType.SQUARE_BRACKET_R); node.AddChild(num); } WordContainer.Advance(WordType.SEMICOLON); return(node); }
public static GATNode _paramList(this LL1Processor ll1) { var node = new GATNode(); node.generator = ParamList; var param = ll1._param(); node.AddChild(param); var next = WordContainer.GetWordType(); while (next == WordType.COMMA) { WordContainer.Advance(WordType.COMMA); param = ll1._param(); node.AddChild(param); next = WordContainer.GetWordType(); } return(node); }
public static GATNode _funDeclaration(this LL1Processor ll1) { var node = new GATNode(); var typeSpecifier = ll1._typeSpecifier(); var id = WordContainer.Advance(WordType.ID); WordContainer.Advance(WordType.BRACKET_L); var param = ll1._params(); WordContainer.Advance(WordType.BRACKET_R); var compoundStmt = ll1._compoundStmt(); // node.name = id.value; // node.generator = FunDeclaration; node.AddChild(typeSpecifier); //0 node.AddChild(id); //1 node.AddChild(param); //2 node.AddChild(GATNode.LabelNode()); //3 node.AddChild(compoundStmt); //4 return(node); }
static void Main(string[] args) { var output = Processor.WordAnalyse(FileManager.ReadFile("test.txt")); string midString = string.Empty; int index = 0; foreach (var v in output) { midString += v.ToString() + '\n'; Console.WriteLine($"{index++} : {v.ToString()}"); } FileManager.WriteFile("midString.txt", midString); WordContainer.InjectData(output); //Console.WriteLine(); //Console.Write(WordContainer.GetString()); var ll1 = new LL1Processor(); ll1.StartProcess(); ll1.StartGenerate(); Console.Write(CodeGenerator.CodeToString()); Console.Write(CodeGenerator.SymbolToString()); Console.Write(CodeGenerator.LabelToString()); /* * FileManager.WriteFile("ttttttt.json", JsonConvert.SerializeObject(new Anony{ * data = "aaaa\\\"aaaa" * })); * Anony obj = JsonConvert.DeserializeObject<Anony>(FileManager.ReadFile("ttttttt.json")); * * Console.WriteLine(obj.data); */ }
// Use this for initialization void Start() { wordsListed = new List<wordOutput>(); firstSpawn(); GridScript.scoreVisual = scoreOutput; GridScript.scoreText = scoreOutput.GetComponent<Text>(); levelOutput.GetComponent<Text>().text = level.ToString(); wordCollection = WordContainer.Load(Path.Combine(Application.dataPath, "Resources/Clean Dictionary.xml")); newWord(); }