diff --git a/Module6/SimpleLanguage1/Main.cs b/Module6/SimpleLanguage1/Main.cs index 01f9c955a1d3fd8447d07f3d51ec6b2fa6a5b10d..a2c7c218221735701ff7c43bb8d7c2e7bceb43a2 100644 --- a/Module6/SimpleLanguage1/Main.cs +++ b/Module6/SimpleLanguage1/Main.cs @@ -3,6 +3,8 @@ using System.IO; using System.Collections.Generic; using SimpleScanner; using SimpleParser; +using System.Text; +using Newtonsoft.Json; namespace SimpleCompiler { @@ -11,6 +13,7 @@ namespace SimpleCompiler public static void Main() { string FileName = @"..\..\a.txt"; + string OutputFileName = @"..\..\a.json"; try { string Text = File.ReadAllText(FileName); @@ -26,8 +29,11 @@ namespace SimpleCompiler else { Console.WriteLine("Синтаксическое дерево построено"); - //foreach (var st in parser.root.StList) - //Console.WriteLine(st); + JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); + jsonSettings.Formatting = Newtonsoft.Json.Formatting.Indented; + jsonSettings.TypeNameHandling = TypeNameHandling.All; + string output = JsonConvert.SerializeObject(parser.root, jsonSettings); + File.WriteAllText(OutputFileName, output); } } catch (FileNotFoundException) diff --git a/Module6/SimpleLanguage1/Newtonsoft.Json.dll b/Module6/SimpleLanguage1/Newtonsoft.Json.dll new file mode 100644 index 0000000000000000000000000000000000000000..71ae7e6cee2c841229a36445461808b8b3d26e2b Binary files /dev/null and b/Module6/SimpleLanguage1/Newtonsoft.Json.dll differ diff --git a/Module6/SimpleLanguage1/SimpleLang1.csproj b/Module6/SimpleLanguage1/SimpleLang1.csproj index 9443c7d5019dd274bb1b76c811a910ded39ae537..540156697d3853fd99623071b881edc5c5a26d1d 100644 --- a/Module6/SimpleLanguage1/SimpleLang1.csproj +++ b/Module6/SimpleLanguage1/SimpleLang1.csproj @@ -34,6 +34,9 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Newtonsoft.Json"> + <HintPath>..\..\..\..\Students\МирзоевДенис\Task6\SimpleLanguage1\Newtonsoft.Json.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" />