public void RunShouldSucceed() { // arrange var engine = new EInterpreter.Engine.Engine(); var tree = new ETree { Utilities = new List <EUtility> { new EUtility("Program") { Functions = new List <EFunction> { new EFunction("Boolean", "Program.Start", new List <EProperty> { new EProperty("Text", "arguments") }) { Elements = { new EReturn("", "true") } } } } } }; // act engine.Run(tree); }
private void _processToken(EToken token, ETree tree) { switch (token.Type) { case ETokenType.WHITESPACE: case ETokenType.COMMENT: case ETokenType.OPEN: // do nothing break; case ETokenType.CLOSE: _handleClose(); break; case ETokenType.CONSTANT: _handleConstant(token, tree); break; case ETokenType.OBJECT: _handleObject(token, tree); break; case ETokenType.PROPERTY: _handleProperty(token); break; case ETokenType.UTILITY: _handleUtility(token, tree); break; case ETokenType.FUNCTION: _handleFunction(token); break; case ETokenType.FUNCTION_STATEMENT: _handleStatement(token); break; case ETokenType.DECLARATION: _handleDeclaration(token); break; case ETokenType.FUNCTION_CALL: _handleFunctionCall(token); break; case ETokenType.FUNCTION_RETURN: _handleFunctionReturn(token); break; case ETokenType.ASSIGNMENT: _handleAssignment(token); break; default: throw new ParserException($"Unhandled token type {token.Type} at line: {token.LineNumber}"); } }
private void _handleConstant(EToken token, ETree tree) { EConstant constant; try { constant = Parsers.ParseConstant(token.Line); } catch { throw new ParserException(_unparsebleMessage("constant", token.LineNumber)); } tree.Constants.Add(constant); }
private void _handleUtility(EToken token, ETree tree) { EUtility utility; try { utility = Parsers.ParseUtility(_getNamespac(), token.Line); } catch { throw new ParserException(_unparsebleMessage("utility", token.LineNumber)); } tree.Utilities.Add(utility); _callStack.Push(utility); }
private void _handleObject(EToken token, ETree tree) { EObject objct; try { objct = Parsers.ParseObject(_getNamespac(), token.Line); } catch { throw new ParserException(_unparsebleMessage("object", token.LineNumber)); } tree.Objects.Add(objct); _callStack.Push(objct); }
public ValidationStepResult Execute(ETree tree) { var dups = new List <string>(); foreach (var util in tree.Utilities) { dups.AddRange(util.Functions.Select(p => p.Name).GetNonDistinctValues()); } return(dups.Any() ? new ValidationStepResult(false, $"Not all utility identifiers have unique names: {string.Join(", ", dups)}") : new ValidationStepResult(true, "All utility identifiers have unique names")); }
public ValidationStepResult Execute(ETree tree) { var identifiers = new List <string>(); identifiers.AddRange(tree.Constants.Select(c => c.Name)); identifiers.AddRange(tree.Utilities.Select(u => u.Name)); identifiers.AddRange(tree.Objects.Select(o => o.Name)); var dups = identifiers.GetNonDistinctValues().ToArray(); return(dups.Any() ? new ValidationStepResult(false, $"Not all global identifiers have unique names: {string.Join(", ", dups)}") : new ValidationStepResult(true, "All global identifiers have unique names")); }
/// <summary> /// Build a ETree out of a list of ETokens /// </summary> /// <param name="tokens">Unordered list of ETokens</param> /// <returns></returns> public ETree Parse(IEnumerable <EToken> tokens) { var tree = new ETree(); var orderedTokens = tokens.OrderBy(t => t.LineNumber).ToList(); foreach (var token in orderedTokens) { _processToken(token, tree); } return(tree); }
public void Run(ETree tree) { var stopwatch = new Stopwatch(); stopwatch.Restart(); _tree = tree; _run(); _tree = null; stopwatch.Stop(); Duration = stopwatch.Elapsed; }
public Equation(string equationString) { var splitEquation = SplitEquation(equationString); try { _equation = EParse(splitEquation); } catch (Exception) { throw new Exception("Unable to parse: " + equationString); } }
private void _lex() { Extensions.WriteColoredLine("Lexing: ", ConsoleColor.DarkCyan); _tree = new Lexer.Lexer().GetTree(_lines); if (_tree != null) { Console.WriteLine(_tree.Summarize()); return; } Extensions.WriteColoredLine("The parser did not return an object tree!", ConsoleColor.Red); throw new LexerException("EInterpreter stopped before execution because of a lexer exception"); }
//组装数并初始化勾选 private async Task <List <ETree> > BuilderTreeAsync(List <int> InitCheck, int ParentID = 0) { IEnumerable <ESysMenu> listMenus = await _SysMenuRepository.GetMenuByParentIDAsync(ParentID); List <ETree> _treeList = new List <ETree>(); try { if (listMenus.Count() > 0) { ETree _tree = null; foreach (ESysMenu item in listMenus) { _tree = new ETree(); _tree.id = item.MenuID; _tree.title = item.MenuTitle; _tree.href = item.MenuUrl; _tree.spread = true;//展开 InitCheck.ForEach(p => { if (p == _tree.id) { _tree.@checked = true; } }); var listChildMenus = await BuilderTreeAsync(InitCheck, _tree.id); if (listChildMenus.Count > 0) { _tree.children = new List <ETree>(); _tree.children.AddRange(listChildMenus); } _treeList.Add(_tree); } } } catch (Exception ex) { throw ex; } return(_treeList); }
public void RunShouldFail() { // arrange var engine = new EInterpreter.Engine.Engine(); var tree = new ETree { Constants = new List <EConstant> { new EConstant("test", "Test1", "") }, Utilities = new List <EUtility> { new EUtility("Test2") } }; // assert Assert.ThrowsException <EInterpreter.EngineException>(() => engine.Run(tree)); }
public void Go(string[] lines, string name) { _tree = null; _lines = lines; _name = name; try { _preValidate(); _lex(); _postValidate(); _runEngine(); } catch (Exception ex) { Extensions.WriteColoredLine(ex.Message, ConsoleColor.Red); } }
//---------------------------------------------FUNCTIONS PUBLIC---------------------------------------------- //o --> error 1 --> correcto //method to do semantic analysis public int Semantic_Analysis() { //instance class ReadFileC rf = new ReadFileC(); //return config start button2.Enabled = false; textBox1.Enabled = false; //get data from the all file string[] res = rf.ReadFile(PathFile); if (res.Length == 0) { MessageBox.Show("El archivo se encontro vacio."); //end program return(0); } else { //add items at lists L_Sets = rf.SplitSets(res); //tested L_Tokens = rf.SplitTokens(res); //tested L_Actions = rf.SplitActions(res); //tested L_Error = rf.SplitError(res); //tested L_Actions = rf.FixActions(L_Actions); //testeed //firs filter (key words) if (F_KeyWords(L_Tokens, L_Actions, L_Error) != "GG") { MessageBox.Show(F_KeyWords(L_Tokens, L_Actions, L_Error)); //end program return(0); } else { MessageBox.Show("Primer Filtro Correcto"); //CONTINUED //------------------- SECOND FILTER //Create string ER string ER_sets1 = "(a+.f+.g.(f+.h.(a|b|c|i).h.(j|k)?)+).#"; //LETRA = 'A'..'Z'+'a'..'z'+'_' string ER_sets2 = "(a+.f+.g.(f+.d+.l.c+.m.j?)+).#"; //CHARSET = CHR(32)..CHR(254) string ER_tokens = "(e+.f+.c+.f*.g.f*.((h.(a|i).h)*|(a|f|n)*|(a|b|f|i)*)+).#"; //'"' CHARSET '"'|''' CHARSET ''' // LETRA ( LETRA | DIGITO )* { RESERVADAS() } string ER_actions = "(c+.f.g.f.h.a+.h).#"; //18 = 'PROGRAM' string ER_error = "(ñ+.f.g.f.c+).#"; //ERROR = 54 //Create tree for each ER... ETree T_Sets = new ETree(); ETree T_Sets2 = new ETree(); ETree T_Tokens = new ETree(); ETree T_Actions = new ETree(); ETree T_Error = new ETree(); //Create stack for each ER Stack <Nodo> Tree_Sets = new Stack <Nodo>(); Stack <Nodo> Tree_Sets2 = new Stack <Nodo>(); Stack <Nodo> Tree_Tokens = new Stack <Nodo>(); Stack <Nodo> Tree_Actions = new Stack <Nodo>(); Stack <Nodo> Tree_Error = new Stack <Nodo>(); //Insert value in differents trees Tree_Sets = T_Sets.Insert(ER_sets1); Tree_Sets2 = T_Sets2.Insert(ER_sets2); Tree_Tokens = T_Tokens.Insert(ER_tokens); Tree_Actions = T_Actions.Insert(ER_actions); Tree_Error = T_Error.Insert(ER_error); // recorrido T_Sets.InOrder(Tree_Sets.Pop()); T_Sets2.InOrder(Tree_Sets2.Pop()); T_Tokens.InOrder(Tree_Tokens.Pop()); T_Actions.InOrder(Tree_Actions.Pop()); T_Error.InOrder(Tree_Error.Pop()); //mostrar recorrido de arboles //MessageBox.Show(T_Sets.cadena); //MessageBox.Show(T_Sets2.cadena); //MessageBox.Show(T_Tokens.cadena); //MessageBox.Show(T_Actions.cadena); //MessageBox.Show(T_Error.cadena); //----------------------------- READ SECTIONS ----------------------------------------------- //send all tokens Token t = new Token(); List <Token> L_t = new List <Token>(); L_t = t.Insert_Tokens(); //filter sets if (rf.ReadSets(L_Sets, L_t, ER_sets1, ER_sets2) != "GG") { string er = rf.ReadSets(L_Sets, L_t, ER_sets1, ER_sets2); char[] x = er.ToArray(); int columna = Error_Columna(x); int line = Error_Line(x, res); MessageBox.Show(er); MessageBox.Show("Error en la linea: " + line + " Columna: " + columna); return(0); } //filter tokens else if (rf.ReadTokens(L_Tokens, L_t, ER_tokens) != "GG") { string er = rf.ReadTokens(L_Tokens, L_t, ER_tokens); char[] x = er.ToArray(); int columna = Error_Columna(x); int line = Error_Line(x, res); MessageBox.Show(er); MessageBox.Show("Error en la linea: " + line + " Columna: " + columna); return(0); } //filter action else if (rf.ReadAction(L_Actions, L_t, ER_actions) != "GG") { string er = rf.ReadAction(L_Actions, L_t, ER_actions); char[] x = er.ToArray(); int columna = Error_Columna(x); int line = Error_Line_A(x, res); if (line == 0) { line = Error_Line(x, res); } MessageBox.Show(er); MessageBox.Show("Error en la linea: " + line + " Columna: " + columna); return(0); } //filter error else if (rf.ReadError(L_Error, L_t, ER_error) != "GG") { string er = rf.ReadError(L_Error, L_t, ER_error); char[] x = er.ToArray(); int columna = Error_Columna(x); int line = Error_Line(x, res); MessageBox.Show(er); MessageBox.Show("Error en la linea: " + line + " Columna: " + columna); return(0); } else { MessageBox.Show("Archivo leido correctamente :)"); return(1); } } } //fiter the file empity }
public void Syntactic_Analysis() { //Save the data the section SETS if exist if (L_Sets != null) { foreach (var item in L_Sets) { N_Sets.Add(Name_SETS(item)); } } //Create ER for syntactic analysis //instance class for functions the ER ER FER = new ER(); string ER_analysis = ""; //Save here ER for syntactic analysis ER_analysis = FER.CreateER(L_Tokens); //SAVE ER version 1 string flag_SETS = FER.Is_Correct_SETS(ER_analysis, N_Sets); if (flag_SETS == "GG") { ER_analysis = FER.String_Completed(ER_analysis); //completed string with symbol '.' textBox2.Text = ER_analysis; //show user //create tree ETree T_Tokens = new ETree(); Stack <Nodo> Tree_Tokens = new Stack <Nodo>(); //stack the final tree Tree_Tokens = T_Tokens.Insert(ER_analysis); //get tree // SECOND PHASE AFD the ETree //insert values the first , last and follow for direct method AFD AFD afd = new AFD(); //instance class Nodo Node_Token = new Nodo(); Node_Token = afd.Direct_Method(Tree_Tokens.Pop()); //Third Phase Transitions the AFD the Etree Columns_Transitions = afd.Transitions_Insert(Columns_Transitions, Node_Token); //save name the columns Values_Transitions = afd.Transitions_values(Values_Transitions, Node_Token, Columns_Transitions, Status); Status = afd.FixList(Status); //order number Values_Transitions = afd.FixList2(Values_Transitions); //Method for show in DataGridView Show_FirstLast(Node_Token); //show in data grid view data the first and last Show_Follow(Node_Token); // show in data grid view data the follow Show_Transitions(Columns_Transitions, Status, Values_Transitions); //shoq in data grid view data the transitions //Me servira para la fase 3 GetLastFollow(Node_Token); //show tree in image //string ruta = T_Tokens.graphic(Node_Token); //System.Threading.Thread.Sleep(1000); //FileStream file = new FileStream(ruta, FileMode.Open); //Image img = Image.FromStream(file); //pictureBox1.Image = img; //file.Close(); } else { MessageBox.Show(flag_SETS); //END PROGRAM } }
public EBinary(Opperator opperator, ETree left, ETree right) { _opp = opperator; _l = left; _r = right; }
public EUnary(Opperator opperator, ETree t) { _t = t; _opp = opperator; }