Esempio n. 1
0
        static void Main(string[] args)
        {
            string filename = null;
            bool outputTokens = false;
            bool debugMode = false;
            int files = 0;
            foreach (string arg in args) {
                switch (arg)
                {
                    case "-tokens":
                        outputTokens = true;
                        break;
                    case "-debug":
                        debugMode = true;
                        break;
                    default:
                        filename = arg;
                        files++;
                        break;
                }
                if (files > 1)
                {
                    filename = null;
                    break;
                }
            }
            if (filename != null)
            {
                CbParser parser = new CbParser();

                try
                {
                    FileStream file = new FileStream(filename, FileMode.Open);
                    LexScanner.Scanner scanner = new LexScanner.Scanner(file);
                    scanner.filename = filename;
                    scanner.tokens = outputTokens;
                    if (outputTokens)
                        scanner.openFile();
                    parser.Scanner = scanner;

                    parser.Parse();
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine("Error encountered while attempting to read file " + filename);
                    if (debugMode)
                    {
                        System.Console.WriteLine(e);
                    }
                }
            }
            else
            {
                System.Console.WriteLine("Usage: cbc [OPTION]... [FILE]");
                System.Console.WriteLine("Compiles Cb file FILE.");
                System.Console.WriteLine("  -tokens             output tokens to tokens.txt");
                System.Console.WriteLine("  -debug              display debug messages");
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string filename     = null;
            bool   outputTokens = false;
            bool   debugMode    = false;
            int    files        = 0;

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "-tokens":
                    outputTokens = true;
                    break;

                case "-debug":
                    debugMode = true;
                    break;

                default:
                    filename = arg;
                    files++;
                    break;
                }
                if (files > 1)
                {
                    filename = null;
                    break;
                }
            }
            if (filename != null)
            {
                CbParser parser = new CbParser();

                try
                {
                    FileStream         file    = new FileStream(filename, FileMode.Open);
                    LexScanner.Scanner scanner = new LexScanner.Scanner(file);
                    scanner.filename = filename;
                    scanner.tokens   = outputTokens;
                    if (outputTokens)
                    {
                        scanner.openFile();
                    }
                    parser.Scanner = scanner;

                    parser.Parse();
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine("Error encountered while attempting to read file " + filename);
                    if (debugMode)
                    {
                        System.Console.WriteLine(e);
                    }
                }
            }
            else
            {
                System.Console.WriteLine("Usage: cbc [OPTION]... [FILE]");
                System.Console.WriteLine("Compiles Cb file FILE.");
                System.Console.WriteLine("  -tokens             output tokens to tokens.txt");
                System.Console.WriteLine("  -debug              display debug messages");
            }
        }