📄 plusplus.y
字号:
%type <tree> assignment-tree
%type <tree> assignment-expression
%type <tree> assignment-expression-opt
%type <tree> conditional-expression
%type <tree> logical-or-expression
%type <tree> logical-and-expression
%type <tree> inclusive-or-expression
%type <tree> exclusive-or-expression
%type <tree> and-expression
%type <tree> equality-expression
%type <tree> relational-expression
%type <tree> shift-expression
%type <tree> additive-expression
%type <tree> multiplicative-expression
%type <tree> pm-expression
%type <tree> cast-expression
%type <tree> unary-operator
%type <tree> unary-expression
%type <tree> offsetof-field
%type <tree> offsetof-index
%type <tree> new-expression
%type <tree> delete-expression
%type <tree> postfix-expression
%type <tree> primary-expression
%type <tree> id-expression
%type <tree> segment-expression
%type <tree> function-like-cast-expression
%type <tree> qualified-id-expression
%type <tree> member-selection-expression
%type <tree> field-expression
%type <tree> field-name
%type <tree> new-placement
%type <tree> class-name-id
%type <tree> enum-name
%type <tree> make-id
%type <tree> literal
%type <tree> strings pragma-id
%type <tree> type-id-list
%type <tree> type-id
%type <tree> new-initializer-opt
%type <tree> constant-expression
%type <tree> mem-initializer-list
%type <tree> mem-initializer-item
%type <tree> template-argument
%type <tree> template-argument-list-opt
%type <tree> template-argument-list
%type <tree> template-class-pre-instantiation
%type <tree> template-class-pre-id
%type <tree> template-directive-class
%type <tree> raw-qualified-namespace-specifier
%type <tree> expr-decl-stmt
%type <tree> goal-symbol
%nonassoc Y_LEFT_PAREN
%nonassoc Y_FAVOUR_REDUCE_SPECIAL
%start goal-symbol
%%
/* these actions change the token to EOF to force acceptance */
goal-symbol
: Y_EXPRESSION_SPECIAL expression
{
$$ = $2;
t = YYEOFTOKEN;
}
| Y_EXPRESSION_SPECIAL type-specifiers declaring-declarator initializer
{
CheckDeclarationDSpec( state->gstack->u.dspec, GetCurrScope() );
GStackPop( &(state->gstack) );
$$ = $3->id;
$3->id = NULL;
FreeDeclInfo( $3 );
t = YYEOFTOKEN;
}
| Y_EXPR_DECL_SPECIAL expr-decl-stmt
{
$$ = $2;
t = YYEOFTOKEN;
}
| might-restart-declarations
{
t = YYEOFTOKEN;
}
| Y_EXCEPTION_SPECIAL exception-declaration
{
/* treat exception decl like an argument */
$$ = (PTREE) AddArgument( NULL, $2 );
t = YYEOFTOKEN;
}
| Y_MEM_INIT_SPECIAL mem-initializer-list Y_LEFT_BRACE
{
$$ = $2;
t = YYEOFTOKEN;
}
| Y_DEFARG_SPECIAL assignment-expression Y_DEFARG_END
{
$$ = $2;
t = YYEOFTOKEN;
}
| Y_TEMPLATE_INT_DEFARG_SPECIAL logical-or-expression Y_DEFARG_END
{
$$ = $2;
t = YYEOFTOKEN;
}
| Y_TEMPLATE_TYPE_DEFARG_SPECIAL type-id Y_DEFARG_END
{
$$ = $2;
t = YYEOFTOKEN;
}
| Y_CLASS_INST_SPECIAL class-specifier
{
$$ = (PTREE) $2;
t = YYEOFTOKEN;
}
/* I have included this as a stack reset leaves us open to abuse now we fixed bug 218 */
/* All linkage gets reset when we have a syntax error earlier in the file which screws up */
/* closing of the parser. We only issue an error if we have not reported any earlier errors */
/* as this error comes out badly at the end of a file */
| Y_RIGHT_BRACE
{
error_state_t save;
CErrCheckpoint(&save);
if(0 == save){
SetErrLoc( &yylp[1] );
CErr1( ERR_MISPLACED_RIGHT_BRACE );
what = P_DIAGNOSED;
}
}
| /* nothing */
{
what = P_DIAGNOSED;
}
;
lt-special
: lt-special-init Y_LT
;
lt-special-init
: /* nothing */
{
angle_bracket_stack *angle_state;
angle_state = VstkPush( &(state->angle_stack) );
angle_state->paren_depth = 0;
}
;
expr-decl-stmt
: expression-before-semicolon Y_SEMI_COLON
{ $$ = $1; }
| local-declaration
{ $$ = NULL; }
;
expression-before-semicolon
: expression
{
$$ = $1;
if( t != Y_SEMI_COLON ) {
SetErrLoc( &yylocation );
CErr1( ERR_SYNTAX_MISSING_SEMICOLON );
what = P_DIAGNOSED;
}
}
;
/*** expression syntax ***/
constant-expression
: conditional-expression
{ $$ = PTreeNonZeroConstantExpr( $1 ); }
;
expression-list-opt
: /* nothing */
{ $$ = NULL; }
| expression-list
;
expression-list
: assignment-expression
{ $$ = PTreeBinary( CO_LIST, NULL, $1 ); }
| expression-list Y_COMMA assignment-expression
{ $$ = setLocation( PTreeBinary( CO_LIST, $1, $3 ), &yylp[2] ); }
;
expression
: assignment-expression
| expression Y_COMMA assignment-expression
{ $$ = setLocation( PTreeBinary( CO_COMMA, $1, $3 ), &yylp[2] ); }
;
assignment-tree
: Y_EQUAL
{ $$ = setLocation( PTreeBinary( CO_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_TIMES_EQUAL
{ $$ = setLocation( PTreeBinary( CO_TIMES_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_DIVIDE_EQUAL
{ $$ = setLocation( PTreeBinary( CO_DIVIDE_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_PERCENT_EQUAL
{ $$ = setLocation( PTreeBinary( CO_PERCENT_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_PLUS_EQUAL
{ $$ = setLocation( PTreeBinary( CO_PLUS_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_MINUS_EQUAL
{ $$ = setLocation( PTreeBinary( CO_MINUS_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_LSHIFT_EQUAL
{ $$ = setLocation( PTreeBinary( CO_LSHIFT_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_RSHIFT_EQUAL
{ $$ = setLocation( PTreeBinary( CO_RSHIFT_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_OR_EQUAL
{ $$ = setLocation( PTreeBinary( CO_OR_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_AND_EQUAL
{ $$ = setLocation( PTreeBinary( CO_AND_EQUAL, NULL, NULL ), &yylp[1] ); }
| Y_XOR_EQUAL
{ $$ = setLocation( PTreeBinary( CO_XOR_EQUAL, NULL, NULL ), &yylp[1] ); }
;
assignment-expression
: conditional-expression
| logical-or-expression assignment-tree assignment-expression
{
$$ = PTreeReplaceLeft( $2, $1 );
$$ = PTreeReplaceRight( $$, $3 );
}
| Y_THROW assignment-expression-opt
{ $$ = setLocation( PTreeUnary( CO_THROW, $2 ), &yylp[1] ); }
;
assignment-expression-opt
: /* nothing */
{ $$ = NULL; }
| assignment-expression
;
conditional-expression
: logical-or-expression
| logical-or-expression Y_QUESTION expression Y_COLON assignment-expression
{
$3 = setLocation( PTreeBinary( CO_COLON, $3, $5 ), &yylp[4] );
$$ = setLocation( PTreeBinary( CO_QUESTION, $1, $3 ), &yylp[2] );
}
;
logical-or-expression
: logical-and-expression
| logical-or-expression Y_OR_OR logical-and-expression
{ $$ = setLocation( PTreeBinary( CO_OR_OR, $1, $3 ), &yylp[2] ); }
;
logical-and-expression
: inclusive-or-expression
| logical-and-expression Y_AND_AND inclusive-or-expression
{ $$ = setLocation( PTreeBinary( CO_AND_AND, $1, $3 ), &yylp[2] ); }
;
inclusive-or-expression
: exclusive-or-expression
| inclusive-or-expression Y_OR exclusive-or-expression
{ $$ = setLocation( PTreeBinary( CO_OR, $1, $3 ), &yylp[2] ); }
;
exclusive-or-expression
: and-expression
| exclusive-or-expression Y_XOR and-expression
{ $$ = setLocation( PTreeBinary( CO_XOR, $1, $3 ), &yylp[2] ); }
;
and-expression
: equality-expression
| and-expression Y_AND equality-expression
{ $$ = setLocation( PTreeBinary( CO_AND, $1, $3 ), &yylp[2] ); }
;
equality-expression
: relational-expression
| equality-expression Y_EQ relational-expression
{ $$ = setLocation( PTreeBinary( CO_EQ, $1, $3 ), &yylp[2] ); }
| equality-expression Y_NE relational-expression
{ $$ = setLocation( PTreeBinary( CO_NE, $1, $3 ), &yylp[2] ); }
;
relational-expression
: shift-expression
| relational-expression Y_LT shift-expression
{ $$ = setLocation( PTreeBinary( CO_LT, $1, $3 ), &yylp[2] ); }
| relational-expression Y_LE shift-expression
{ $$ = setLocation( PTreeBinary( CO_LE, $1, $3 ), &yylp[2] ); }
| relational-expression Y_GT shift-expression
{ $$ = setLocation( PTreeBinary( CO_GT, $1, $3 ), &yylp[2] ); }
| relational-expression Y_GE shift-expression
{ $$ = setLocation( PTreeBinary( CO_GE, $1, $3 ), &yylp[2] ); }
;
shift-expression
: additive-expression
| shift-expression Y_RSHIFT additive-expression
{ $$ = setLocation( PTreeBinary( CO_RSHIFT, $1, $3 ), &yylp[2] ); }
| shift-expression Y_LSHIFT additive-expression
{ $$ = setLocation( PTreeBinary( CO_LSHIFT, $1, $3 ), &yylp[2] ); }
;
additive-expression
: multiplicative-expression
| additive-expression Y_PLUS multiplicative-expression
{ $$ = setLocation( PTreeBinary( CO_PLUS, $1, $3 ), &yylp[2] ); }
| additive-expression Y_MINUS multiplicative-expression
{ $$ = setLocation( PTreeBinary( CO_MINUS, $1, $3 ), &yylp[2] ); }
;
multiplicative-expression
: pm-expression
| multiplicative-expression Y_TIMES pm-expression
{ $$ = setLocation( PTreeBinary( CO_TIMES, $1, $3 ), &yylp[2] ); }
| multiplicative-expression Y_DIVIDE pm-expression
{ $$ = setLocation( PTreeBinary( CO_DIVIDE, $1, $3 ), &yylp[2] ); }
| multiplicative-expression Y_PERCENT pm-expression
{ $$ = setLocation( PTreeBinary( CO_PERCENT, $1, $3 ), &yylp[2] ); }
;
pm-expression
: segment-expression
| pm-expression Y_DOT_STAR segment-expression
{ $$ = setLocation( PTreeBinary( CO_DOT_STAR, $1, $3 ), &yylp[2] ); }
| pm-expression Y_ARROW_STAR segment-expression
{ $$ = setLocation( PTreeBinary( CO_ARROW_STAR, $1, $3 ), &yylp[2] ); }
;
segment-expression
: cast-expression
| segment-expression Y_SEG_OP cast-expression
{ $$ = setLocation( PTreeBinary( CO_SEG_OP, $1, $3 ), &yylp[2] ); }
;
cast-expression
: unary-expression
| Y_LEFT_PAREN type-id Y_RIGHT_PAREN cast-expression
{ $$ = setLocation( MakeNormalCast( $2, $4 ), &yylp[3] ); }
;
unary-operator
: Y_TIMES
{ $$ = setLocation( PTreeUnary( CO_INDIRECT, NULL ), &yylp[1] ); }
| Y_AND
{ $$ = setLocation( PTreeUnary( CO_ADDR_OF, NULL ), &yylp[1] ); }
| Y_PLUS
{ $$ = setLocation( PTreeUnary( CO_UPLUS, NULL ), &yylp[1] ); }
| Y_MINUS
{ $$ = setLocation( PTreeUnary( CO_UMINUS, NULL ), &yylp[1] ); }
| Y_EXCLAMATION
{ $$ = setLocation( PTreeUnary( CO_EXCLAMATION, NULL ), &yylp[1] ); }
| Y_TILDE
{ $$ = setLocation( PTreeUnary( CO_TILDE, NULL ), &yylp[1] ); }
;
unary-expression
: postfix-expression
| Y_PLUS_PLUS cast-expression
{ $$ = setLocation( PTreeUnary( CO_PRE_PLUS_PLUS, $2 ), &yylp[1] ); }
| Y_MINUS_MINUS cast-expression
{ $$ = setLocation( PTreeUnary( CO_PRE_MINUS_MINUS, $2 ), &yylp[1] ); }
| unary-operator cast-expression
{ $$ = PTreeReplaceLeft( $1, $2 ); }
| Y_SIZEOF unary-expression
{ $$ = setLocation( PTreeUnary( CO_SIZEOF_EXPR, $2 ), &yylp[1] ); }
| Y_SIZEOF Y_LEFT_PAREN type-id Y_RIGHT_PAREN
{ $$ = setLocation( PTreeUnary( CO_SIZEOF_TYPE, $3 ), &yylp[1] ); }
| Y_SIZEOF Y_TYPE_NAME
{ $$ = setLocation( PTreeUnary( CO_SIZEOF_TYPE, PTreeMSSizeofKludge( $2 ) ), &yylp[1] ); }
| Y___BUILTIN_ISFLOAT Y_LEFT_PAREN type-id Y_RIGHT_PAREN
{ $$ = setLocation( MakeBuiltinIsFloat( $3 ), &yylp[1] ); }
| Y___OFFSETOF Y_LEFT_PAREN type-id Y_COMMA offsetof-field Y_RIGHT_PAREN
{ $$ = setLocation( PTreeOffsetof( $3, $5 ), &yylp[4] ); }
| new-expression
| delete-expression
;
offsetof-field
: make-id
{
$$ = PTreeBinary( CO_DOT, $1, NULL );
$$ = PTreeBinary( CO_DOT, NULL, $$ );
}
| make-id offsetof-index
{
$$ = PTreeBinary( CO_DOT, $1, $2 );
$$ = PTreeBinary( CO_DOT, NULL, $$ );
}
| offsetof-field Y_DOT make-id
{
$$ = setLocation( PTreeBinary( CO_DOT, $3, NULL ), &yylp[2] );
$$ = setLocation( PTreeBinary( CO_DOT, $1, $$ ), &yylp[2] );
}
| offsetof-field Y_DOT make-id offsetof-index
{
$$ = setLocation( PTreeBinary( CO_DOT, $3, $4 ), &yylp[2] );
$$ = setLocation( PTreeBinary( CO_DOT, $1, $$ ), &yylp[2] );
}
;
offsetof-index
: Y_LEFT_BRACKET constant-expression Y_RIGHT_BRACKET
{ $$ = setLocation( PTreeBinary( CO_INDEX, NULL, $2 ), &yylp[1] ); }
| offsetof-index Y_LEFT_BRACKET constant-expression Y_RIGHT_BRACKET
{ $$ = setLocation( PTreeBinary( CO_INDEX, $1, $3 ), &yylp[2] ); }
;
new-expression
: Y_NEW new-modifier-opt new-placement new-type-id new-initializer-opt
{ $$ = setLocation( MakeNewExpr( NULL, $3, $4, $5 ), &yylp[1] ); }
| Y_NEW new-modifier-opt new-type-id new-initializer-opt
{ $$ = setLocation( MakeNewExpr( NULL, NULL, $3, $4 ), &yylp[1] ); }
| Y_GLOBAL_NEW new-modifier-opt new-placement new-type-id new-initializer-opt
{ $$ = setLocation( MakeNewExpr( $1, $3, $4, $5 ), &yylp[1] ); }
| Y_GLOBAL_NEW new-modifier-opt new-type-id new-initializer-opt
{ $$ = setLocation( MakeNewExpr( $1, NULL, $3, $4 ), &yylp[1] ); }
;
new-modifier-opt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -