private static Node ResolveIdentifier(Node node, Env env) { if ("True".Equals(node.Content)) { return(Node.TRUE); } if ("False".Equals(node.Content)) { return(Node.FALSE); } if (double.TryParse(node.Content.ToString(), out double result)) { return(node); } if (env != null && env.TryGetValue(node.Content.ToString(), out Node envNode)) { return(envNode); } string errorMsg = "Identifier not found in env: " + node.Content; return(new Node(StdNodeTypes.Error, errorMsg)); }
public bool TryGetValue(string content, out Node envNode) { if (localEnv.TryGetValue(content, out Node localEnvNode)) { envNode = localEnvNode; return(true); } if (parentEnv == null) { envNode = null; return(false); } bool success = parentEnv.TryGetValue(content, out Node parentEnvNode); envNode = parentEnvNode; return(success); }
private static int ReplaceMacros(Env env) { int replaceCount = 0; foreach (string key in env.GetEnvKeys()) { if (env.TryGetValue(key, out Node node)) { Node newNode = ExpandMacros(node, env, out int expansionsCount); if (newNode != node) { env.Add(key, newNode); } replaceCount += expansionsCount; } } return(replaceCount); }
private static Node TryGetMacro(string functionName, Env env) { if (functionName == null) { return(null); } if (!env.TryGetValue(functionName, out Node envNode)) { return(null); } if (!StdNodeTypes.Macro.Equals(envNode.NodeType)) { return(null); } return(envNode); }