static IrBlock ParseBlock(MfNode node) { return(new IrBlock { Name = node.Value, Instructions = node.Select(ParseInstruction).ToArray() }); }
public static IrModule Parse(string code) { var cur = new MfNode(); var stack = new Stack <MfNode>(); var tokens = Tokenize(code).ToList(); for (var i = 0; i < tokens.Count;) { if (tokens[i] == "$$end") { i++; cur = stack.Pop(); } else { var next = new MfNode { Name = tokens[i++], Value = tokens[i++] }; stack.Push(cur); cur.Add(next); cur = next; } } return(new IrModule { Functions = cur.Select(ParseFunction).ToArray() }); }