Пример #1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Error("The file to run is the one and only file that should be passed as an argument.");
            }

            if (args[0].StartsWith("-"))
            {
                Error("Invalid filename. Cannot start with \"-\".");
            }

            string code = "";

            try
            {
                code = System.IO.File.ReadAllText(args[0]);
            }
            catch (FileNotFoundException)
            {
                Error("The file you specified does not exist.");
            }

            LoadAssemblies();

            // TODO: add other options to commandline arguments
            ParsingApi.SetDialect(new DefaultDialect());

            Api.Program p = GS.CreateProgram(code);
            GS.Run(p);
        }
Пример #2
0
        public static void Load(string dir)
        {
            foreach (string file in Directory.EnumerateFiles(dir))
            {
                if (file.EndsWith("dll"))
                {
                    AssemblyName assemblyName = AssemblyName.GetAssemblyName(file);
                    Assembly     assembly     = Assembly.Load(assemblyName);

                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.GetCustomAttributes(typeof(GsDialect), true).Length == 1)
                        {
                            object o = type.GetConstructor(new Type[0])?.Invoke(new object[0]);

                            if (o == null)
                            {
                                Console.WriteLine("Recieved a class with the \"GsDialect\" attribute, but it wasn't a dialect. Ignoring.");
                                continue;
                            }

                            Dialect   d         = (Dialect)o;
                            GsDialect attribute = (GsDialect)type.GetCustomAttributes(typeof(GsDialect), true)[0];

                            d.Initialize(attribute.Name ?? "", attribute.Description ?? "", attribute.Version ?? "1.0", attribute.Extension ?? "");

                            ParsingApi.AddDialect(d);

                            Console.WriteLine("Successfully loaded " + d.Name);
                        }
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Run the program. This is assuming all of the other API's and whatnot are already setup. If those are not setup,
 /// an exception will be thrown.
 /// </summary>
 public void Run()
 {
     ParsingApi.Lex(this);
     ParsingApi.Parse(this);
     ParsingApi.BuildActionTree(this);
 }
Пример #4
0
 public Dialect(ParsingApi api)
 {
     _api = api;
 }