public EntryPoint(Namespace ns, params ISyntaxNode[] body) { Name = "~Main"; Body = new List<ISyntaxNode>(body); Variables = ns.AddScope(); Namespace = ns; }
public static MethodCall Parse(ref string input, Namespace ns) { var orgInput = input; var ident = Identifier.Parse(ref input); if (ident == null) return null; if (input[0] != '(') return null; input = input.Substring(1); var length = input.Length; var args = new List<IExpression>(); while (true) { var expr = Expression.Parse(ref input, ns); if (expr != null) { if (expr.ReturnType.Name == "System.Void") throw new ArgumentException("Argument must have a return type"); args.Add(expr); } Whitespace.Parse(ref input); if (input.Length == 0) { input = orgInput; return null; } if (input[0] == ',') { input = input.Substring(1); continue; } else if (input[0] == ')') { input = input.Substring(1); break; } if (length == input.Length) throw new Exception("Could not parse:" + Environment.NewLine + input); length = input.Length; } var method = ns.GetMethod(ident.Value, args.Select(e => e.ReturnType).ToArray()); if (method == null) throw new Exception("Could not find method: " + ident.Value); var returnType = new AsmType(method.Split(' ')[0]); var methodName = string.Join(" ", method.Split(' ').Skip(1)); ident = new Identifier(methodName); return new MethodCall(ident, returnType, args.ToArray()); }
public static void Main(string[] args) { var ns = new Namespace(); ns.Add("/usr/lib/mono/4.5/mscorlib.dll"); ns.Using("System"); ns.Alias("System.Console.WriteLine", "Print"); ns.Alias("System.Console.ReadLine", "ReadLine"); var program = new Program(ns); foreach (var arg in args) program.Parse(File.ReadAllText(arg)); program.Emit(); }
public Program(Namespace ns) { Root = new List<ISyntaxNode>(); Main = new EntryPoint(ns); Namespace = ns; }