private void traducirToolStripMenuItem_Click(object sender, EventArgs e) { Console.WriteLine(!(true || false)); Syntactic mySyntactic = new Syntactic(); //bool resultado = mySyntactic.analyze(getRichTextBox().Text); ParseTreeNode resultado = mySyntactic.analyze(getRichTextBox().Text); if (resultado != null) { MessageBox.Show("Analisis Correcto"); richTextBox1.Text = ""; String text = ""; String lenguaje = (Recorrido.recorrerAST(resultado.ChildNodes.ElementAt(0), text)); getRichTextBox2().Text = lenguaje; Recorrido.traducir(resultado); Syntactic.generarImagen(resultado); } else { MessageBox.Show("Analisis con errores"); richTextBox1.Text = ""; foreach (sol.com.analyzer.Token item in Syntactic.lista) { richTextBox1.Text += "\nError " + item.tipo + ": Lexema: \"" + item.lexema + "\"" + ", Linea: " + item.fila + ", Columna: " + item.columna + ", Descripcion: " + item.descripcion; } } }
private void compilar_Click(object sender, EventArgs e) { Syntactic s = new Syntactic(); C3DController.Instance.clearCode(); ErrorController.Instance.Clean(); s.analizer(areaanalizar.Text, Application.StartupPath); this.errores.Enabled = this.tablasimbolos.Enabled = false; consola.Text = ""; if (ErrorController.Instance.containLexicalError()) { consola.Text += ErrorController.Instance.getLexicalError(); this.errores.Enabled = true; } else if (ErrorController.Instance.containSemantycError()) { consola.Text += ErrorController.Instance.getSemantycError(); this.errores.Enabled = true; } else if (ErrorController.Instance.containSyntacticError()) { consola.Text += ErrorController.Instance.getSintactycError(); this.errores.Enabled = true; } else { consola.Text = "#include <stdio.h>\nfloat Heap[100000]; //estructura heap\nfloat Stack[100000]; //estructura stack\n\n"; consola.Text += "int SP = 0; //puntero Stack pointer\nint HP = 0; //puntero Heap pointer\n\n"; consola.Text += C3DController.Instance.getTemps(); consola.Text += C3DController.Instance.get_Genenal(); this.tablasimbolos.Enabled = true; } }
public SLRParser(Semantic semantic, Syntactic syntactic) { _tableParser = new TableParser(); Generated = false; IsSLR = true; _semantic = semantic; _syntactic = syntactic; }
public LALRParser(Semantic semantic, Syntactic syntactic) { Generated = false; IsLALR = true; _semantic = semantic; _syntactic = syntactic; _tableParser = new TableParser(); states = new List <LRState>(); }
public TablesForm(Syntactic syntactic, Semantic semantic) { _semantic = semantic; _syntactic = syntactic; _llanalyser = new LLParser(_semantic, _syntactic); _lrParser = new LRParser(_semantic, _syntactic); _slrParser = new SLRParser(_semantic, _syntactic); _lalrParser = new LALRParser(_semantic, _syntactic); InitializeComponent(); }
static void Main(string[] args) { HanldersFiles handlerFile = new HanldersFiles(); var sourceCodes = handlerFile.getCode(); Lexer.Lexer lexer = new Lexer.Lexer(new StringContent(sourceCodes.ToLower())); Console.WriteLine(sourceCodes); Console.WriteLine("********************************************************"); /*Testing Lexer * while (currentToken.Type != TokenTypes.Eof) * { * string s = * $" Token : {currentToken.Type} Lexeme : {currentToken.Lexeme} Row : {currentToken.Row} Column : {currentToken.Column} "; * Console.WriteLine(s); * * currentToken = lexer.GetNextToken(); * } */ /* Testing Syntactic */ Syntactic parser = new Syntactic(lexer); //try //{ var treeNode = parser.Parse(); Console.WriteLine(" No se encontro ningun error de sintaxys"); foreach (var sentencesNode in treeNode) { sentencesNode.ValidateSemantic(); } foreach (var sentencesNode in treeNode) { sentencesNode.Interpretation(); } //} //catch (Exception e) //{ // Console.Write(e.Message); //} Console.ReadKey(); }
static void Main(string[] args) { GenerateMain generatePascal = new GenerateMain(); HandlerFiles handlFile = new HandlerFiles(); string pascalCode = handlFile.getCode(); string firstCode = " "; //Declaraciones Syntactic parser = new Syntactic(new Lexer.Lexer(new StringContent(pascalCode.ToLower()))); try { var treeNodes = parser.Parse(); var javaCode = string.Empty; foreach (var sentencesNode in treeNodes) { sentencesNode.ValidateSemantic(); if (sentencesNode is ProcedureNode || sentencesNode is FunctionNode || sentencesNode is RecordNode || sentencesNode is EnumerateNode) { firstCode += sentencesNode.GenerateCode(); } else { javaCode += sentencesNode.GenerateCode(); } } Console.WriteLine(generatePascal.ReturnCode(javaCode, firstCode)); handlFile.writeCode(generatePascal.ReturnCode(javaCode, firstCode)); Console.WriteLine("errors no founds"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.ReadKey(); } System.Diagnostics.Process.Start("C:\\Users\\Sequeiros\\Documents\\Compi\\pascal.bat"); }
private void InitializeElements() { _lexical = new Lexical(); _semantic = new Semantic(); _syntactic = new Syntactic(_semantic); RtxtCompiler.Text = " < E >::=< T >< El >\n < T >::=< F >< Tl >\n < F >::=\"a\" <E>\"f\"\n<F>::=\"x\"\n<El>::=\"m\"<T><El>\n<El>::=\"\"\n<Tl>::=\"v\"<F><Tl>\n<Tl>::=\"\"".Replace(" ", string.Empty); btnLexical.Enabled = true; btnSyntatic.Enabled = false; btnShowFirst.Enabled = false; btnFollow.Enabled = false; btnTables.Enabled = false; rbGrammar1.Enabled = true; rbGrammar2.Enabled = true; lblLexical.Text = ""; lblSyntactic.Text = ""; }
private void ejecutar_Click(object sender, EventArgs e) { //LIMPIA LA CONSOLA ConsolaController.Instance.clean(); ErrorController.Instance.Clean(); var texto_analizar = textAnalizar.Text; if (texto_analizar != "") { consola.Text = get_text(); Syntactic syntactic = new Syntactic(); syntactic.analizer(texto_analizar, Application.StartupPath); if (!ErrorController.Instance.containLexicalError()) { if (!ErrorController.Instance.containSyntacticError()) { setPicture_text(consola, pictureBox4, ConsolaController.Instance.getText(), "ast.png"); setPicture_text(consola, pictureBox5, "", "tabla_simbolostotal.png"); ErrorController.Instance.getSemantycError(Application.StartupPath); setPicture_text(consola, pictureBox3, "", "error_semantico.png"); } else { setPicture_text(consola, pictureBox2, ErrorController.Instance.getSintactycError(Application.StartupPath), "error_sintactico.png"); } } else { setPicture_text(consola, pictureBox1, ErrorController.Instance.getLexicalError(Application.StartupPath), "error_lexico.png"); } consola.Text = consola.Text + "\nFinalizado."; } else { consola.Text = "Debe escribir texto en el editor"; } }
static void Main(string[] args) { var wat = System.Reflection.Assembly.GetExecutingAssembly().Location; Console.WriteLine("Informe o caminho do diretorio de saída:"); var outDir = Console.ReadLine(); //var outDir = "C:\\Temp"; Console.WriteLine("Informe o caminho do arquivo de entrada:"); var inDir = Console.ReadLine(); //var inDir = "C:\\Temp\\code.py"; string lines = File.ReadAllText(inDir); Analyzer analyzer = new Analyzer(); analyzer.Analyze(lines); using (StreamWriter file = new System.IO.StreamWriter(outDir + @"\output.txt")) { foreach (Tkn tkn in analyzer.Tkns) { file.WriteLine(tkn.ToString()); } } var teste = analyzer.Tkns.Select(tk => tk.Type); Syntactic syntactic = new Syntactic(analyzer.Tkns); if (syntactic.Analyze()) { Console.WriteLine("Análise sintática foi concluida com sucesso."); } else { Console.WriteLine("Ocorreu um erro na análise sintática no token número " + syntactic.index); } Console.ReadKey(); }
public static string Run(string code) { long start = DateTime.Now.Ticks; Compiler com = new Compiler(); Reserved.Load(); string output = string.Empty; Lexical lexical = new Lexical(code); lexical.Run(); Compiler.LINE = lexical.row; Compiler.COLUMN = lexical.column; com.Tokens = lexical.Tokens; foreach (Token t in com.Tokens) { Console.WriteLine(t.ToString()); } com.Errors.AddRange(lexical.Errors); Syntactic syntatic = new Syntactic(com.Tokens); syntatic.Run(); //com.Errors.AddRange(syntatic.Errors); foreach (Error err in lexical.Errors) { output += $">> Lexical Error: {err}\n"; } foreach (Error err in syntatic.Errors) { output += $">> Syntatic Error: {err}\n"; } long stop = DateTime.Now.Ticks; output = (output == string.Empty) ? ">> Compilado com sucesso!" : output; int res = Convert.ToInt32(stop - start); output += "\n>> Tempo de compilação: " + (double)res / 10000000 + "s"; return(output); }
private void btnSyntatic_Click(object sender, EventArgs e) { _syntactic = new Syntactic(this._semantic); bool syntacticResult = _syntactic.VerifySyntactic(_lexical.GetSentence()); if (!syntacticResult) { lblSyntactic.Text = "Erro Sintático no simbolo: " + _syntactic.ErrorMessage; lblSyntactic.ForeColor = Color.Red; } else { ShowSyntacticResult(syntacticResult); } //Só calcula o first e o follow se não tiver erro sintáticoo if (syntacticResult) { _semantic.First(_syntactic.GetNonTerminals(), _syntactic.GetSingleProductions()); _semantic.Follow(_syntactic.GetNonTerminals(), _syntactic.GetSingleProductions()); } }
public async void RunCompiler() { bool ans = false; ans = await Task.Run(() => { try { // var lexical = new Lexical(); var syntactic = new Syntactic(); return(syntactic.Run(TxtEditor.FilePath)); } catch (Exception e) { UpdateScreenAlert(e.Message, true); return(false); } }); if (ans) { UpdateScreenAlert("Your file has been compiled successfully.", false); } }
// Use this for initialization void Start() { syn = gameObject.GetComponent <Syntactic>(); lex = gameObject.GetComponent <Lexical>(); }
private void toolStripButton1_Click(object sender, EventArgs e) { Parser.lines.Clear(); FileText = openFileDialog1.FileName; if (FileText != "") { Form activeChild = this.ActiveMdiChild; if (activeChild != null) { SplitContainer sp = (SplitContainer)activeChild.ActiveControl; RichTextBox editBox = (RichTextBox)sp.Panel2.Controls[0]; if (editBox != null) { Encoding en = Encoding.GetEncoding(1251); StreamWriter sw = new StreamWriter(FileText, false, en); sw.Write(editBox.Text); sw.Close(); } } } else { saveFileDialog1.ShowDialog(); } if (FileText != "") { Syntactic.errors.Clear(); Generation.lbls.Clear(); Parser.isStart = false; Parser.identy.Clear(); Parser.lexems.Clear(); Parser.effLabels.Clear(); Parser.lables.Clear(); Parser.isStart = false; Parser.const_str.Clear(); Parser.const_int.Clear(); Parser.num = 0; Parser.numlbs = 0; Encoding en = Encoding.GetEncoding(1251); StreamReader sr = new StreamReader(FileText, en); while (!sr.EndOfStream) { Parser.Parse(sr.ReadLine()); } sr.Close(); Generation.const_int.Clear(); Generation.const_str.Clear(); Generation.labels.Clear(); Generation.EndWhilelabels.Clear(); Generation.whilelabels.Clear(); Generation.Code = ""; Generation.numLabels = 0; Generation.numWhileLbls = 0; Generation.numEndWhileLbls = 0; Generation.GenData = false; Generation.GenDeclar = false; Syntactic synt = new Syntactic(); Form activeChild1 = this.ActiveMdiChild; SplitContainer sp1 = (SplitContainer)activeChild1.ActiveControl; RichTextBox editBox = (RichTextBox)sp1.Panel1.Controls[0]; int Start = 0; string text, temp; text = editBox.Text; while (Start != -1) { if (Start != text.Length) { Start++; Start = text.IndexOf("\n", Start); temp = text.Remove(Start); text = text.Remove(0, Start + 1); Parser.lables.Add(temp, Convert.ToInt32(temp).ToString()); Start = 0; } else { Start = -1; } } synt.ParseRoot(Parser.lexems); Lexical_analysis la = new Lexical_analysis(); la.ShowDialog(); } }