Main.cs :  » Script » IronRuby » gpcc » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Script » IronRuby 
IronRuby » gpcc » Main.cs
// Copyright (c) Microsoft Corporation. All rights reserved.

using System;
using System.Collections.Generic;


namespace gpcc{
  class GPCG
  {
    public static bool LINES = true;
    public static bool REPORT = false;
        public static bool DEFINES = false;
        public static bool FORGPLEX = false;

    private static void Main(string[] args)
    {
      try
      {
        string filename = ProcessOptions(args);

        if (filename == null)
          return;

        Parser parser = new Parser();
        Grammar grammar = parser.Parse(filename);

        LALRGenerator generator = new LALRGenerator(grammar);
        List<State> states = generator.BuildStates();
        generator.ComputeLookAhead();
        generator.BuildParseTable();
                if (!grammar.CheckGrammar())
                    throw new Exception("Non-terminating grammar");

        if (REPORT)
          generator.Report();
        else
        {
          CodeGenerator code = new CodeGenerator();
          code.Generate(states, grammar);
        }
      }
      catch (Scanner.ParseException e)
      {
        Console.Error.WriteLine("Parse error (line {0}, column {1}): {2}", e.line, e.column, e.Message);
      }
      catch (System.Exception e)
      {
        Console.Error.WriteLine("Unexpected Error {0}", e.Message);
      }
    }


    private static string ProcessOptions(string[] args)
    {
      string filename = null;

      foreach (string arg in args)
      {
        if (arg[0] == '-' || arg[0] == '/')
          switch (arg.Substring(1))
          {
            case "?":
            case "h":
            case "help":
              DisplayHelp();
              return null;
            case "v":
            case "version":
              DisplayVersion();
              return null;
            case "l":
            case "no-lines":
              LINES = false;
              break;
            case "r":
            case "report":
              REPORT = true;
              break;
                        case "d":
                        case "defines":
                            DEFINES = true;
                            break;
                        case "gplex":
                            FORGPLEX = true;
                            break;
          }
        else
          filename = arg;
      }

      if (filename == null)
        DisplayHelp();

      return filename;
    }


    private static void DisplayHelp()
    {
      Console.WriteLine("Usage gppg [options] filename");
      Console.WriteLine();
      Console.WriteLine("/help:       Display this help message");
      Console.WriteLine("/version:    Display version information");
      Console.WriteLine("/report:     Display LALR(1) parsing states");
      Console.WriteLine("/no-lines:   Suppress the generation of #line directives");
            Console.WriteLine("/defines:    Emit \"tokens\" file with token name list");
            Console.WriteLine("/gplex:      Generate scanner base class for GPLEX");
      Console.WriteLine();
    }


    private static void DisplayVersion()
    {
            Console.WriteLine("Gardens Point Parser Generator (gppg) 1.0.1.69 23/January/2007");
            Console.WriteLine("Written by Wayne Kelly");
            Console.WriteLine("w.kelly@qut.ed.au");
            Console.WriteLine("Queensland University of Technology");
            Console.WriteLine();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.