public void semantic_token_comparison(string first, string second, int result) { var tk = new SemanticToken(first); var tk2 = new SemanticToken(second); Assert.Equal(result, tk.CompareTo(tk2)); }
public string GetComment(SemanticToken token) { IToken t = (SemanticToken)token; int line = t.Position.Line; string lineContent = GetLine(line - 1); if (!string.IsNullOrEmpty(lineContent)) { return(string.Format("Line: {0} {1}", line, lineContent.Trim())); } return(null); }
private bool CheckOpLog(List <Pair> Pairs) { if ((Pairs[0].Token == 31 || Pairs[0].Token == 32 || Pairs[0].Token == 33 || Pairs[0].Token == 34) && Pairs[1].Token == 50 && (Pairs[2].Token == 31 || Pairs[2].Token == 32 || Pairs[2].Token == 33 || Pairs[2].Token == 34)) { SemanticToken token = new SemanticToken(); token.Rule = 4; //token.TokenList = new List<int>(); //token.LexemList = new List<LexemList>(); for (int i = 0; i < 3; i++) { token.PairList.Add(Pairs[i]); token.TokenList.Add(Pairs[i].Token); token.LexemList.Add(TableLexems[i]); } SemanticTokens.Add(token); return(true); } else { return(false); } }
private int CheckDecl(List <Pair> Pairs) { if (Pairs[0].Token == 10 && Pairs[1].Token == 31 && Pairs[2].Token == 100 && (Pairs[3].Token == 31 || Pairs[3].Token == 32 || Pairs[3].Token == 33 || Pairs[3].Token == 34) && Pairs[4].Token == 101) { SemanticToken token = new SemanticToken(); token.Rule = 9; //token.TokenList = new List<int>(); //token.LexemList = new List<LexemList>(); for (int i = 0; i < 5; i++) { token.PairList.Add(Pairs[i]); token.TokenList.Add(Pairs[i].Token); token.LexemList.Add(TableLexems[i]); } SemanticTokens.Add(token); textTree.Text += ", Regla 9"; return(1); } else { return(0); } }
public void semantic_token_comparison(string first,string second,int result) { var tk = new SemanticToken(first); var tk2 = new SemanticToken(second); Assert.Equal(result,tk.CompareTo(tk2)); }
// Sentencia private int CheckSent(List <Pair> Pairs, int StartToken) { textTree.Text += ", Regla 2"; // Declaracion if (Pairs[StartToken].Token == 10 && Pairs[StartToken + 1].Token == 31 && Pairs[StartToken + 2].Token == 100 && (Pairs[StartToken + 3].Token == 31 || Pairs[StartToken + 3].Token == 32 || Pairs[StartToken + 3].Token == 33 || Pairs[StartToken + 3].Token == 34) && Pairs[StartToken + 4].Token == 101) { textTree.Text += ", Regla 9"; SemanticToken token = new SemanticToken(); token.Rule = 9; for (int i = 0; i < 5; i++) { token.PairList.Add(Pairs[i]); token.TokenList.Add(Pairs[i].Token); token.LexemList.Add(TableLexems[i]); } SemanticTokens.Add(token); return(RemoveTokens(5, false)); } // If else if ((Pairs[0].Token == 23 || Pairs[0].Token == 27) && Pairs[1].Token == 41) { int inputInt = CheckIf(Pairs, 2) + 1; int outputInt = 0; if (inputInt != 1) { if (Pairs[0].Token == 23) { textTree.Text += ", Regla 3"; } else if (Pairs[0].Token == 27) { textTree.Text += ", Regla 8"; } textTree.Text += ", Regla 4"; } List <Pair> temp_Sent = ReloadSent(Pairs, inputInt + 1); outputInt = inputInt + 1 + temp_Sent.Count; inputInt = CheckSent(temp_Sent, 0); int removedTokens = RemoveTokens(outputInt - inputInt + 1, false); if (Pairs.Count > 0 && (Pairs[0].Token == 24 && Pairs[1].Token == 45)) { temp_Sent = ReloadSent(Pairs, 2); CheckSent(temp_Sent, 0); return(RemoveTokens(3, false)); } else { return(removedTokens); } } else if (Pairs[0].Token == 25 && Pairs[1].Token == 41) { //For int inputInt = CheckFor(Pairs) + 2; if (inputInt != 1 && Pairs[inputInt - 2].Token == 42 && Pairs[inputInt - 1].Token == 45) { List <Pair> temp_Sent = ReloadSent(Pairs, inputInt); int outputInt = 0; outputInt = inputInt + 1 + temp_Sent.Count; inputInt = CheckSent(temp_Sent, 0); int removedTokens = RemoveTokens(outputInt - inputInt, false); return(1); } else { return(0); } } else { return(0); } }