|
Java example source code file (Token.java)
The Token.java Java example source code/* * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * COMPONENT_NAME: idl.parser * * ORIGINS: 27 * * Licensed Materials - Property of IBM * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 * RMI-IIOP v1.0 * */ package com.sun.tools.corba.se.idl; // NOTES: // -F46082.51<daz> Remove -stateful feature. // -D59166<daz> Add support for keyword/identifier collision detection. This // feature is implemented here, rather than class Scanner, to allow the Parser // to handle the problem. // -F60858.1<daz> Support -corba option, level <= 2.2: identify 2.3 keywords. // -D62023<daz> Support -corba option, level <= 2.3, identify 2.4 keywords. // KMC Support -corba, level <= 3.0. Added 3.0 keywords. // // Should escaped Identifier should be a type rather than an attribute? // /** * Class Token represents a lexeme appearing within an IDL source. Every * Token has a type. Depending on its type and on the supported version * of IDL, a Token will have other associated attributes, such as a name * (identifier, e.g.), and whether it is escaped, deprecated, or is a type * that is known to be in a future version of IDL. **/ class Token { /////////////// // Available types static final int // Keywords Any = 0, // 2.2 Attribute = 1, // | Boolean = 2, // . Case = 3, // . Char = 4, // . Const = 5, Context = 6, Default = 7, Double = 8, Enum = 9, Exception = 10, FALSE = 11, Fixed = 12, // New addition Float = 13, In = 14, Inout = 15, Interface = 16, Long = 17, Module = 18, Native = 19, // New addition Object = 20, Octet = 21, Oneway = 22, Out = 23, Raises = 24, Readonly = 25, Sequence = 26, Short = 27, String = 28, Struct = 29, Switch = 30, TRUE = 31, Typedef = 32, Unsigned = 33, // . Union = 34, // . Void = 35, // . Wchar = 36, // | Wstring = 37, // 2.2 // <f46082.40> New OBV keywords... // <d62023> In 2.4rtf, "factory" is synonymous to "init" in 2.3 Init = 38, // 2.3 only Abstract = 39, // 2.3 2.4rtf Custom = 40, // | | Private = 41, // | | Public = 42, // | | Supports = 43, // | | Truncatable = 44, // | | ValueBase = 45, // | | Valuetype = 46, // 2.3 2.4rtf Factory = 47, // 2.4rtf only // Keywords in CORBA 3.0 Component = 48, Consumes = 49, Emits = 50, Finder = 51, GetRaises = 52, Home = 53, Import = 54, Local = 55, Manages = 56, Multiple = 57, PrimaryKey = 58, Provides = 59, Publishes = 60, SetRaises = 61, TypeId = 62, TypePrefix = 63, Uses = 64, Identifier = 80, // Identifier MacroIdentifier = 81, // Macro Identifier Semicolon = 100, // Symbols LeftBrace = 101, RightBrace = 102, Colon = 103, Comma = 104, Equal = 105, Plus = 106, Minus = 107, LeftParen = 108, RightParen = 109, LessThan = 110, GreaterThan = 111, LeftBracket = 112, RightBracket = 113, Apostrophe = 114, Quote = 115, Backslash = 116, Bar = 117, Carat = 118, Ampersand = 119, Star = 120, Slash = 121, Percent = 122, Tilde = 123, DoubleColon = 124, ShiftLeft = 125, ShiftRight = 126, Period = 127, Hash = 128, Exclamation = 129, DoubleEqual = 130, NotEqual = 131, GreaterEqual = 132, LessEqual = 133, DoubleBar = 134, DoubleAmpersand = 135, BooleanLiteral = 200, // Literals CharacterLiteral = 201, IntegerLiteral = 202, FloatingPointLiteral = 203, StringLiteral = 204, Literal = 205, Define = 300, // Directives Undef = 301, If = 302, Ifdef = 303, Ifndef = 304, Else = 305, Elif = 306, Include = 307, Endif = 308, Line = 309, Error = 310, Pragma = 311, Null = 312, Unknown = 313, Defined = 400, // <f46082.40> Keyword identifiers. //Abstract = 500, //Custom = 501, //Init = 502, //Private2 = 503, //Public2 = 504, //Supports = 505, //Truncatable = 506, //ValueBase = 507, //Valuetype = 508, EOF = 999; // End of Input // Available types /////////////// // Keywords static final String [] Keywords = { "any", "attribute", "boolean", "case", "char", "const", "context", "default", "double", "enum", "exception", "FALSE", "fixed", "float", "in", "inout", "interface", "long", "module", "native", "Object", "octet", "oneway", "out", "raises", "readonly", "sequence", "short", "string", "struct", "switch", "TRUE", "typedef", "unsigned", "union", "void", "wchar", "wstring", "init", // In 2.3 only "abstract", "custom", "private", // 2.3 and 2.4rtf "public", "supports", "truncatable", "ValueBase", "valuetype", "factory", // In 2.4rtf only // CORBA 3.0 keywords "component", "consumes", "emits", "finder", "getRaises", "home", "import", "local", "manages", "multiple", "primaryKey", "provides", "publishes", "setRaises", "supports", "typeId", "typePrefix", "uses" } ; // <f46082.40> Remove keyword identifiers. //static final int // FirstKeywordIdentifier = 500, // LastKeywordIdentifier = Valuetype; // //static final String[] KeywordIdentifiers = { // "abstract", "custom", "init", // "private", "public", "supports", // "truncatable", "valueBase", "valuetype"}; /** * Determine whether this token is a keyword. * @return true iff this token is a keyword. **/ boolean isKeyword () { return type >= FirstKeyword && type <= LastKeyword; } // isKeyword private static final int FirstKeyword = Any, // 0 LastKeyword = Uses; // <f60858.1> Keywords in CORBA 2.2 that we support. private static final int First22Keyword = Any, // 0 Last22Keyword = Wstring; // <f60858.1> New keywords in CORBA 2.3 (preliminary) that we support. private static final int First23Keyword = Init, Last23Keyword = Valuetype; // <d62023> New keywords in CORBA 2.4rtf (accepted 2.3) that we support. // Note that "factory" replaces "init". Scanner must account for this in // keyword scan. private static final int First24rtfKeyword = Abstract, Last24rtfKeyword = Factory; // New keywords in CORBA 3.0 (from CORBA components v. 1) private static final int First30Keyword = Component, Last30Keyword = Uses; // Current valid CORBA levels: // 2.2 (or <2.3): the default: no OBV support // 2.3: add OBV with init // >2.3: OBV with init replcaed by factory // 3.0: adds components, attr exceptions, local interfaces, type repository // decls. private static final int CORBA_LEVEL_22 = 0 ; private static final int CORBA_LEVEL_23 = 1 ; private static final int CORBA_LEVEL_24RTF = 2 ; private static final int CORBA_LEVEL_30 = 3 ; // Do the conversion from a floating point CORBA level to an int private static int getLevel( float cLevel ) { if (cLevel < 2.3f) return CORBA_LEVEL_22 ; if (Util.absDelta( cLevel, 2.3f ) < 0.001f) return CORBA_LEVEL_23 ; if (cLevel < 3.0f) return CORBA_LEVEL_24RTF ; return CORBA_LEVEL_30 ; } // Return the last keyword corresponding to a particular CORBA level private static int getLastKeyword( int level ) { if (level == CORBA_LEVEL_22) return Last22Keyword ; if (level == CORBA_LEVEL_23) return Last23Keyword ; if (level == CORBA_LEVEL_24RTF) return Last24rtfKeyword ; return Last30Keyword ; } /** Create a keyword token from a string. * Determines whether the string is an IDL keyword based on the corbaLevel. * Strings that are keywords at higher CORBA levels than the corbaLevel * argument create identifier tokens that are marked as "collidesWithKeyword", unless * escapedOK is FALSE, which is the case only when preprocessing is taking place. * In the case of the "init" keyword, which was only defined in CORBA 2.3, init is * marked deprecated in CORBA 2.3 since it is not supported in higher levels. * @param String string The string we are converting to a token. * @param float corbaLevel The CORBA level, currently in the interval [2.2, 3.0]. * @param boolean escapedOK Flag set true if _ is used to escape an IDL keyword for use * as an identifier. * @param boolean[] collidesWithKeyword is an array containing one value: a flag * representing whether this string is an identifier that collides with a keyword. * This is set by this method. * @returns Token The resulting Token corresponding to string. */ public static Token makeKeywordToken( String string, float corbaLevel, boolean escapedOK, boolean[] collision ) { int level = getLevel( corbaLevel ) ; int lastKeyword = getLastKeyword( level ) ; boolean deprecated = false ; collision[0] = false ; // If the string is a keyword token, return that token for (int i = Token.FirstKeyword; i <= Token.LastKeyword; ++i) { if (string.equals (Token.Keywords[i])) { // <f60858.1> Other Java examples (source code examples)Here is a short list of links related to this Java Token.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.