public void InlineCommentTokenTest() { var token = LexicalAnalyzer.Analyze("/*", 1, 1); var token2 = LexicalAnalyzer.Analyze("*/", 1, 1); Assert.IsTrue(token.Type.Contains("inlinecmt")); Assert.IsTrue(token2.Type.Contains("inlinecmt")); }
public string Render(string paragraph) { var analyzer = new LexicalAnalyzer(); var tokens = analyzer.Analyze(paragraph); var parser = new TokenParser(tokens, paragraph); var tags = parser.Parse(); var tagInserter = new TagInserter(); var HTMLtext = tagInserter.Insert(paragraph, tags); return(HTMLtext); }
public void LoadRulesLA_test2() { LexicalAnalyzer la = new LexicalAnalyzer(); if (!la.LoadRules(path)) { Assert.Fail(); } la.Analyze("=2.5;\n"); Assert.AreEqual(la.data[1].property, "Num"); Assert.AreEqual(la.data[1].value, "2.5"); }
public void LoadRulesLA_test() { LexicalAnalyzer la = new LexicalAnalyzer(); if (!la.LoadRules(path)) { Assert.Fail(); } la.Analyze("import iopew 2;"); Assert.AreEqual(la.data[0].property, "Import"); Assert.AreEqual(la.data[1].value, "iopew"); Assert.AreEqual(la.data[2].value, "2"); Assert.AreEqual(la.data[3].value, ";"); }
private static void TestCode(Assembly asm, string directory, string compilerDir, string grammarId, SyntaxParserMapAlgorithm syntaxParserMapAlgorithm) { if (asm == null) { Console.WriteLine(" Get Compiled Compiler Failed..."); return; } { string conflicts = File.ReadAllText(Path.Combine(compilerDir, "Conflicts.log")); if (int.Parse(conflicts) > 0) { Console.WriteLine(" No need to Test Code with conflicts in SyntaxParser"); return; } } try { LexicalAnalyzer lexi = asm.CreateInstance( GetNamespace(grammarId) + "." + GetLexicalAnalyzerName(grammarId)) as LexicalAnalyzer; LRSyntaxParser parser = asm.CreateInstance( GetNamespace(grammarId) + "." + GetParserName(grammarId, syntaxParserMapAlgorithm)) as LRSyntaxParser; string[] sourceCodeFullnames = Directory.GetFiles( directory, "*.Code", SearchOption.TopDirectoryOnly); foreach (var fullname in sourceCodeFullnames) { try { FileInfo fileInfo = new FileInfo(fullname); string sourceCode = File.ReadAllText(fullname); TokenList tokenList = lexi.Analyze(sourceCode); tokenList.Dump(Path.Combine(compilerDir, fileInfo.Name + ".TokenList.log")); SyntaxTree tree = parser.Parse(tokenList); tree.Dump(Path.Combine(compilerDir, fileInfo.Name + ".Tree.log")); } catch (Exception e) { Console.WriteLine("Testing Error for {0}:", fullname); Console.WriteLine(e); } } } catch (Exception ex) { Console.WriteLine("Running Errors:"); Console.Write(" "); Console.WriteLine(ex); } }
public void LoadRulesLA_test1() { LexicalAnalyzer la = new LexicalAnalyzer(); if (!la.LoadRules(path)) { Assert.Fail(); } la.Analyze("sdaew rwo;ro!>=rep[]]]<*=" + "dsew" + "f;"); Assert.AreEqual(la.data[0].property, "ID"); Assert.AreEqual(la.data[1].value, "rwo"); Assert.AreEqual(la.data[2].value, ";"); Assert.AreEqual(la.data[4].property, "Not"); Assert.AreEqual(la.data[5].value, ">="); }
public void LoadRulesLA_test3() { LexicalAnalyzer la = new LexicalAnalyzer(); if (!la.LoadRules(path)) { Assert.Fail(); } la.Analyze("import java;\n" + "public class plus\n" + "{\n" + "double b=2;\n" + "double c=(a+b);\n" + "}"); Assert.AreEqual(la.data[7].property, "Double"); Assert.AreEqual(la.data[7].value, "double"); Assert.AreEqual(la.data[10].property, "Num"); Assert.AreEqual(la.data[10].value, "2"); }
private void button1_Click_1(object sender, EventArgs e) { try { var lexicalAnalyzer = new LexicalAnalyzer(); var lexems = lexicalAnalyzer.Analyze(InputBox.Text); SyntaxBox.Text = lexicalAnalyzer.ToStr(lexems); NonTerninalExp com = SyntaxAnalyser.Analyse(lexems); List <String> operatorsList; List <String> consoleList; Interpreter.Interpret(com, out operatorsList, out consoleList); OperatorsBox.Lines = operatorsList.ToArray(); ConsoleBox.Lines = consoleList.ToArray(); } catch (Exception msg) { MessageBox.Show(msg.ToString(), "Exception", MessageBoxButtons.OK); } }
// internal List<string> Decode(string axPath) #if AllowDecryption // internal List<string> DecodeAndDecrypt(BinaryReader reader,int fileSize) #endif public override List <string> Decode(BinaryReader reader) { AxData data = new AxData(); LexicalAnalyzer lex = null; TokenCollection stream = null; SyntacticAnalyzer synt = null; List <LogicalLine> lines = null; List <string> stringLines = new List <string>(); try { global::KttK.HspDecompiler.HspConsole.Write("ヘッダー解析中..."); data.LoadStart(reader, dictionary); data.ReadHeader(); global::KttK.HspDecompiler.HspConsole.Write("プリプロセッサ解析中..."); data.ReadPreprocessor(dictionary); global::KttK.HspDecompiler.HspConsole.Write("字句解析中..."); lex = new LexicalAnalyzer(dictionary); stream = lex.Analyze(data); data.LoadEnd(); global::KttK.HspDecompiler.HspConsole.Write("構文解析中..."); synt = new SyntacticAnalyzer(); lines = synt.Analyze(stream, data); global::KttK.HspDecompiler.HspConsole.Write("出力ファイル作成中..."); foreach (LogicalLine line in lines) { if (line.Visible) { string str = new string('\t', line.TabCount); stringLines.Add(str + line.ToString()); } } } catch (SystemException e) { throw new HspDecoderException("AxData", "想定外のエラー", e); } return(stringLines); }
public void DictionaryTokenTest() { var token = LexicalAnalyzer.Analyze("=", 1, 1); Assert.IsTrue(token.Type.Equals("assign")); }
public void TokenTest_GradingInt2() { var token = LexicalAnalyzer.Analyze("1", 1, 1); Assert.IsTrue(token.Type.Equals("intnum")); }
public void IdTokenTest() { var token = LexicalAnalyzer.Analyze("a394jojfsd_3498fds", 1, 1); Assert.IsTrue(token.Type.Equals("id")); }
public void FloatTokenTest() { var token = LexicalAnalyzer.Analyze("2e+1", 1, 1); Assert.IsTrue(token.Type.Contains("floatnum")); }
public void ZeroIntegerTokenTest() { var token = LexicalAnalyzer.Analyze("123", 1, 1); Assert.IsTrue(token.Type.Equals("intnum")); }
public void IdErrorTokenTest() { var token = LexicalAnalyzer.Analyze("a394jojfsd_3498fds&", 1, 1); Assert.IsTrue(token.Type.Contains("Invalid")); }
public void BlockCommentTokenTest() { var token = LexicalAnalyzer.Analyze("//", 1, 1); Assert.IsTrue(token.Type.Equals("blockcmt")); }
public void ErrorTokenTest() { var token = LexicalAnalyzer.Analyze("&", 1, 1); Assert.IsTrue(token.Type.Contains("Invalid")); }