Source Code Cross Referenced for Tool.java in  » IDE-Netbeans » cnd » antlr » preprocessor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » cnd » antlr.preprocessor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package antlr.preprocessor;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.cs.usfca.edu
005:         * Software rights: http://www.antlr.org/license.html
006:         */
007:
008:        import java.io.*;
009:        import antlr.collections.impl.Vector;
010:        import java.util.Enumeration;
011:
012:        /** Tester for the preprocessor */
013:        public class Tool {
014:            protected Hierarchy theHierarchy;
015:            protected String grammarFileName;
016:            protected String[] args;
017:            protected int nargs; // how many args in new args list
018:            protected Vector grammars;
019:            protected antlr.Tool antlrTool;
020:
021:            public Tool(antlr.Tool t, String[] args) {
022:                antlrTool = t;
023:                processArguments(args);
024:            }
025:
026:            public static void main(String[] args) {
027:                antlr.Tool antlrTool = new antlr.Tool();
028:                Tool theTool = new Tool(antlrTool, args);
029:                theTool.preprocess();
030:                String[] a = theTool.preprocessedArgList();
031:                for (int i = 0; i < a.length; i++) {
032:                    System.out.print(" " + a[i]);
033:                }
034:                System.out.println();
035:            }
036:
037:            public boolean preprocess() {
038:                if (grammarFileName == null) {
039:                    antlrTool.toolError("no grammar file specified");
040:                    return false;
041:                }
042:                if (grammars != null) {
043:                    theHierarchy = new Hierarchy(antlrTool);
044:                    for (Enumeration e = grammars.elements(); e
045:                            .hasMoreElements();) {
046:                        String f = (String) e.nextElement();
047:                        try {
048:                            theHierarchy.readGrammarFile(f);
049:                        } catch (FileNotFoundException fe) {
050:                            antlrTool.toolError("file " + f + " not found");
051:                            return false;
052:                        }
053:                    }
054:                }
055:
056:                // do the actual inheritance stuff
057:                boolean complete = theHierarchy.verifyThatHierarchyIsComplete();
058:                if (!complete)
059:                    return false;
060:                theHierarchy.expandGrammarsInFile(grammarFileName);
061:                GrammarFile gf = theHierarchy.getFile(grammarFileName);
062:                String expandedFileName = gf
063:                        .nameForExpandedGrammarFile(grammarFileName);
064:
065:                // generate the output file if necessary
066:                if (expandedFileName.equals(grammarFileName)) {
067:                    args[nargs++] = grammarFileName; // add to argument list
068:                } else {
069:                    try {
070:                        gf.generateExpandedFile(); // generate file to feed ANTLR
071:                        args[nargs++] = antlrTool.getOutputDirectory()
072:                                + System.getProperty("file.separator")
073:                                + expandedFileName; // add to argument list
074:                    } catch (IOException io) {
075:                        antlrTool
076:                                .toolError("cannot write expanded grammar file "
077:                                        + expandedFileName);
078:                        return false;
079:                    }
080:                }
081:                return true;
082:            }
083:
084:            /** create new arg list with correct length to pass to ANTLR */
085:            public String[] preprocessedArgList() {
086:                String[] a = new String[nargs];
087:                System.arraycopy(args, 0, a, 0, nargs);
088:                args = a;
089:                return args;
090:            }
091:
092:            /** Process -glib options and grammar file.  Create a new args list
093:             *  that does not contain the -glib option.  The grammar file name
094:             *  might be modified and, hence, is not added yet to args list.
095:             */
096:            private void processArguments(String[] incomingArgs) {
097:                this .nargs = 0;
098:                this .args = new String[incomingArgs.length];
099:                for (int i = 0; i < incomingArgs.length; i++) {
100:                    if (incomingArgs[i].length() == 0) {
101:                        antlrTool.warning("Zero length argument ignoring...");
102:                        continue;
103:                    }
104:                    if (incomingArgs[i].equals("-glib")) {
105:                        // if on a pc and they use a '/', warn them
106:                        if (File.separator.equals("\\")
107:                                && incomingArgs[i].indexOf('/') != -1) {
108:                            antlrTool
109:                                    .warning("-glib cannot deal with '/' on a PC: use '\\'; ignoring...");
110:                        } else {
111:                            grammars = antlrTool.parseSeparatedList(
112:                                    incomingArgs[i + 1], ';');
113:                            i++;
114:                        }
115:                    } else if (incomingArgs[i].equals("-o")) {
116:                        args[this .nargs++] = incomingArgs[i];
117:                        if (i + 1 >= incomingArgs.length) {
118:                            antlrTool
119:                                    .error("missing output directory with -o option; ignoring");
120:                        } else {
121:                            i++;
122:                            args[this .nargs++] = incomingArgs[i];
123:                            antlrTool.setOutputDirectory(incomingArgs[i]);
124:                        }
125:                    } else if (incomingArgs[i].charAt(0) == '-') {
126:                        args[this .nargs++] = incomingArgs[i];
127:                    } else {
128:                        // Must be the grammar file
129:                        grammarFileName = incomingArgs[i];
130:                        if (grammars == null) {
131:                            grammars = new Vector(10);
132:                        }
133:                        grammars.appendElement(grammarFileName); // process it too
134:                        if ((i + 1) < incomingArgs.length) {
135:                            antlrTool
136:                                    .warning("grammar file must be last; ignoring other arguments...");
137:                            break;
138:                        }
139:                    }
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.