Source Code Cross Referenced for Symbol.java in  » Parser » beaver » beaver » 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 » Parser » beaver » beaver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
002:         * This file is part of Beaver Parser Generator.                       *
003:         * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>.  *
004:         * All rights reserved.                                                *
005:         * See the file "LICENSE" for the terms and conditions for copying,    *
006:         * distribution and modification of Beaver.                            *
007:         * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
008:
009:        package beaver;
010:
011:        /**
012:         * Represents a symbol of a grammar.
013:         */
014:        public class Symbol {
015:            static private final int COLUMN_FIELD_BITS = 12;
016:            static private final int COLUMN_FIELD_MASK = (1 << COLUMN_FIELD_BITS) - 1;
017:
018:            /**
019:             * Packes symbol "coordinates" into a single number.
020:             */
021:            static public int makePosition(int line, int column) {
022:                return line << COLUMN_FIELD_BITS | column;
023:            }
024:
025:            /**
026:             * Extracts line number from a packed position.
027:             */
028:            static public int getLine(int position) {
029:                return position >>> COLUMN_FIELD_BITS;
030:            }
031:
032:            /**
033:             * Extracts column number from a packed position.
034:             */
035:            static public int getColumn(int position) {
036:                return position & COLUMN_FIELD_MASK;
037:            }
038:
039:            /**
040:             * Value assigned to this symbol. 
041:             */
042:            public final Object value;
043:
044:            /** 
045:             * Numeric symbol ID. 
046:             */
047:            protected short id;
048:
049:            /**
050:             * Line and column where this symbol begins.
051:             */
052:            protected int start;
053:
054:            /**
055:             * Line and column where this symbol ends.
056:             */
057:            protected int end;
058:
059:            public Symbol(short id) {
060:                this .id = id;
061:                this .value = null;
062:            }
063:
064:            public Symbol(short id, Object value) {
065:                this .id = id;
066:                this .value = value;
067:            }
068:
069:            public Symbol(short id, int start, int end) {
070:                this .id = id;
071:                this .value = null;
072:                this .start = start;
073:                this .end = end;
074:            }
075:
076:            public Symbol(short id, int left, int right, Object value) {
077:                this .id = id;
078:                this .value = value;
079:                this .start = left;
080:                this .end = right;
081:            }
082:
083:            public Symbol(short id, int start_line, int start_column, int length) {
084:                this .id = id;
085:                this .value = null;
086:                this .start = makePosition(start_line, start_column);
087:                this .end = makePosition(start_line, start_column + length - 1);
088:            }
089:
090:            public Symbol(short id, int start_line, int start_column,
091:                    int length, Object value) {
092:                this .id = id;
093:                this .value = value;
094:                this .start = makePosition(start_line, start_column);
095:                this .end = makePosition(start_line, start_column + length - 1);
096:            }
097:
098:            /**
099:             * Creates Symbol for non-symbolic results of action routines
100:             * 
101:             * @param value attached Symbol's value
102:             */
103:            public Symbol(Object value) {
104:                this .value = value;
105:            }
106:
107:            /**
108:             * Special case constructor that allows creation of explicitly Symbol-ized nonterminals.
109:             * <p/>
110:             * Used by classes descending from Symbol and which instances are returned by reduce actions.
111:             * In this case ID and symbol position will be assigned by the parser when reduce action
112:             * code returns this symbol.
113:             */
114:            protected Symbol() {
115:                this .value = this ;
116:            }
117:
118:            /**
119:             * Returns an ID of this symbol.
120:             * <p/>
121:             * This ID typically is, depending on a symbol type, either a terminal ID if a Symbol is a token
122:             * created and returned by a Scanner, or a nonterminal ID if a symbol was created by parser based
123:             * on that nonterminal definition. In the former case the ID is one of IDs generated by Beaver
124:             * for terminal symbols. The latter keeps IDs of nonterminal symbols.
125:             * 
126:             * @return symbol's ID
127:             */
128:            public short getId() {
129:                return id;
130:            }
131:
132:            /**
133:             * Returns a position in a source where this symbol starts.
134:             *
135:             * @return packed line and column numbers
136:             */
137:            public int getStart() {
138:                return start;
139:            }
140:
141:            /**
142:             * Returns a position in a source where this symbol ends.
143:             * 
144:             * @return packed line and column numbers
145:             */
146:            public int getEnd() {
147:                return end;
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.