static async Task Main(string[] args) { var http = new HttpClient(); var serializer = new SerializerBuilder() .DisableAliases() .WithTypeConverter(new ColorYamlTypeConverter()) .Build(); var tokenizer = new DMTokenizer(); DMParser.Defines.Add("REAGENTS_METABOLISM", 0.4m); DMParser.Defines.Add("REM", 0.1m); DMParser.Defines.Add("T0C", 273.15m); DMParser.Defines.Add("BLOOD_VOLUME_NORMAL", 560m); var uri = new Uri(args[0]); var dmText = await http.GetStringAsync(uri); dmText = RemoveFunctions(dmText); var tokens = tokenizer.Tokenize(dmText); var obj = DMParser.ObjectList(tokens); if (obj.ErrorPosition.HasValue) { Console.WriteLine(obj); //var errorLine = objs.ErrorPosition.Line; //WriteSurrounding(objs, errorLine, 3); } var yaml = serializer.Serialize(obj.Value); Console.WriteLine(yaml); }
private void loadtree() { TreeNode objroot = new TreeNode("Universe"); int totalFiles = 0; List <fileInfo> files = new List <fileInfo>(); foreach (fileInfo F in info.files.Values) { if (F.Extension != ".dm") { continue; } totalFiles++; files.Add(F); } // int doneFiles = 0; DMParser P = new DMParser(); foreach (fileInfo F in files) { FileStream f = new FileStream(F.FullPath, FileMode.Open); if (f == null) { continue; } P.parseFile(f, F.InternalPath); f.Close(); } foreach (DMToken token in P.tokens) { string[] paths = token.pathToString().Split('/'); TreeNode curNode = objroot; foreach (string s in paths) { if (s == "") { continue; } if (curNode.Nodes.ContainsKey(s)) { curNode = curNode.Nodes[s]; continue; } else { TreeNode n = new TreeNode(s); n.Name = s; curNode.Nodes.Add(n); n.Tag = token; curNode = n; continue; } } } foreach (TreeNode n in objroot.Nodes) { // if (n.Nodes.Count == 0) // continue; treeView1.Nodes.Add(n); } }
private void loadtree() { TreeNode objroot = new TreeNode("Universe"); int totalFiles = 0; List<fileInfo> files = new List<fileInfo>(); foreach (fileInfo F in info.files.Values) { if (F.Extension != ".dm") continue; totalFiles++; files.Add(F); } // int doneFiles = 0; DMParser P = new DMParser(); foreach (fileInfo F in files) { FileStream f = new FileStream(F.FullPath, FileMode.Open); if (f == null) continue; P.parseFile(f, F.InternalPath); f.Close(); } foreach (DMToken token in P.tokens) { string[] paths = token.pathToString().Split('/'); TreeNode curNode = objroot; foreach (string s in paths) { if (s == "") continue; if (curNode.Nodes.ContainsKey(s)) { curNode = curNode.Nodes[s]; continue; } else { TreeNode n = new TreeNode(s); n.Name = s; curNode.Nodes.Add(n); n.Tag = token; curNode = n; continue; } } } foreach (TreeNode n in objroot.Nodes) { // if (n.Nodes.Count == 0) // continue; treeView1.Nodes.Add(n); } }
private static bool Compile(List <Token> preprocessedTokens) { DMLexer dmLexer = new DMLexer(null, preprocessedTokens); DMParser dmParser = new DMParser(dmLexer, !Settings.SuppressUnimplementedWarnings); VerbosePrint("Parsing"); DMASTFile astFile = dmParser.File(); if (dmParser.Warnings.Count > 0) { foreach (CompilerWarning warning in dmParser.Warnings) { Warning(warning); } } if (dmParser.Errors.Count > 0) { foreach (CompilerError error in dmParser.Errors) { Error(error); } } if (astFile == null) { return(false); } DMASTSimplifier astSimplifier = new DMASTSimplifier(); VerbosePrint("Constant folding"); astSimplifier.SimplifyAST(astFile); DMObjectBuilder dmObjectBuilder = new DMObjectBuilder(); dmObjectBuilder.BuildObjectTree(astFile); if (ErrorCount > 0) { return(false); } return(true); }