diff --git a/src/language.yacc b/src/language.yacc index daeae72302c9c3a6c95346c567ff0e3c72c26ad0..50fab42f34ca5521e714a626f8645c579b85f555 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: language.yacc,v 1.431 2008/06/16 22:16:53 mast Exp $ +|| $Id: language.yacc,v 1.432 2008/06/18 17:10:32 grubba Exp $ */ %pure_parser @@ -59,6 +59,7 @@ %token TOK_GAUGE %token TOK_GLOBAL %token TOK_IDENTIFIER +%token TOK_RESERVED %token TOK_IF %token TOK_IMPORT %token TOK_INHERIT @@ -291,6 +292,7 @@ int yylex(YYSTYPE *yylval); %type <n> optional_identifier %type <n> implicit_identifier %type <n> TOK_IDENTIFIER +%type <n> TOK_RESERVED %type <n> TOK_VERSION %type <n> attribute %type <n> assoc_pair @@ -606,34 +608,36 @@ constant_name: TOK_IDENTIFIER '=' safe_expr0 if(!is_const($3)) { - if(Pike_compiler->compiler_pass==2) { - int depth = 0; - struct program_state *state = Pike_compiler; - node *n = $3; - while (((n->token == F_COMMA_EXPR) || (n->token == F_ARG_LIST)) && - ((!CAR(n)) ^ (!CDR(n)))) { - if (CAR(n)) n = CAR(n); - else n = CDR(n); - } - if (n->token == F_EXTERNAL) { - while (state && (state->new_program->id != n->u.integer.a)) { - depth++; - state = state->previous; - } - } - if (depth && state) { - /* Alias for a symbol in a surrounding scope. */ - int id = really_low_reference_inherited_identifier(state, 0, - n->u.integer.b); - define_alias($1->u.sval.u.string, n->type, - Pike_compiler->current_modifiers & ~ID_EXTERN, - depth, id); - } else { - yyerror("Constant definition is not constant."); + int depth = 0; + struct program_state *state = Pike_compiler; + node *n = $3; + while (((n->token == F_COMMA_EXPR) || (n->token == F_ARG_LIST)) && + ((!CAR(n)) ^ (!CDR(n)))) { + if (CAR(n)) n = CAR(n); + else n = CDR(n); + } + if (n->token == F_EXTERNAL) { + while (state && (state->new_program->id != n->u.integer.a)) { + depth++; + state = state->previous; } - } else - add_constant($1->u.sval.u.string, 0, + } + if (depth && state) { + /* Alias for a symbol in a surrounding scope. */ + int id = really_low_reference_inherited_identifier(state, 0, + n->u.integer.b); + define_alias($1->u.sval.u.string, n->type, + Pike_compiler->current_modifiers & ~ID_EXTERN, + depth, id); + } else if (Pike_compiler->compiler_pass == 2) { + yyerror("Constant definition is not constant."); + } else { + /* Place holder. */ + push_undefined(); + add_constant($1->u.sval.u.string, Pike_sp-1, Pike_compiler->current_modifiers & ~ID_EXTERN); + pop_stack(); + } } else { if(!Pike_compiler->num_parse_error) { @@ -1297,7 +1301,7 @@ magic_identifiers3: magic_identifiers: magic_identifiers1 | magic_identifiers2 | magic_identifiers3 ; -magic_identifier: TOK_IDENTIFIER +magic_identifier: TOK_IDENTIFIER | TOK_RESERVED | magic_identifiers { struct pike_string *tmp=make_shared_string($1); @@ -3893,6 +3897,14 @@ low_idents: TOK_IDENTIFIER } free_node($1); } + | TOK_RESERVED + { + ref_push_string($1->u.sval.u.string); + low_yyreport(REPORT_ERROR, NULL, 0, parser_system_string, + 1, "Unknown reserved symbol %s."); + free_node($1); + $$ = 0; + } | TOK_PREDEF TOK_COLON_COLON TOK_IDENTIFIER { struct compilation *c = THIS_COMPILATION; @@ -4309,6 +4321,13 @@ bad_identifier: bad_expr_ident { yyerror_reserved("typedef"); } | TOK_VOID_ID { yyerror_reserved("void"); } + | TOK_RESERVED + { + ref_push_string($1->u.sval.u.string); + low_yyreport(REPORT_ERROR, NULL, 0, parser_system_string, + 1, "Unknown reserved symbol %s."); + free_node($1); + } ; bad_expr_ident: diff --git a/src/lexer.h b/src/lexer.h index 34279ac5d067ca7de93e86412cbdfd780fc2bb49..ef1d0bd7b099f94eaeae231b4966036e1690d128 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: lexer.h,v 1.76 2008/05/31 21:17:47 grubba Exp $ +|| $Id: lexer.h,v 1.77 2008/06/18 17:10:32 grubba Exp $ */ /* @@ -603,10 +603,20 @@ static int low_yylex(struct lex *lex, YYSTYPE *yylval) (INDEX_CHARP(buf, 0, SHIFT) != '_') || (INDEX_CHARP(buf, 1, SHIFT) != '_')) break; /* Double underscore before and after is reserved for keywords. */ - push_string(make_shared_binary_pcharp(MKPCHARP(buf, SHIFT), len)); - low_yyreport(REPORT_ERROR, NULL, 0, parser_system_string, - 1, "Unknown reserved symbol %s."); - break; +#if (SHIFT == 0) + struct pike_string *tmp = make_shared_binary_string(buf, len); +#else /* SHIFT != 0 */ +#if (SHIFT == 1) + struct pike_string *tmp = make_shared_binary_string1((p_wchar1 *)buf, + len); +#else /* SHIFT != 1 */ + struct pike_string *tmp = make_shared_binary_string2((p_wchar2 *)buf, + len); +#endif /* SHIFT == 1 */ +#endif /* SHIFT == 0 */ + yylval->n=mkstrnode(tmp); + free_string(tmp); + return TOK_RESERVED; } } {