📄 plusplus.y
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: PLUSPLUS.Y : description of C++ syntax
Modified By Reason
-------- -- ------
92/10/02 Greg Bentz Initial version, shipped as "alpha"
Jim Randall
Anthony Scian
Jim Welch
92/10/02 A.F.Scian changed cast-expression to use MakeNormalCast so
we can distinguish programmer specified casts
92/10/15 A.F.Scian added new keywords __stdcall, _Syscall, _Packed,
and _Seg16
92/10/16 A.F.Scian - added _Packed semantic actions for OS/2
- added _Seg16 semantic actions for OS/2
- made far16 equivalent to far for 16-bit compiler
- made syscall and stdcall equivalent to cdecl
for 16-bit compiler
92/10/22 A.F.Scian instead of parsing one global declaration at a
time and accepting the tokens, parse all of the
global declarations before accepting
92/10/23 A.F.Scian made interrupt a flag instead of a calling convention
92/10/28 A.F.Scian used direct access to standard calling conventions
92/10/29 A.F.Scian - treat exception decls just like arguments
- corrected throw to have an optional expr
92/12/01 A.F.Scian added better error messages for missing ';'
92/12/04 A.F.Scian added optional size expression for delete []
93/01/07 A.F.Scian changed precedence of :> operator to just less
than a cast
93/01/27 A.F.Scian added support for '::'<template-name>
93/01/31 A.F.Scian removed kludge to define class template symbols
93/02/08 A.F.Scian fixed problem with "struct T<x>" followed by id
93/02/09 A.F.Scian added calls to zapTemplateClassDeclSpec
(see YYDRIVER.C for explanation)
93/03/11 J.W.Welch New messaging
93/03/16 A.F.Scian streamlined member-declarator to directly call
DeclNoInit instead of going through DataInitNoInit
93/03/29 A.F.Scian added semantics for "new (int [x+1])" 5.3.3
"The first array dimension can be a general
integral expression even when <type-id> is used"
93/04/20 A.F.Scian added rules for y_template_scoped_typename to
handle nested types inside of templates
93/04/21 A.F.Scian fixed actions for function-declaration to not
pop the GS_DECL_SPEC stack until the function
body is processed (this allows any linkage on
the function symbol to be retained for the
entire processing of the function body)
93/07/13 A.F.Scian - added more than one pointer declarator to
conversion function ids
- fixed concatenation of strings so that the
type of the result is correct
93/07/29 A.F.Scian it was impossible to tell the difference between
no parms and ( void ) (both had parms == NULL)
so code now calls AddExplicitParms which handles
the problem by setting a bit in the DECL_INFO
93/08/11 A.F.Scian allow multiple ;'s in member decl lists
e.g., struct S { int a;;;; void foo(){};;; };
93/12/01 A.F.Scian added %ambig directives supported by new YACC
93/12/15 A.F.Scian added operator new []/operator delete [] support
94/03/23 A.F.Scian set up so that class S<int>; doesn't define the
class
94/04/18 A.F.Scian added support for "class __export __stdcall X"
94/04/19 A.F.Scian push some calls to FreeDeclInfo into functions
that are called before
94/06/08 A.F.Scian improved error message location for missing ';'
error messages
94/10/14 A.F.Scian added __declspec( <id> )
94/10/18 A.F.Scian added kludge to support:
typedef struct S { } S, const *CPS;
^^^^^- accept this
94/10/25 A.F.Scian upgrade LHS of assignment-expr so that it
accepts casts and pm-exprs
94/11/02 A.F.Scian added support for "class __declspec(dllimport) X"
94/12/07 A.F.Scian added Y_GLOBAL_ID as a valid declarator-id so
struct S { friend int ::foo( int ); }; works
95/02/23 A.F.Scian added __builtin_isfloat( <type-id> ) construct
95/04/28 A.F.Scian added __unaligned modifier
95/05/16 A.F.Scian added class template directives
95/06/28 A.F.Scian added more general offsetof field expressions
96/01/10 A.F.Scian adjusted syntax of __unaligned to match 'const'
rather than 'far'
96/02/12 A.F.Scian added support for __declspec( pragma-modifier )
96/02/26 A.F.Scian added some namespace syntax
96/03/19 A.F.Scian adjusted ++@/--@ grammar as per ISO C++ mtg in
Santa Cruz, CA resolutions
96/05/07 A.F.Scian added "using namespace X;"
96/06/07 A.F.Scian added support for multiple ids in __declspec()
96/07/02 A.F.Scian added sizeof <type-name>
96/07/25 A.F.Scian accept unsigned <type-name> : 1; as a bitfield
96/10/28 A.F.Scian fixed 96/07/25 so that <type-name> : 1; still works
*/
%token Y_IMPOSSIBLE
/*** declaration keywords ***/
%token Y_ASM
%token Y_AUTO
%token Y_BOOL
%token Y_CHAR
%token Y_CLASS
%token Y_CONST
%token Y_CONST_CAST
%token Y_DELETE
%token Y_DOUBLE
%token Y_DYNAMIC_CAST
%token Y_ELSE
%token Y_ENUM
%token Y_EXPLICIT
%token Y_EXPORT
%token Y_EXTERN
%token Y_FALSE
%token Y_FLOAT
%token Y_FOR
%token Y_FRIEND
%token Y_INLINE
%token Y_INT
%token Y_LONG
%token Y_MUTABLE
%token Y_NAMESPACE
%token Y_NEW
%token Y_OPERATOR
%token Y_PRIVATE
%token Y_PROTECTED
%token Y_PUBLIC
%token Y_REGISTER
%token Y_REINTERPRET_CAST
%token Y_SHORT
%token Y_SIGNED
%token Y_SIZEOF
%token Y_STATIC
%token Y_STATIC_ASSERT
%token Y_STATIC_CAST
%token Y_STRUCT
%token Y_TEMPLATE
%token Y_THIS
%token Y_THROW
%token Y_TRUE
%token Y_TYPEDEF
%token Y_TYPEID
%token Y_TYPENAME
%token Y_UNION
%token Y_UNSIGNED
%token Y_USING
%token Y_VIRTUAL
%token Y_VOID
%token Y_VOLATILE
/*** punctuation and operators ***/
%token Y_COMMA
%token Y_QUESTION
%token Y_COLON
%token Y_SEMI_COLON
%token Y_LEFT_PAREN
%token Y_RIGHT_PAREN
%token Y_LEFT_BRACKET
%token Y_RIGHT_BRACKET
%token Y_LEFT_BRACE
%token Y_RIGHT_BRACE
%token Y_TILDE
%token Y_EQUAL
%token Y_EQ
%token Y_EXCLAMATION
%token Y_NE
%token Y_OR
%token Y_OR_EQUAL
%token Y_OR_OR
%token Y_AND
%token Y_AND_EQUAL
%token Y_AND_AND
%token Y_XOR
%token Y_XOR_EQUAL
%token Y_GT
%token Y_GE
%token Y_LT
%token Y_LE
%token Y_LSHIFT
%token Y_LSHIFT_EQUAL
%token Y_RSHIFT
%token Y_RSHIFT_EQUAL
%token Y_PLUS
%token Y_PLUS_EQUAL
%token Y_PLUS_PLUS
%token Y_MINUS
%token Y_MINUS_EQUAL
%token Y_MINUS_MINUS
%token Y_TIMES
%token Y_TIMES_EQUAL
%token Y_DIVIDE
%token Y_DIVIDE_EQUAL
%token Y_PERCENT
%token Y_PERCENT_EQUAL
%token Y_DOT
%token Y_DOT_DOT_DOT
%token Y_DOT_STAR
%token Y_ARROW
%token Y_ARROW_STAR
%token Y_SEG_OP
/*** special lexical tokens ***/
%token <tree> Y_ID
%token <tree> Y_TYPE_NAME
%token <tree> Y_TEMPLATE_NAME
%token <tree> Y_NAMESPACE_NAME
%token <tree> Y_CONSTANT
%token <tree> Y_TRUE
%token <tree> Y_FALSE
%token <tree> Y_STRING
%token <tree> Y_GLOBAL_ID /* ::<id> */
%token <tree> Y_GLOBAL_TYPE_NAME /* ::<type-name> */
%token <tree> Y_GLOBAL_TEMPLATE_NAME /* ::<template-name> */
%token <tree> Y_GLOBAL_NAMESPACE_NAME /* ::<namespace-name> */
%token <tree> Y_GLOBAL_OPERATOR /* ::operator */
%token <tree> Y_GLOBAL_TILDE /* ::~ */
%token <tree> Y_GLOBAL_NEW /* ::new */
%token <tree> Y_GLOBAL_DELETE /* ::delete */
/* Y_SCOPED_* tokens must stay in line with Y_TEMPLATE_SCOPED_* tokens */
%token <tree> Y_SCOPED_ID /* C::<id> */
%token <tree> Y_SCOPED_TYPE_NAME /* C::<type-name> */
%token <tree> Y_SCOPED_TEMPLATE_NAME /* C::<template-name> */
%token <tree> Y_SCOPED_NAMESPACE_NAME /* C::<namespace-name> */
%token <tree> Y_SCOPED_OPERATOR /* C::operator */
%token <tree> Y_SCOPED_TILDE /* C::~ */
%token <tree> Y_SCOPED_TIMES /* C::* */
%token <tree> Y_TEMPLATE_SCOPED_ID /* T<>::<id> */
%token <tree> Y_TEMPLATE_SCOPED_TYPE_NAME/* T<>::<type-name> */
%token <tree> Y_TEMPLATE_SCOPED_TEMPLATE_NAME/* T<>::<template-name> */
%token <tree> Y_TEMPLATE_SCOPED_NAMESPACE_NAME/* T<>::<namespace-name> */
%token <tree> Y_TEMPLATE_SCOPED_OPERATOR/* T<>::operator */
%token <tree> Y_TEMPLATE_SCOPED_TILDE /* T<>::~ */
%token <tree> Y_TEMPLATE_SCOPED_TIMES /* T<>::* */
/*** leader token for "special" parsing ***/
%token Y_EXPRESSION_SPECIAL
%token Y_EXPR_DECL_SPECIAL
%token Y_EXCEPTION_SPECIAL
%token Y_MEM_INIT_SPECIAL
%token Y_DEFARG_SPECIAL
%token Y_TEMPLATE_INT_DEFARG_SPECIAL
%token Y_TEMPLATE_TYPE_DEFARG_SPECIAL
%token Y_CLASS_INST_SPECIAL
/*** terminator tokens for "special" parsing ***/
%token Y_DEFARG_END
%token Y_GT_SPECIAL
/*** tokens that are never generated by yylex() ***/
%token Y_REDUCE_SPECIAL
%token Y_SHIFT_SPECIAL
%token Y_DEFARG_GONE_SPECIAL
%token Y_TEMPLATE_DEFARG_GONE_SPECIAL
%token Y_PURE_FUNCTION_SPECIAL
/*** special function names ***/
%token Y___OFFSETOF
%token Y___TYPEOF
%token Y___BUILTIN_ISFLOAT
/*** PC-specific keywords ***/
%token Y___ASM
%token Y___BASED
%token Y__CDECL
%token Y___CDECL
%token Y___DECLSPEC
%token Y__EXPORT
%token Y___EXPORT
%token Y___FAR
%token Y__FAR16
%token Y___FAR16
%token Y__FASTCALL
%token Y___FASTCALL
%token Y___FORTRAN
%token Y___HUGE
%token Y___INLINE
%token Y___INT64
%token Y___INTERRUPT
%token Y___LOADDS
%token Y___NEAR
%token Y__OPTLINK
%token Y__PACKED
%token Y__PASCAL
%token Y___PASCAL
%token Y___PRAGMA
%token Y___SAVEREGS
%token Y__SEG16
%token Y___SEGMENT
%token Y___SEGNAME
%token Y___SELF
%token Y___STDCALL
%token Y__SYSCALL
%token Y___SYSCALL
%token Y__SYSTEM
%token Y___WATCALL
%token Y___UNALIGNED
%type <flags> modifier
%type <flags> access-specifier
%type <flags> cv-qualifiers-opt
%type <flags> base-qualifiers-opt
%type <flags> segment-cast-opt
%type <flags> packed-class-opt
%type <token> class-key
%type <token> template-typename-key
%type <token> operator-function-type
%type <type> class-mod-opt
%type <type> class-mod-seq
%type <type> class-mod
%type <type> ptr-operator
%type <type> pragma-modifier
%type <type> based-expression
%type <type> ptr-mod
%type <base> base-specifier base-specifier-list
%type <rewrite> ctor-initializer
%type <rewrite> defarg-check
%type <dspec> type-specifiers
%type <dspec> type-specifier
%type <dspec> typeof-specifier
%type <dspec> arg-decl-specifiers
%type <dspec> decl-specifiers
%type <dspec> non-type-decl-specifiers
%type <dspec> non-type-decl-specifier
%type <dspec> no-declarator-declaration
%type <dspec> basic-type-specifier
%type <dspec> simple-type-specifier
%type <dspec> maybe-type-decl-specifiers
%type <dspec> storage-class-specifier
%type <dspec> ms-specific-declspec
%type <dspec> ms-declspec-seq
%type <dspec> function-specifier
%type <dspec> cv-qualifier
%type <dspec> class-specifier
%type <dspec> enum-specifier
%type <dspec> typename-specifier
%type <dspec> class-substance
%type <dspec> class-body
%type <dspec> qualified-type-specifier
%type <dspec> qualified-class-specifier
%type <dspec> qualified-class-type
%type <dspec> template-class-id
%type <dspec> template-class-instantiation
%type <dspec> template-member-class-id
%type <dinfo> function-declaration
%type <dinfo> declarator
%type <dinfo> comma-declarator
%type <dinfo> init-declarator
%type <dinfo> comma-init-declarator
%type <dinfo> ctor-declarator
%type <dinfo> declaring-declarator
%type <dinfo> comma-declaring-declarator
%type <dinfo> actual-declarator
%type <dinfo> ptr-mod-init-declarator
%type <dinfo> ptr-mod-declarator
%type <dinfo> conversion-function-ptr-declarator
%type <dinfo> special-new-abstract-ptr-mod-declarator
%type <dinfo> abstract-ptr-mod-declarator
%type <dinfo> special-new-abstract-declarator
%type <dinfo> abstract-declarator
%type <dinfo> special-new-actual-abstract-declarator
%type <dinfo> actual-abstract-declarator
%type <dinfo> abstract-args
%type <dinfo> simple-arg-declaration
%type <dinfo> arg-declaration
%type <dinfo> template-parameter
%type <dinfo> type-parameter
%type <dinfo> type-parameter-no-defarg
%type <dinfo> arg-declaration-list
%type <dinfo> actual-exception-declaration
%type <dinfo> exception-declaration
%type <dinfo> member-declaring-declarator
%type <dinfo> member-declarator
%type <dinfo> actual-new-declarator
%type <dinfo> partial-ptr-declarator
%type <dinfo> new-declarator
%type <dinfo> new-type-id
%type <dinfo> special-new-type-id
%type <dinfo> dynamic-type-id
%type <dinfo> simple-arg-no-id
%type <tree> declarator-id
%type <tree> conversion-function-type
%type <tree> operator-name
%type <tree> destructor-name
%type <tree> except-spec-opt
%type <tree> expression
%type <tree> expression-before-semicolon
%type <tree> expression-list
%type <tree> expression-list-opt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -