public void Convert_ExpressionWithSeveralReturns_CorrectPolis() { var syntacticalAnalyzer = new SyntacticalAnalyzer(); var program = new TestProgramBuilder() .WithTokens(TestSourceKey.SeveralReturnsWithFirstWorking) .WithPolis(TestSourceKey.SeveralReturnsWithFirstWorking) .Build(); var actual = syntacticalAnalyzer.Convert(program.Tokens); Assert.AreEqual(program.Polis, actual); Assert.AreEqual(program.PolisConditionIndexes, syntacticalAnalyzer.PolisConditionsIndexes); }
public void Convert_ExpressionWithCycleWhileInCondition_CorrectPolis() { var syntacticalAnalyzer = new SyntacticalAnalyzer(); var program = new TestProgramBuilder() .WithTokens(TestSourceKey.CycleWhileInCondition) .WithPolis(TestSourceKey.CycleWhileInCondition) .Build(); var actual = syntacticalAnalyzer.Convert(program.Tokens); Assert.AreEqual(program.Polis, actual); Assert.AreEqual(program.PolisConditionIndexes, syntacticalAnalyzer.PolisConditionsIndexes); }
private async void AnalyzeCode(bool debugMode) { tbConsole.Text = "Preparando...\n"; // Reset analyze controls analyzeStopped = false; analyzeResumed = false; analyzePaused = false; // Enable stop button stopDebugButton.Visible = true; stopDebugButton.Enabled = true; // Initialize tokens data table DataTable tokensDataTable = CreateTokensDataTable(); dgTokens.DataSource = tokensDataTable; // Get text to lexical analysis string[] textToAnalyze = ConvertSourceCodeLinesToArray(sourceCode.Lines); try { // LEXICAL ANALISIS tbConsole.AppendText("Executando análise léxica...\n"); // Initialize lexical analyzer LexicalAnalyzer lexicalAnalyzer = new LexicalAnalyzer(textToAnalyze); IList <Token> extractedTokens = lexicalAnalyzer.Start(); if (debugMode) { // Enable debug control buttons resumeDebugButton.Visible = true; resumeDebugButton.Enabled = true; continueDebugButton.Visible = true; continueDebugButton.Enabled = true; // Add extracted tokens to data table _ = Task.Run(() => { AddExtractedTokensToDataTable(tokensDataTable, extractedTokens); }); } tbConsole.AppendText("Análise léxica concluída\n"); // SYNTACTICAL ANALISIS tbConsole.AppendText("Executando análise sintática/semântica...\n"); SyntacticalAnalyzer syntacticalAnalyzer = new SyntacticalAnalyzer(extractedTokens); foreach (SyntacticalAnalysisProcessing processing in syntacticalAnalyzer.Start()) { if (debugMode && processing.RemovedToken != null && tokensDataTable.Rows.Count > 0) { tokensDataTable.Rows.RemoveAt(0); } // Stop analyze if (analyzeStopped) { StopAnalyze(); return; } // Controls debug mode if (debugMode) { // Set expansions to analyzer data source dgAnalyzer.DataSource = processing.ExpansionStack.ToList(); if (!analyzeResumed) { // Select last processed line SelectLine(processing.LineNumber); } // Wait until continue debug action while (analyzePaused) { if (analyzeStopped) { StopAnalyze(); return; } await Task.Delay(250); } if (!analyzeResumed) { analyzePaused = true; } else { await Task.Delay(10); } } } tbConsole.AppendText("Análise sintática/semântica concluída\n"); MessageBox.Show("Finalizado com sucesso"); } catch (LexicalException error) { // Set error to console tbConsole.AppendText("ERRO! "); tbConsole.AppendText(error.Message + "\n"); // Select error in the textbox SelectLine(error.GetLine()); // Show error dialog MessageBox.Show("Houve um erro ao efetuar a análise léxica do código fonte\n"); } catch (SyntacticalException error) { // Set error to console tbConsole.AppendText("ERRO! "); tbConsole.AppendText(error.Message + "\n"); // Select error in the textbox SelectLine(error.GetLine()); // Show error dialog MessageBox.Show("Houve um erro ao efetuar a análise sintática do código fonte\n"); } catch (SemanticException error) { // Set error to console tbConsole.AppendText("ERRO! "); tbConsole.AppendText(error.Message + "\n"); // Select error in the textbox SelectLine(error.GetLine()); // Show error dialog MessageBox.Show("Houve um erro ao efetuar a análise semântica do código fonte\n"); } // Disabled buttons ResetDebugControlButtons(); }
public Compiler() { SyntacticalAnalyzer = new SyntacticalAnalyzer(); TriadsConverter = new TriadsConverter(); TriadsOptimizer = new TriadsOptimizer(); }