7a08f32000-01-25Henrik Grubbström (Grubba) /* -*- C -*- */
215bed1996-09-28Fredrik Hübinette (Hubbe) /*\ ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License) ||| See the files COPYING and DISCLAIMER for more information. \*/
7a08f32000-01-25Henrik Grubbström (Grubba) /**/
215bed1996-09-28Fredrik Hübinette (Hubbe) %pure_parser
f76b4c2000-05-11Henrik Grubbström (Grubba)  %token TOK_ARROW
215bed1996-09-28Fredrik Hübinette (Hubbe)  /* * Basic value pushing */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_CONSTANT TOK_FLOAT TOK_STRING %token TOK_NUMBER
215bed1996-09-28Fredrik Hübinette (Hubbe) /* * These are the predefined functions that can be accessed from Pike. */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_INC TOK_DEC %token TOK_RETURN
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_EQ TOK_GE TOK_LE TOK_NE %token TOK_NOT %token TOK_LSH TOK_RSH %token TOK_LAND TOK_LOR %token TOK_SWITCH TOK_SSCANF TOK_CATCH %token TOK_FOREACH
215bed1996-09-28Fredrik Hübinette (Hubbe) 
db271d1998-04-27Henrik Grubbström (Grubba) /* This is the end of file marker used by the lexer * to enable nicer EOF in error handling. */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_LEX_EOF %token TOK_ADD_EQ %token TOK_AND_EQ %token TOK_ARRAY_ID %token TOK_BREAK %token TOK_CASE %token TOK_CLASS %token TOK_COLON_COLON %token TOK_CONTINUE %token TOK_DEFAULT %token TOK_DIV_EQ %token TOK_DO %token TOK_DOT_DOT %token TOK_DOT_DOT_DOT %token TOK_ELSE
86dd562001-04-03Henrik Grubbström (Grubba) %token TOK_ENUM
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_EXTERN %token TOK_FLOAT_ID %token TOK_FOR %token TOK_FUNCTION_ID %token TOK_GAUGE %token TOK_IDENTIFIER %token TOK_IF %token TOK_IMPORT %token TOK_INHERIT %token TOK_INLINE %token TOK_LOCAL_ID %token TOK_FINAL_ID %token TOK_INT_ID %token TOK_LAMBDA %token TOK_MULTISET_ID %token TOK_MULTISET_END %token TOK_MULTISET_START %token TOK_LSH_EQ %token TOK_MAPPING_ID %token TOK_MIXED_ID %token TOK_MOD_EQ %token TOK_MULT_EQ %token TOK_NO_MASK %token TOK_OBJECT_ID %token TOK_OR_EQ %token TOK_PRIVATE %token TOK_PROGRAM_ID %token TOK_PROTECTED %token TOK_PREDEF %token TOK_PUBLIC %token TOK_RSH_EQ %token TOK_STATIC %token TOK_STRING_ID %token TOK_SUB_EQ
86dd562001-04-03Henrik Grubbström (Grubba) %token TOK_TYPEDEF
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_TYPEOF
8f733e2000-07-12Henrik Grubbström (Grubba) %token TOK_VARIANT
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_VOID_ID %token TOK_WHILE %token TOK_XOR_EQ %token TOK_OPTIONAL
215bed1996-09-28Fredrik Hübinette (Hubbe)  %right '=' %right '?'
f76b4c2000-05-11Henrik Grubbström (Grubba) %left TOK_LOR %left TOK_LAND
215bed1996-09-28Fredrik Hübinette (Hubbe) %left '|' %left '^' %left '&'
f76b4c2000-05-11Henrik Grubbström (Grubba) %left TOK_EQ TOK_NE %left '>' TOK_GE '<' TOK_LE /* nonassoc? */ %left TOK_LSH TOK_RSH
215bed1996-09-28Fredrik Hübinette (Hubbe) %left '+' '-'
413c8e1996-11-01Fredrik Hübinette (Hubbe) %left '*' '%' '/'
f76b4c2000-05-11Henrik Grubbström (Grubba) %right TOK_NOT '~' %nonassoc TOK_INC TOK_DEC
215bed1996-09-28Fredrik Hübinette (Hubbe)  %{ /* This is the grammar definition of Pike. */ #include "global.h"
d5f07d2001-04-03Henrik Grubbström (Grubba) RCSID("$Id: language.yacc,v 1.226 2001/04/03 12:15:29 grubba Exp $");
215bed1996-09-28Fredrik Hübinette (Hubbe) #ifdef HAVE_MEMORY_H #include <memory.h> #endif #include "interpret.h" #include "array.h" #include "object.h" #include "stralloc.h" #include "las.h" #include "interpret.h" #include "program.h" #include "pike_types.h" #include "constants.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
bb8a782000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) #include "docode.h"
4868db1997-05-07Per Hedbor #include "machine.h"
b9188f1999-12-13Henrik Grubbström (Grubba) #include "main.h"
f76b4c2000-05-11Henrik Grubbström (Grubba) #include "opcodes.h"
86dd562001-04-03Henrik Grubbström (Grubba) #include "operators.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #define YYMAXDEPTH 1000
215bed1996-09-28Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
8c77b61998-04-13Henrik Grubbström (Grubba) #ifndef YYDEBUG /* May also be defined by machine.h */
189fd01997-01-28Fredrik Hübinette (Hubbe) #define YYDEBUG 1
8c77b61998-04-13Henrik Grubbström (Grubba) #endif /* YYDEBUG */
189fd01997-01-28Fredrik Hübinette (Hubbe) #endif
215bed1996-09-28Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe) int add_local_name(struct pike_string *,struct pike_string *,node *); int low_add_local_name(struct compiler_frame *, struct pike_string *,struct pike_string *,node *);
4218011999-01-31Fredrik Hübinette (Hubbe) static node *lexical_islocal(struct pike_string *);
86dd562001-04-03Henrik Grubbström (Grubba) static void safe_inc_enum(void);
215bed1996-09-28Fredrik Hübinette (Hubbe) 
8c64232000-06-26Henrik Grubbström (Grubba) static int inherit_depth; static struct program_state *inherit_state = NULL;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
cd89d71997-09-10Henrik Grubbström (Grubba) /* * Kludge for Bison not using prototypes. */ #ifndef __GNUC__ #ifndef __cplusplus
f5d7042001-01-20Henrik Grubbström (Grubba) static void __yy_memcpy(char *to, char *from, YY_COUNT_TYPE count);
cd89d71997-09-10Henrik Grubbström (Grubba) #endif /* !__cplusplus */ #endif /* !__GNUC__ */
215bed1996-09-28Fredrik Hübinette (Hubbe) %}
e2acf71997-04-23Henrik Grubbström (Grubba) 
215bed1996-09-28Fredrik Hübinette (Hubbe) %union { int number; FLOAT_TYPE fnum; struct node_s *n;
315aa81999-12-17Fredrik Hübinette (Hubbe)  char *str;
215bed1996-09-28Fredrik Hübinette (Hubbe) }
e2acf71997-04-23Henrik Grubbström (Grubba) %{
4b974c1999-02-20Henrik Grubbström (Grubba) /* Needs to be included after YYSTYPE is defined. */ #include "lex.h" %} %{
7ee3801998-11-10Henrik Grubbström (Grubba) /* Include <stdio.h> our selves, so that we can do our magic * without being disturbed... */ #include <stdio.h>
e2acf71997-04-23Henrik Grubbström (Grubba) int yylex(YYSTYPE *yylval);
7ee3801998-11-10Henrik Grubbström (Grubba) /* Bison is stupid, and tries to optimize for space... */ #ifdef YYBISON #define short int #endif /* YYBISON */
e2acf71997-04-23Henrik Grubbström (Grubba) %}
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <fnum> TOK_FLOAT %type <number> TOK_ARRAY_ID %type <number> TOK_BREAK %type <number> TOK_CASE %type <number> TOK_CATCH %type <number> TOK_CONTINUE %type <number> TOK_DEFAULT %type <number> TOK_DO %type <number> TOK_ELSE %type <number> TOK_FLOAT_ID %type <number> TOK_FOR %type <number> TOK_FOREACH %type <number> TOK_FUNCTION_ID %type <number> TOK_GAUGE %type <number> TOK_IF %type <number> TOK_INHERIT %type <number> TOK_INLINE %type <number> TOK_INT_ID %type <number> TOK_LAMBDA %type <number> TOK_LOCAL_ID %type <number> TOK_MAPPING_ID %type <number> TOK_MIXED_ID %type <number> TOK_MULTISET_ID %type <number> TOK_NO_MASK %type <number> TOK_OBJECT_ID %type <number> TOK_PREDEF %type <number> TOK_PRIVATE %type <number> TOK_PROGRAM_ID %type <number> TOK_PROTECTED %type <number> TOK_PUBLIC %type <number> TOK_RETURN %type <number> TOK_SSCANF %type <number> TOK_STATIC %type <number> TOK_STRING_ID %type <number> TOK_SWITCH %type <number> TOK_VOID_ID %type <number> TOK_WHILE
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> arguments %type <number> arguments2
febbc81997-04-22Fredrik Hübinette (Hubbe) %type <number> func_args
c20a522000-07-08Henrik Grubbström (Grubba) %type <number> optional_create_arguments %type <number> create_arguments %type <number> create_arguments2 %type <number> create_arg
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> assign %type <number> modifier %type <number> modifier_list %type <number> modifiers
8c64232000-06-26Henrik Grubbström (Grubba) %type <number> inherit_specifier
cbae7e2000-03-30Henrik Grubbström (Grubba) %type <number> function_type_list %type <number> function_type_list2
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> optional_dot_dot_dot
cbae7e2000-03-30Henrik Grubbström (Grubba) %type <number> optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> optional_stars
215bed1996-09-28Fredrik Hübinette (Hubbe) 
315aa81999-12-17Fredrik Hübinette (Hubbe) %type <str> magic_identifiers %type <str> magic_identifiers1 %type <str> magic_identifiers2 %type <str> magic_identifiers3
8c77b61998-04-13Henrik Grubbström (Grubba) /* The following symbols return type information */
215bed1996-09-28Fredrik Hübinette (Hubbe) 
011ad31999-10-22Fredrik Hübinette (Hubbe) %type <n> number_or_minint %type <n> number_or_maxint
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> cast
1d73ef1999-11-23Henrik Grubbström (Grubba) %type <n> soft_cast
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> simple_type
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> simple_type2 %type <n> simple_identifier_type
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> string_constant %type <n> string
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_STRING %type <n> TOK_NUMBER
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> optional_rename_inherit %type <n> optional_identifier
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> assoc_pair %type <n> block
a30f092000-07-12Fredrik Hübinette (Hubbe) %type <n> optional_block
01d3e21997-04-23Fredrik Hübinette (Hubbe) %type <n> failsafe_block
bb213c1999-12-27Henrik Grubbström (Grubba) %type <n> close_paren_or_missing
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> block_or_semi %type <n> break %type <n> case %type <n> catch %type <n> catch_arg %type <n> class
86dd562001-04-03Henrik Grubbström (Grubba) %type <n> enum
4d21331998-04-14Henrik Grubbström (Grubba) %type <n> safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> comma_expr %type <n> comma_expr2 %type <n> comma_expr_or_maxint %type <n> comma_expr_or_zero %type <n> cond %type <n> continue %type <n> default %type <n> do
998e1f1998-04-15Henrik Grubbström (Grubba) %type <n> safe_expr0
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> expr00 %type <n> expr01 %type <n> expr1 %type <n> expr2 %type <n> expr3 expr0 %type <n> expr4 %type <n> expr_list %type <n> expr_list2 %type <n> for %type <n> for_expr %type <n> foreach %type <n> gauge
d2c6081996-11-07Fredrik Hübinette (Hubbe) %type <n> idents
71d9702000-06-21Henrik Grubbström (Grubba) %type <n> idents2
5a0fd52001-01-10Martin Stjernholm %type <n> labeled_statement
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> lambda %type <n> local_name_list
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> local_name_list2
591c0c1997-01-19Fredrik Hübinette (Hubbe) %type <n> low_idents
998e1f1998-04-15Henrik Grubbström (Grubba) %type <n> safe_lvalue
3ddb531996-11-02Fredrik Hübinette (Hubbe) %type <n> lvalue
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> lvalue_list
2a32691998-01-31Fredrik Hübinette (Hubbe) %type <n> low_lvalue_list
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> m_expr_list %type <n> m_expr_list2 %type <n> new_local_name
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> new_local_name2
5a0fd52001-01-10Martin Stjernholm %type <n> normal_label_statement
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> optional_else_part
5a0fd52001-01-10Martin Stjernholm %type <n> optional_label
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> return %type <n> sscanf %type <n> statement %type <n> statements %type <n> switch %type <n> typeof %type <n> unused %type <n> unused2 %type <n> while
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %type <n> optional_comma_expr
61e9a01998-01-25Fredrik Hübinette (Hubbe) %type <n> low_program_ref
a566ca1999-12-14Fredrik Hübinette (Hubbe) %type <n> local_function %type <n> local_function2
315aa81999-12-17Fredrik Hübinette (Hubbe) %type <n> magic_identifier
86dd562001-04-03Henrik Grubbström (Grubba) %type <n> simple_identifier
215bed1996-09-28Fredrik Hübinette (Hubbe) %%
db271d1998-04-27Henrik Grubbström (Grubba) all: program { YYACCEPT; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | program TOK_LEX_EOF { YYACCEPT; } /* | error TOK_LEX_EOF { YYABORT; } */
8c77b61998-04-13Henrik Grubbström (Grubba)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
9ce6b62000-09-20Henrik Grubbström (Grubba) program: program def | program ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) string_constant: string | string_constant '+' string
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *a,*b; copy_shared_string(a,$1->u.sval.u.string); copy_shared_string(b,$3->u.sval.u.string); free_node($1); free_node($3); a=add_and_free_shared_strings(a,b); $$=mkstrnode(a); free_string(a);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_rename_inherit: ':' TOK_IDENTIFIER { $$=$2; }
8c77b61998-04-13Henrik Grubbström (Grubba)  | ':' bad_identifier { $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | ':' error { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | { $$=0; } ;
d2c6081996-11-07Fredrik Hübinette (Hubbe) 
66c2361998-08-29Henrik Grubbström (Grubba) /* NOTE: This rule pushes a string "name" on the stack in addition * to resolving the program reference. */
61e9a01998-01-25Fredrik Hübinette (Hubbe) low_program_ref: string_constant
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  ref_push_string($1->u.sval.u.string); ref_push_string($1->u.sval.u.string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  ref_push_string(lex.current_file);
10e16f1999-11-04Henrik Grubbström (Grubba)  if (error_handler && error_handler->prog) { ref_push_object(error_handler); SAFE_APPLY_MASTER("handle_inherit", 3); } else { SAFE_APPLY_MASTER("handle_inherit", 2); }
d2c6081996-11-07Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp[-1].type != T_PROGRAM)
66c2361998-08-29Henrik Grubbström (Grubba)  my_yyerror("Couldn't cast string \"%s\" to program", $1->u.sval.u.string->str);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
f077582000-07-06Fredrik Hübinette (Hubbe)  $$=mksvaluenode(Pike_sp-1);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if($$->name) free_string($$->name);
f077582000-07-06Fredrik Hübinette (Hubbe)  add_ref( $$->name=Pike_sp[-2].u.string );
61e9a01998-01-25Fredrik Hübinette (Hubbe)  pop_stack();
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } | idents {
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier)
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  ref_push_string(Pike_compiler->last_identifier);
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  }else{
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_constant_text("");
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  }
61e9a01998-01-25Fredrik Hübinette (Hubbe)  $$=$1; } ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
66c2361998-08-29Henrik Grubbström (Grubba) /* NOTE: Pushes the resolved program on the stack. */
61e9a01998-01-25Fredrik Hübinette (Hubbe) program_ref: low_program_ref {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  resolv_program($1); free_node($1);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } ;
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) inheritance: modifiers TOK_INHERIT low_program_ref optional_rename_inherit ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (($1 & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared inherit."); }
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!(Pike_compiler->new_program->flags & PROGRAM_PASS_1_DONE))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  struct pike_string *s=Pike_sp[-1].u.string;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if($4) s=$4->u.sval.u.string;
61e9a01998-01-25Fredrik Hübinette (Hubbe)  compiler_do_inherit($3,$1,s);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if($4) free_node($4);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  pop_n_elems(1); free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT low_program_ref error ';'
8c77b61998-04-13Henrik Grubbström (Grubba)  { free_node($3); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT low_program_ref error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { free_node($3); yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT low_program_ref error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  { free_node($3); yyerror("Missing ';'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT error ';' { yyerrok; } | modifiers TOK_INHERIT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT error '}' { yyerror("Missing ';'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) import: TOK_IMPORT idents ';'
591c0c1997-01-19Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  resolv_constant($2); free_node($2);
f077582000-07-06Fredrik Hübinette (Hubbe)  use_module(Pike_sp-1);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  pop_stack();
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT string ';'
eb5c901998-04-19Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  ref_push_string($2->u.sval.u.string); free_node($2);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  ref_push_string(lex.current_file);
10e16f1999-11-04Henrik Grubbström (Grubba)  if (error_handler && error_handler->prog) { ref_push_object(error_handler); SAFE_APPLY_MASTER("handle_import", 3); } else { SAFE_APPLY_MASTER("handle_import", 2); }
f077582000-07-06Fredrik Hübinette (Hubbe)  use_module(Pike_sp-1);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  pop_stack(); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT error ';' { yyerrok; } | TOK_IMPORT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT error '}' { yyerror("Missing ';'."); }
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) constant_name: TOK_IDENTIFIER '=' safe_expr0
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { /* This can be made more lenient in the future */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  /* Ugly hack to make sure that $3 is optimized */
b5c9052000-08-19Henrik Grubbström (Grubba)  { int tmp=Pike_compiler->compiler_pass; $3=mknode(F_COMMA_EXPR,$3,0); Pike_compiler->compiler_pass=tmp; }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
019b3d2000-07-09Henrik Grubbström (Grubba)  if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared constant."); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!is_const($3))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass==2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  yyerror("Constant definition is not constant.");
a786431999-11-18Martin Stjernholm  else
019b3d2000-07-09Henrik Grubbström (Grubba)  add_constant($1->u.sval.u.string, 0, Pike_compiler->current_modifiers & ~ID_EXTERN);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } else {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->num_parse_error)
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  {
b5c9052000-08-19Henrik Grubbström (Grubba)  ptrdiff_t tmp=eval_low($3);
57cddc1998-04-19Per Hedbor  if(tmp < 1) { yyerror("Error in constant definition."); }else{
84f8952000-08-16Henrik Grubbström (Grubba)  pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1)));
f077582000-07-06Fredrik Hübinette (Hubbe)  add_constant($1->u.sval.u.string, Pike_sp-1,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers & ~ID_EXTERN);
57cddc1998-04-19Per Hedbor  pop_stack(); }
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if($3) free_node($3);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
998e1f1998-04-15Henrik Grubbström (Grubba)  | bad_identifier '=' safe_expr0 { if ($3) free_node($3); } | error '=' safe_expr0 { if ($3) free_node($3); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ; constant_list: constant_name | constant_list ',' constant_name ;
f76b4c2000-05-11Henrik Grubbström (Grubba) constant: modifiers TOK_CONSTANT constant_list ';' {} | modifiers TOK_CONSTANT error ';' { yyerrok; } | modifiers TOK_CONSTANT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_CONSTANT error '}' { yyerror("Missing ';'."); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) block_or_semi: block {
498ec11999-11-12Henrik Grubbström (Grubba)  $$ = check_node_hash(mknode(F_COMMA_EXPR,$1,mknode(F_RETURN,mkintnode(0),0)));
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
76b4491999-12-09Henrik Grubbström (Grubba)  | ';' { $$ = NULL; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Expected ';'."); $$ = NULL; }
76b4491999-12-09Henrik Grubbström (Grubba)  | error { $$ = NULL; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  type_or_error: simple_type
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG check_type_string(check_node_hash($1)->u.sval.u.string); #endif /* PIKE_DEBUG */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_type) free_string(Pike_compiler->compiler_frame->current_type); copy_shared_string(Pike_compiler->compiler_frame->current_type,$1->u.sval.u.string);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
76b4491999-12-09Henrik Grubbström (Grubba)  close_paren_or_missing: ')'
bb213c1999-12-27Henrik Grubbström (Grubba)  { /* Used to hold line-number info */ $$ = mkintnode(0); }
76b4491999-12-09Henrik Grubbström (Grubba)  | /* empty */ { yyerror("Missing ')'.");
bb213c1999-12-27Henrik Grubbström (Grubba)  /* Used to hold line-number info */ $$ = mkintnode(0);
76b4491999-12-09Henrik Grubbström (Grubba)  } ; close_brace_or_missing: '}' | /* empty */ { yyerror("Missing '}'."); } ; close_bracket_or_missing: ']' | /* empty */ { yyerror("Missing ']'."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba) push_compiler_frame0: /* empty */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8322b62000-05-08Fredrik Hübinette (Hubbe)  push_compiler_frame(SCOPE_LOCAL);
b5aa651999-12-16Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->compiler_frame->previous || !Pike_compiler->compiler_frame->previous->current_type)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Internal compiler fault.");
bad5162000-06-23Fredrik Hübinette (Hubbe)  copy_shared_string(Pike_compiler->compiler_frame->current_type,
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  mixed_type_string); }else{
bad5162000-06-23Fredrik Hübinette (Hubbe)  copy_shared_string(Pike_compiler->compiler_frame->current_type, Pike_compiler->compiler_frame->previous->current_type);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }
3ec3df1999-12-16Henrik Grubbström (Grubba)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) def: modifiers type_or_error optional_stars TOK_IDENTIFIER push_compiler_frame0
76b4491999-12-09Henrik Grubbström (Grubba)  '(' arguments close_paren_or_missing
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e; /* construct the function type */
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($3 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
febbc81997-04-22Fredrik Hübinette (Hubbe)  while(--$3>=0) push_type(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_return_type) free_string(Pike_compiler->compiler_frame->current_return_type); Pike_compiler->compiler_frame->current_return_type=compiler_pop_type();
7e50571996-11-02Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
3ec3df1999-12-16Henrik Grubbström (Grubba)  e=$7-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--;
c3cfe92000-07-10Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } push_type(T_FUNCTION);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
be57ea2000-07-14Henrik Grubbström (Grubba)  int i = isidentifier($4->u.sval.u.string); if (Pike_compiler->compiler_pass == 1) { if ($1 & ID_VARIANT) { /* FIXME: Lookup the type of any existing variant */ /* Or the types. */ fprintf(stderr, "Pass %d: Identifier %s:\n", Pike_compiler->compiler_pass, $4->u.sval.u.string->str); if (i >= 0) { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, i); if (id) { struct pike_string *new_type; fprintf(stderr, "Defined, type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(id->type);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  new_type = or_pike_types(s, id->type, 1); free_string(s); s = new_type; fprintf(stderr, "Resulting type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } else { my_yyerror("Lost identifier %s (%d).", $4->u.sval.u.string->str, i); } } else { fprintf(stderr, "Not defined.\n"); } fprintf(stderr, "New type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } } else { /* FIXME: Second pass reuses the type from the end of * the first pass if this is a variant function. */ if (i >= 0) { if (Pike_compiler->new_program->identifier_references[i].id_flags & ID_VARIANT) { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, i); fprintf(stderr, "Pass %d: Identifier %s:\n", Pike_compiler->compiler_pass, $4->u.sval.u.string->str); free_string(s); copy_shared_string(s, id->type); fprintf(stderr, "Resulting type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } } else { my_yyerror("Identifier %s lost after first pass.", $4->u.sval.u.string->str); } }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $<n>$=mkstrnode(s); free_string(s); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
be57ea2000-07-14Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe) /* if(Pike_compiler->compiler_pass==1) */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
6fd5172000-04-25Fredrik Hübinette (Hubbe)  /* FIXME: * set current_function_number for local functions as well */
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->current_function_number=
6fd5172000-04-25Fredrik Hübinette (Hubbe)  define_function(check_node_hash($4)->u.sval.u.string, check_node_hash($<n>$)->u.sval.u.string, $1 & (~ID_EXTERN), IDENTIFIER_PIKE_FUNCTION,
1ef5572000-08-30Henrik Grubbström (Grubba)  0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);
be57ea2000-07-14Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { fprintf(stderr, "Function number: %d\n", Pike_compiler->compiler_frame->current_function_number); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } block_or_semi { int e;
3ec3df1999-12-16Henrik Grubbström (Grubba)  if($10)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
22edc21998-01-29Fredrik Hübinette (Hubbe)  int f;
b9188f1999-12-13Henrik Grubbström (Grubba)  node *check_args = NULL;
bb213c1999-12-27Henrik Grubbström (Grubba)  int save_line = lex.current_line;
9039702000-08-15Henrik Grubbström (Grubba)  int num_required_args = 0;
1ef5572000-08-30Henrik Grubbström (Grubba)  struct identifier *i;
bb213c1999-12-27Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG struct pike_string *save_file = lex.current_file; lex.current_file = $8->current_file; #endif /* PIKE_DEBUG */ lex.current_line = $8->line_number;
b9188f1999-12-13Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (($1 & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared function definition."); }
3ec3df1999-12-16Henrik Grubbström (Grubba)  for(e=0; e<$7; e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->compiler_frame->variable[e].name || !Pike_compiler->compiler_frame->variable[e].name->len)
b9188f1999-12-13Henrik Grubbström (Grubba)  { my_yyerror("Missing name for argument %d.",e); } else {
9039702000-08-15Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { if ($1 & ID_VARIANT) { struct pike_string *arg_type = Pike_compiler->compiler_frame->variable[e].type; /* FIXME: Generate code that checks the arguments. */ /* If there is a bad argument, call the fallback, and return. */ if (! pike_types_le(void_type_string, arg_type)) { /* Argument my not be void. * ie it's required. */ num_required_args++; } } else { /* FIXME: Should probably use some other flag. */ if ((runtime_options & RUNTIME_CHECK_TYPES) && (Pike_compiler->compiler_frame->variable[e].type != mixed_type_string)) { node *local_node; /* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/ local_node = mklocalnode(e, 0); /* The following is needed to go around the optimization in * mksoftcastnode(). */ free_string(local_node->type); copy_shared_string(local_node->type, mixed_type_string); check_args = mknode(F_COMMA_EXPR, check_args, mksoftcastnode(Pike_compiler->compiler_frame->variable[e].type, local_node)); }
8f733e2000-07-12Henrik Grubbström (Grubba)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
b9188f1999-12-13Henrik Grubbström (Grubba)  } }
9039702000-08-15Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { struct pike_string *bad_arg_str; MAKE_CONSTANT_SHARED_STRING(bad_arg_str, "Bad number of arguments!\n"); fprintf(stderr, "Required args: %d\n", num_required_args); check_args = mknode('?', mkopernode("`<", mkefuncallnode("query_num_arg", NULL), mkintnode(num_required_args)), mknode(':', mkefuncallnode("throw", mkefuncallnode("aggregate", mkstrnode(bad_arg_str))), NULL)); free_string(bad_arg_str); }
b9188f1999-12-13Henrik Grubbström (Grubba)  if (check_args) { /* Prepend the arg checking code. */
3ec3df1999-12-16Henrik Grubbström (Grubba)  $10 = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, check_args, NULL), $10);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
329cc01997-02-17Fredrik Hübinette (Hubbe) 
bb213c1999-12-27Henrik Grubbström (Grubba)  lex.current_line = save_line; #ifdef PIKE_DEBUG lex.current_file = save_file; #endif /* PIKE_DEBUG */
6fd5172000-04-25Fredrik Hübinette (Hubbe)  f=dooptcode(check_node_hash($4)->u.sval.u.string, check_node_hash($10), check_node_hash($<n>9)->u.sval.u.string, $1);
be57ea2000-07-14Henrik Grubbström (Grubba) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i = ID_FROM_INT(Pike_compiler->new_program, f); i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
be57ea2000-07-14Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { fprintf(stderr, "Function number: %d\n", f); }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  if(Pike_interpreter.recoveries && ((Pike_sp - Pike_interpreter.evaluator_stack) < Pike_interpreter.recoveries->stack_pointer))
294dc51997-08-03Fredrik Hübinette (Hubbe)  fatal("Stack error (underflow)\n");
ae95031999-04-07Fredrik Hübinette (Hubbe) 
be57ea2000-07-14Henrik Grubbström (Grubba)  if((Pike_compiler->compiler_pass == 1) && (f != Pike_compiler->compiler_frame->current_function_number)) fatal("define_function screwed up! %d != %d\n", f, Pike_compiler->compiler_frame->current_function_number);
294dc51997-08-03Fredrik Hübinette (Hubbe) #endif
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($4);
bb213c1999-12-27Henrik Grubbström (Grubba)  free_node($8);
3ec3df1999-12-16Henrik Grubbström (Grubba)  free_node($<n>9);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers type_or_error optional_stars TOK_IDENTIFIER push_compiler_frame0
b5aa651999-12-16Henrik Grubbström (Grubba)  error { pop_compiler_frame(); free_node($4);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers type_or_error optional_stars bad_identifier {
4142a61998-05-19Fredrik Hübinette (Hubbe)  free_string(compiler_pop_type());
8c77b61998-04-13Henrik Grubbström (Grubba)  }
33b82c1999-12-19Henrik Grubbström (Grubba)  '(' arguments ')' block_or_semi { if ($9) free_node($9); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | modifiers type_or_error name_list ';' {} | inheritance {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  | import {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | constant {}
121d491996-11-27Fredrik Hübinette (Hubbe)  | class { free_node($1); }
86dd562001-04-03Henrik Grubbström (Grubba)  | enum { free_node($1); } | typedef {}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { reset_type_stack(); yyerror("Missing ';'."); yyerror("Unexpected end of file"); }
07f33e1998-11-05Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); yyerrok;
bad5162000-06-23Fredrik Hübinette (Hubbe) /* if(Pike_compiler->num_parse_error>5) YYACCEPT; */
07f33e1998-11-05Henrik Grubbström (Grubba)  }
2968361998-04-14Henrik Grubbström (Grubba)  | error '}' { reset_type_stack();
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Missing ';'.");
eb5c901998-04-19Fredrik Hübinette (Hubbe)  /* yychar = '}'; */ /* Put the '}' back on the input stream */
2968361998-04-14Henrik Grubbström (Grubba)  }
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | modifiers '{' { $<number>$=lex.pragmas; lex.pragmas|=$1; } program '}' { lex.pragmas=$<number>3; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_dot_dot_dot: TOK_DOT_DOT_DOT { $$=1; }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_DOT_DOT { yyerror("Range indicator ('..') where elipsis ('...') expected."); $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_identifier: TOK_IDENTIFIER
97358e1998-04-23Fredrik Hübinette (Hubbe)  | bad_identifier { $$=0; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) new_arg_name: type7 optional_dot_dot_dot optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs) yyerror("Can't define more arguments after ...");
215bed1996-09-28Fredrik Hübinette (Hubbe) 
7e50571996-11-02Fredrik Hübinette (Hubbe)  if($2) { push_type(T_ARRAY);
c3cfe92000-07-10Henrik Grubbström (Grubba)  Pike_compiler->varargs=1;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!$3)
3c0c281998-01-26Fredrik Hübinette (Hubbe)  { struct pike_string *s; MAKE_CONSTANT_SHARED_STRING(s,""); $3=mkstrnode(s); free_string(s); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
96ab241998-02-28Fredrik Hübinette (Hubbe)  if($3->u.sval.u.string->len &&
fe80612000-09-05Henrik Grubbström (Grubba)  islocal($3->u.sval.u.string) >= 0)
c012391997-03-11Henrik Grubbström (Grubba)  my_yyerror("Variable '%s' appears twice in argument list.",
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $3->u.sval.u.string->str);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($3->u.sval.u.string, compiler_pop_type(),0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
bb213c1999-12-27Henrik Grubbström (Grubba) func_args: '(' arguments close_paren_or_missing { free_node($3); $$=$2; } ;
febbc81997-04-22Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) arguments: /* empty */ optional_comma { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | arguments2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  arguments2: new_arg_name { $$ = 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | arguments2 ',' new_arg_name { $$ = $1 + 1; }
76b4491999-12-09Henrik Grubbström (Grubba)  | arguments2 ':' new_arg_name { yyerror("Unexpected ':' in argument list."); $$ = $1 + 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
a7c3a42000-07-10Henrik Grubbström (Grubba) modifier: TOK_NO_MASK { $$ = ID_NOMASK; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FINAL_ID { $$ = ID_NOMASK; } | TOK_STATIC { $$ = ID_STATIC; } | TOK_EXTERN { $$ = ID_EXTERN; } | TOK_OPTIONAL { $$ = ID_OPTIONAL; } | TOK_PRIVATE { $$ = ID_PRIVATE | ID_STATIC; } | TOK_LOCAL_ID { $$ = ID_INLINE; } | TOK_PUBLIC { $$ = ID_PUBLIC; } | TOK_PROTECTED { $$ = ID_PROTECTED; } | TOK_INLINE { $$ = ID_INLINE; }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { $$ = ID_VARIANT; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
315aa81999-12-17Fredrik Hübinette (Hubbe) magic_identifiers1:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_NO_MASK { $$ = "nomask"; } | TOK_FINAL_ID { $$ = "final"; } | TOK_STATIC { $$ = "static"; }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_EXTERN { $$ = "extern"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PRIVATE { $$ = "private"; } | TOK_LOCAL_ID { $$ = "local"; } | TOK_PUBLIC { $$ = "public"; } | TOK_PROTECTED { $$ = "protected"; } | TOK_INLINE { $$ = "inline"; } | TOK_OPTIONAL { $$ = "optional"; }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { $$ = "variant"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers2:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_VOID_ID { $$ = "void"; } | TOK_MIXED_ID { $$ = "mixed"; } | TOK_ARRAY_ID { $$ = "array"; } | TOK_MAPPING_ID { $$ = "mapping"; } | TOK_MULTISET_ID { $$ = "multiset"; } | TOK_OBJECT_ID { $$ = "object"; } | TOK_FUNCTION_ID { $$ = "function"; } | TOK_PROGRAM_ID { $$ = "program"; } | TOK_STRING_ID { $$ = "string"; } | TOK_FLOAT_ID { $$ = "float"; } | TOK_INT_ID { $$ = "int"; }
86dd562001-04-03Henrik Grubbström (Grubba)  | TOK_ENUM { $$ = "enum"; } | TOK_TYPEDEF { $$ = "typedef"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers3:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_IF { $$ = "if"; } | TOK_DO { $$ = "do"; } | TOK_FOR { $$ = "for"; } | TOK_WHILE { $$ = "while"; } | TOK_ELSE { $$ = "else"; } | TOK_FOREACH { $$ = "foreach"; } | TOK_CATCH { $$ = "catch"; } | TOK_GAUGE { $$ = "gauge"; } | TOK_CLASS { $$ = "class"; } | TOK_BREAK { $$ = "break"; } | TOK_CASE { $$ = "case"; } | TOK_CONSTANT { $$ = "constant"; } | TOK_CONTINUE { $$ = "continue"; } | TOK_DEFAULT { $$ = "default"; } | TOK_IMPORT { $$ = "import"; } | TOK_INHERIT { $$ = "inherit"; } | TOK_LAMBDA { $$ = "lambda"; } | TOK_PREDEF { $$ = "predef"; } | TOK_RETURN { $$ = "return"; } | TOK_SSCANF { $$ = "sscanf"; } | TOK_SWITCH { $$ = "switch"; } | TOK_TYPEOF { $$ = "typeof"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ;
21b2c91999-12-17Fredrik Hübinette (Hubbe) magic_identifiers: magic_identifiers1 | magic_identifiers2 | magic_identifiers3 ;
f76b4c2000-05-11Henrik Grubbström (Grubba) magic_identifier: TOK_IDENTIFIER
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | magic_identifiers
315aa81999-12-17Fredrik Hübinette (Hubbe)  { struct pike_string *tmp=make_shared_string($1); $$=mkstrnode(tmp); free_string(tmp); } ;
1d73ef1999-11-23Henrik Grubbström (Grubba) modifiers: modifier_list {
019b3d2000-07-09Henrik Grubbström (Grubba)  $$=Pike_compiler->current_modifiers=$1 | (lex.pragmas & ID_MODIFIER_MASK);
1d73ef1999-11-23Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  modifier_list: /* empty */ { $$ = 0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | modifier modifier_list { $$ = $1 | $2; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_stars: optional_stars '*' { $$=$1 + 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) cast: '(' type ')' {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mkstrnode(s); free_string(s); }
2e4e451997-02-13Fredrik Hübinette (Hubbe)  ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
1d73ef1999-11-23Henrik Grubbström (Grubba) soft_cast: '[' type ']' { struct pike_string *s=compiler_pop_type(); $$=mkstrnode(s); free_string(s); } ;
86dd562001-04-03Henrik Grubbström (Grubba) full_type: type4 | full_type '*' { if (Pike_compiler->compiler_pass == 2) { yywarning("The *-syntax in types is obsolete. Use array instead."); } push_type(T_ARRAY); } ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) type6: type | identifier_type ;
2e4e451997-02-13Fredrik Hübinette (Hubbe) 
66f7712000-02-17Henrik Grubbström (Grubba) type: type '*' {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 2) {
67abdc2000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
66f7712000-02-17Henrik Grubbström (Grubba)  push_type(T_ARRAY); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | type2 ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
66f7712000-02-17Henrik Grubbström (Grubba) type7: type7 '*' {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 2) {
67abdc2000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
66f7712000-02-17Henrik Grubbström (Grubba)  push_type(T_ARRAY); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | type4 ; simple_type: type4 {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
6bc9281998-04-10Fredrik Hübinette (Hubbe)  $$=mkstrnode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if ($$->u.sval.u.string != s) { fatal("mkstrnode(%p:\"%s\") created node with %p:\"%s\"\n", s, s->str, $$->u.sval.u.string, $$->u.sval.u.string->str); } #endif /* PIKE_DEBUG */
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_string(s); } ; simple_type2: type2 {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
6bc9281998-04-10Fredrik Hübinette (Hubbe)  $$=mkstrnode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if ($$->u.sval.u.string != s) { fatal("mkstrnode(%p:\"%s\") created node with %p:\"%s\"\n", s, s->str, $$->u.sval.u.string, $$->u.sval.u.string->str); } #endif /* PIKE_DEBUG */
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_string(s); } ; simple_identifier_type: identifier_type
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mkstrnode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if ($$->u.sval.u.string != s) { fatal("mkstrnode(%p:\"%s\") created node with %p:\"%s\"\n", s, s->str, $$->u.sval.u.string, $$->u.sval.u.string->str); } #endif /* PIKE_DEBUG */
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_string(s); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) identifier_type: idents
7a08f32000-01-25Henrik Grubbström (Grubba)  { resolv_constant($1);
f077582000-07-06Fredrik Hübinette (Hubbe)  if (Pike_sp[-1].type == T_TYPE) {
7a08f32000-01-25Henrik Grubbström (Grubba)  /* "typedef" */
f077582000-07-06Fredrik Hübinette (Hubbe)  push_finished_type(Pike_sp[-1].u.string);
7a08f32000-01-25Henrik Grubbström (Grubba)  } else { /* object type */ struct program *p = NULL;
f077582000-07-06Fredrik Hübinette (Hubbe)  if (Pike_sp[-1].type == T_OBJECT) { if(!Pike_sp[-1].u.object->prog)
7a08f32000-01-25Henrik Grubbström (Grubba)  { pop_stack(); push_int(0); yyerror("Destructed object used as program identifier."); }else{
97f6282000-03-07Fredrik Hübinette (Hubbe)  extern void f_object_program(INT32);
7a08f32000-01-25Henrik Grubbström (Grubba)  f_object_program(1); } }
f077582000-07-06Fredrik Hübinette (Hubbe)  switch(Pike_sp[-1].type) {
7a08f32000-01-25Henrik Grubbström (Grubba)  case T_FUNCTION:
f077582000-07-06Fredrik Hübinette (Hubbe)  if((p = program_from_function(Pike_sp-1)))
7a08f32000-01-25Henrik Grubbström (Grubba)  break; default:
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass!=1)
7a08f32000-01-25Henrik Grubbström (Grubba)  yyerror("Illegal program identifier."); pop_stack(); push_int(0); break; case T_PROGRAM:
f077582000-07-06Fredrik Hübinette (Hubbe)  p = Pike_sp[-1].u.program;
7a08f32000-01-25Henrik Grubbström (Grubba)  break; } if(p) { push_type_int(p->id); }else{ push_type_int(0); } push_type(0); push_type(T_OBJECT); } pop_stack(); free_node($1); } ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
7e0f821999-11-15Martin Stjernholm type4: type4 '|' type8 { push_type(T_OR); } | type8 ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) type2: type2 '|' type3 { push_type(T_OR); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | type3
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) type3: TOK_INT_ID opt_int_range { push_type(T_INT); } | TOK_FLOAT_ID { push_type(T_FLOAT); } | TOK_PROGRAM_ID { push_type(T_PROGRAM); } | TOK_VOID_ID { push_type(T_VOID); } | TOK_MIXED_ID { push_type(T_MIXED); } | TOK_STRING_ID { push_type(T_STRING); } | TOK_OBJECT_ID opt_object_type { push_type(T_OBJECT); } | TOK_MAPPING_ID opt_mapping_type { push_type(T_MAPPING); } | TOK_ARRAY_ID opt_array_type { push_type(T_ARRAY); } | TOK_MULTISET_ID opt_array_type { push_type(T_MULTISET); } | TOK_FUNCTION_ID opt_function_type { push_type(T_FUNCTION); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
7e0f821999-11-15Martin Stjernholm type8: type3 | identifier_type ;
f5fd531999-03-29Henrik Grubbström (Grubba) number_or_maxint: /* Empty */
8c77b61998-04-13Henrik Grubbström (Grubba)  {
011ad31999-10-22Fredrik Hübinette (Hubbe)  $$ = mkintnode(MAX_INT32);
f5fd531999-03-29Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | '-' TOK_NUMBER
3dc8561999-12-30Henrik Grubbström (Grubba)  { #ifdef PIKE_DEBUG if (($2->token != F_CONSTANT) || ($2->u.sval.type != T_INT)) { fatal("Unexpected number in negative int-range.\n"); } #endif /* PIKE_DEBUG */ $$ = mkintnode(-($2->u.sval.u.integer)); free_node($2); }
f5fd531999-03-29Henrik Grubbström (Grubba)  ; number_or_minint: /* Empty */ {
011ad31999-10-22Fredrik Hübinette (Hubbe)  $$ = mkintnode(MIN_INT32);
f5fd531999-03-29Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | '-' TOK_NUMBER
3dc8561999-12-30Henrik Grubbström (Grubba)  { #ifdef PIKE_DEBUG if (($2->token != F_CONSTANT) || ($2->u.sval.type != T_INT)) { fatal("Unexpected number in negative int-range.\n"); } #endif /* PIKE_DEBUG */ $$ = mkintnode(-($2->u.sval.u.integer)); free_node($2); }
f5fd531999-03-29Henrik Grubbström (Grubba)  ;
a7c3a42000-07-10Henrik Grubbström (Grubba) expected_dot_dot: TOK_DOT_DOT | TOK_DOT_DOT_DOT { yyerror("Elipsis ('...') where range indicator ('..') expected."); } ;
f5fd531999-03-29Henrik Grubbström (Grubba) opt_int_range: /* Empty */ { push_type_int(MAX_INT32); push_type_int(MIN_INT32); }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | '(' number_or_minint expected_dot_dot number_or_maxint ')'
f5fd531999-03-29Henrik Grubbström (Grubba)  { /* FIXME: Check that $4 is >= $2. */
1e00c12000-06-09Martin Stjernholm  if($4->token == F_CONSTANT && $4->u.sval.type == T_INT)
011ad31999-10-22Fredrik Hübinette (Hubbe)  { push_type_int($4->u.sval.u.integer); }else{ push_type_int(MAX_INT32); }
6bbfee1999-11-21Henrik Grubbström (Grubba)  if($2->token == F_CONSTANT && $2->u.sval.type == T_INT)
011ad31999-10-22Fredrik Hübinette (Hubbe)  {
6bbfee1999-11-21Henrik Grubbström (Grubba)  push_type_int($2->u.sval.u.integer);
011ad31999-10-22Fredrik Hübinette (Hubbe)  }else{ push_type_int(MIN_INT32); } free_node($2); free_node($4);
8c77b61998-04-13Henrik Grubbström (Grubba)  }
3803c21998-11-11Henrik Grubbström (Grubba)  ;
8c77b61998-04-13Henrik Grubbström (Grubba) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) opt_object_type: /* Empty */ { push_type_int(0); push_type(0); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | '(' program_ref ')' {
66c2361998-08-29Henrik Grubbström (Grubba)  /* NOTE: On entry, there are two items on the stack:
f077582000-07-06Fredrik Hübinette (Hubbe)  * Pike_sp-2: Name of the program reference (string). * Pike_sp-1: The resolved program (program|function|zero).
66c2361998-08-29Henrik Grubbström (Grubba)  */
f077582000-07-06Fredrik Hübinette (Hubbe)  struct program *p=program_from_svalue(Pike_sp-1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(p)
1532e61996-11-16Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_type_int(p->id);
1532e61996-11-16Fredrik Hübinette (Hubbe)  }else{
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass!=1) {
f077582000-07-06Fredrik Hübinette (Hubbe)  if ((Pike_sp[-2].type == T_STRING) && (Pike_sp[-2].u.string->len > 0) && (Pike_sp[-2].u.string->len < 256)) {
a786431999-11-18Martin Stjernholm  my_yyerror("Not a valid program specifier: '%s'",
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp[-2].u.string->str);
a786431999-11-18Martin Stjernholm  } else { yyerror("Not a valid program specifier."); }
66c2361998-08-29Henrik Grubbström (Grubba)  }
1532e61996-11-16Fredrik Hübinette (Hubbe)  push_type_int(0); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  pop_n_elems(2);
6bc9281998-04-10Fredrik Hübinette (Hubbe)  push_type(0);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) opt_function_type: '('
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_mark(); type_stack_mark(); } function_type_list optional_dot_dot_dot ':' { if ($4) {
7e71da2000-03-30Henrik Grubbström (Grubba)  if ($3) { push_type(T_MANY); type_stack_reverse(); } else { /* function_type_list ends with a comma, or is empty. * FIXME: Should this be a syntax error or not? */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 1) {
6deabd2000-03-30Henrik Grubbström (Grubba)  yyerror("Missing type before ... .");
85fb3d2000-03-30Henrik Grubbström (Grubba)  }
7e71da2000-03-30Henrik Grubbström (Grubba)  type_stack_reverse(); push_type(T_MANY); push_type(T_MIXED);
cbae7e2000-03-30Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{ type_stack_reverse(); push_type(T_MANY); push_type(T_VOID); } type_stack_mark(); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_reverse(); type_stack_reverse(); } | /* empty */ { push_type(T_MIXED);
327c051999-11-24Fredrik Hübinette (Hubbe)  push_type(T_VOID); push_type(T_OR);
2401c72000-01-03Martin Stjernholm  push_type(T_ZERO);
327c051999-11-24Fredrik Hübinette (Hubbe)  push_type(T_VOID); push_type(T_OR);
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MANY); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) function_type_list: /* Empty */ optional_comma { $$=0; } | function_type_list2 optional_comma { $$=!$2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) function_type_list2: type7 { $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | function_type_list2 ',' { type_stack_reverse(); type_stack_mark(); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) opt_array_type: '(' type7 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | { push_type(T_MIXED); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  opt_mapping_type: '('
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_mark(); type_stack_mark(); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7 ':'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_reverse(); type_stack_mark(); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_reverse(); type_stack_reverse(); } ')' | /* empty */ { push_type(T_MIXED); push_type(T_MIXED); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  name_list: new_name
7e50571996-11-02Fredrik Hübinette (Hubbe)  | name_list ',' new_name ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_name: optional_stars TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { struct pike_string *type;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
019b3d2000-07-09Henrik Grubbström (Grubba)  define_variable($2->u.sval.u.string, type, Pike_compiler->current_modifiers);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(type);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier {}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '='
7e50571996-11-02Fredrik Hübinette (Hubbe)  { struct pike_string *type;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
019b3d2000-07-09Henrik Grubbström (Grubba)  if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared variable has initializer."); } $<number>$=define_variable($2->u.sval.u.string, type,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers & (~ID_EXTERN));
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(type); } expr0 {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->init_node=mknode(F_COMMA_EXPR,Pike_compiler->init_node,
7e50571996-11-02Fredrik Hübinette (Hubbe)  mkcastnode(void_type_string, mknode(F_ASSIGN,$5, mkidentifiernode($<number>4))));
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' error
2968361998-04-14Henrik Grubbström (Grubba)  { free_node($2); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("Unexpected end of file in variable definition."); free_node($2); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier '=' expr0 { free_node($4); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_local_name: optional_stars TOK_IDENTIFIER
6bbfee1999-11-21Henrik Grubbström (Grubba)  {
4943aa1998-04-09Fredrik Hübinette (Hubbe)  push_finished_type($<n>0->u.sval.u.string);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string, compiler_pop_type(),0);
1c858f1999-11-14Henrik Grubbström (Grubba)  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($2->u.sval.u.string),0));
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  | optional_stars bad_identifier { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' expr0
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4943aa1998-04-09Fredrik Hübinette (Hubbe)  push_finished_type($<n>0->u.sval.u.string);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string, compiler_pop_type(),0);
4218011999-01-31Fredrik Hübinette (Hubbe)  $$=mknode(F_ASSIGN,$4,mklocalnode(islocal($2->u.sval.u.string),0));
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier '=' expr0 { free_node($4);
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' error
8c77b61998-04-13Henrik Grubbström (Grubba)  { free_node($2); /* No yyerok here since we aren't done yet. */
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("Unexpected end of file in local variable definition."); free_node($2); /* No yyerok here since we aren't done yet. */ $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_local_name2: TOK_IDENTIFIER
6bc9281998-04-10Fredrik Hübinette (Hubbe)  {
e73dae1998-04-17Fredrik Hübinette (Hubbe)  add_ref($<n>0->u.sval.u.string);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string, 0);
1c858f1999-11-14Henrik Grubbström (Grubba)  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($1->u.sval.u.string),0));
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_node($1); }
498ec11999-11-12Henrik Grubbström (Grubba)  | bad_identifier { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' safe_expr0
6bc9281998-04-10Fredrik Hübinette (Hubbe)  {
e73dae1998-04-17Fredrik Hübinette (Hubbe)  add_ref($<n>0->u.sval.u.string);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string, 0);
4218011999-01-31Fredrik Hübinette (Hubbe)  $$=mknode(F_ASSIGN,$3, mklocalnode(islocal($1->u.sval.u.string),0));
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_node($1); }
998e1f1998-04-15Henrik Grubbström (Grubba)  | bad_identifier '=' safe_expr0 { $$=$3; }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) block:'{'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>1=Pike_compiler->num_used_modules; $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level;
120d842000-11-08Fredrik Hübinette (Hubbe)  if($<number>$ == -1) /* if 'first block' */ Pike_compiler->compiler_frame->last_block_level=0; /* all variables */ else Pike_compiler->compiler_frame->last_block_level=$<number>2;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  }
73a2a11998-04-27Henrik Grubbström (Grubba)  statements end_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  unuse_modules(Pike_compiler->num_used_modules - $<number>1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3; $$=$4;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_block: '}'
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing '}'."); yyerror("Unexpected end of file."); } ;
01d3e21997-04-23Fredrik Hübinette (Hubbe) failsafe_block: block
73a2a11998-04-27Henrik Grubbström (Grubba)  | error { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
01d3e21997-04-23Fredrik Hübinette (Hubbe)  ;
a30f092000-07-12Fredrik Hübinette (Hubbe) 
01d3e21997-04-23Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) local_name_list: new_local_name
6126472000-03-02Fredrik Hübinette (Hubbe)  | local_name_list ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_COMMA_EXPR,mkcastnode(void_type_string,$1),$4); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) local_name_list2: new_local_name2
6126472000-03-02Fredrik Hübinette (Hubbe)  | local_name_list2 ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_COMMA_EXPR,mkcastnode(void_type_string,$1),$4); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
f5df592000-10-25Fredrik Hübinette (Hubbe)  local_constant_name: TOK_IDENTIFIER '=' safe_expr0 { struct pike_string *type; /* Ugly hack to make sure that $3 is optimized */ { int tmp=Pike_compiler->compiler_pass; $3=mknode(F_COMMA_EXPR,$3,0); Pike_compiler->compiler_pass=tmp; type=$3->u.node.a->type; } if(!is_const($3)) { if(Pike_compiler->compiler_pass==2) yyerror("Constant definition is not constant."); }else{ ptrdiff_t tmp=eval_low($3); if(tmp < 1) { yyerror("Error in constant definition."); }else{ pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1))); if($3) free_node($3); $3=mksvaluenode(Pike_sp-1); type=$3->type; pop_stack(); } } if(!type) type=mixed_type_string; add_ref(type);
107a0a2001-01-16Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame, /*->previous,*/
f5df592000-10-25Fredrik Hübinette (Hubbe)  $1->u.sval.u.string, type, $3); free_node($1); } | bad_identifier '=' safe_expr0 { if ($3) free_node($3); } | error '=' safe_expr0 { if ($3) free_node($3); } ; local_constant_list: local_constant_name
1070292000-11-04Henrik Grubbström (Grubba)  | local_constant_list ',' local_constant_name
f5df592000-10-25Fredrik Hübinette (Hubbe)  ;
1070292000-11-04Henrik Grubbström (Grubba) local_constant: TOK_CONSTANT local_constant_list ';' | TOK_CONSTANT error ';' { yyerrok; } | TOK_CONSTANT error TOK_LEX_EOF
f5df592000-10-25Fredrik Hübinette (Hubbe)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
1070292000-11-04Henrik Grubbström (Grubba)  | TOK_CONSTANT error '}' { yyerror("Missing ';'."); }
f5df592000-10-25Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) statements: { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | statements statement {
3d78821999-11-06Henrik Grubbström (Grubba)  $$=mknode(F_COMMA_EXPR,$1,mkcastnode(void_type_string,$2));
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f5df592000-10-25Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm normal_label_statement: unused2 ';'
97358e1998-04-23Fredrik Hübinette (Hubbe)  | import { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cond
586b8a1998-04-28Henrik Grubbström (Grubba)  | return expected_semicolon
f5df592000-10-25Fredrik Hübinette (Hubbe)  | local_constant { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | block
586b8a1998-04-28Henrik Grubbström (Grubba)  | break expected_semicolon | continue expected_semicolon
e2acf71997-04-23Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { reset_type_stack(); yyerror("Missing ';'."); yyerror("Unexpected end of file."); $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | error '}' { reset_type_stack();
998e1f1998-04-15Henrik Grubbström (Grubba)  yyerror("Missing ';'.");
eb5c901998-04-19Fredrik Hübinette (Hubbe) /* yychar = '}'; */ /* Put the '}' back on the input stream. */ $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | ';' { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm statement: normal_label_statement { Pike_compiler->compiler_frame->opt_flags &= ~OPT_CUSTOM_LABELS; } | while | do | for | foreach | switch | case | default | labeled_statement ; labeled_statement: TOK_IDENTIFIER { $<number>$ = lex.current_line; Pike_compiler->compiler_frame->opt_flags &= ~OPT_CUSTOM_LABELS; } ':' statement { $$ = mknode(Pike_compiler->compiler_frame->opt_flags & OPT_CUSTOM_LABELS ? F_CUSTOM_STMT_LABEL : F_NORMAL_STMT_LABEL, $1, $4); /* FIXME: This won't be correct if the node happens to be shared. * That's an issue to be solved with shared nodes in general, * though. */ $$->line_number = $<number>2; } ; optional_label: TOK_IDENTIFIER | /* empty */ {$$ = 0;} ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm break: TOK_BREAK optional_label { $$=mknode(F_BREAK,$2,0); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) default: TOK_DEFAULT ':' { $$=mknode(F_DEFAULT,0,0); } | TOK_DEFAULT
4d21331998-04-14Henrik Grubbström (Grubba)  { $$=mknode(F_DEFAULT,0,0); yyerror("Expected ':' after default."); } ;
5a0fd52001-01-10Martin Stjernholm continue: TOK_CONTINUE optional_label { $$=mknode(F_CONTINUE,$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba) push_compiler_frame1: /* empty */
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
8322b62000-05-08Fredrik Hübinette (Hubbe)  push_compiler_frame(SCOPE_LOCAL);
b5aa651999-12-16Henrik Grubbström (Grubba)  } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) lambda: TOK_LAMBDA push_compiler_frame1
b5aa651999-12-16Henrik Grubbström (Grubba)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type) free_string(Pike_compiler->compiler_frame->current_return_type); copy_shared_string(Pike_compiler->compiler_frame->current_return_type,any_type_string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
9039702000-08-15Henrik Grubbström (Grubba)  func_args { $<number>$ = Pike_compiler->varargs; Pike_compiler->varargs = 0; } failsafe_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  { struct pike_string *type; char buf[40];
329cc01997-02-17Fredrik Hübinette (Hubbe)  int f,e;
7e50571996-11-02Fredrik Hübinette (Hubbe)  struct pike_string *name;
9039702000-08-15Henrik Grubbström (Grubba)  debug_malloc_touch($6); $6=mknode(F_COMMA_EXPR,$6,mknode(F_RETURN,mkintnode(0),0)); type=find_return_type($6);
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
b0ef311999-12-14Henrik Grubbström (Grubba)  if(type) {
61e9a01998-01-25Fredrik Hübinette (Hubbe)  push_finished_type(type);
b0ef311999-12-14Henrik Grubbström (Grubba)  free_string(type); } else
61e9a01998-01-25Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  e=$4-1;
9039702000-08-15Henrik Grubbström (Grubba)  if($<number>5)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--; pop_type_stack(); }else{ push_type(T_VOID); }
9039702000-08-15Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MANY); for(; e>=0; e--)
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_FUNCTION);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
22edc21998-01-29Fredrik Hübinette (Hubbe)  sprintf(buf,"__lambda_%ld_%ld",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id, (long)(Pike_compiler->local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */
8267f41998-01-28Fredrik Hübinette (Hubbe)  name=make_shared_string(buf);
c4d4681998-06-06Henrik Grubbström (Grubba)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
c4d4681998-06-06Henrik Grubbström (Grubba) #endif /* LAMBDA_DEBUG */
8267f41998-01-28Fredrik Hübinette (Hubbe)  f=dooptcode(name,
9039702000-08-15Henrik Grubbström (Grubba)  $6,
8267f41998-01-28Fredrik Hübinette (Hubbe)  type,
c6eb961999-12-14Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
22edc21998-01-29Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED) {
498ec11999-11-12Henrik Grubbström (Grubba)  $$ = mktrampolinenode(f); } else { $$ = mkidentifiernode(f); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(name); free_string(type);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LAMBDA push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame();
3857bd2000-11-04Henrik Grubbström (Grubba)  $$ = mkintnode(0);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) local_function: TOK_IDENTIFIER push_compiler_frame1 func_args
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  char buf[40]; struct pike_string *name,*type;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int id,e;
97f6282000-03-07Fredrik Hübinette (Hubbe)  node *n; struct identifier *i=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type) free_string(Pike_compiler->compiler_frame->current_return_type); copy_shared_string(Pike_compiler->compiler_frame->current_return_type,
b5aa651999-12-16Henrik Grubbström (Grubba)  $<n>0->u.sval.u.string);
97f6282000-03-07Fredrik Hübinette (Hubbe) 
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e=$3-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  e--;
c3cfe92000-07-10Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--)
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  push_type(T_FUNCTION); type=compiler_pop_type();
97f6282000-03-07Fredrik Hübinette (Hubbe)  /***/
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  sprintf(buf,"__lambda_%ld_%ld",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id, (long)(Pike_compiler->local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */ name=make_shared_string(buf); id=define_function(name, type, 0, IDENTIFIER_PIKE_FUNCTION,
1ef5572000-08-30Henrik Grubbström (Grubba)  0, OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  n=0; #if 0
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1 && (i=ID_FROM_INT(Pike_compiler->new_program, id)))
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  if(!(i->identifier_flags & IDENTIFIER_SCOPED)) n = mkidentifiernode(id); #endif
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame->previous,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  $1->u.sval.u.string, type, n); $<number>$=id; free_string(name); } failsafe_block { int localid;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>4);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0));
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($5);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  dooptcode(i->name,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $5,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  i->type,
97f6282000-03-07Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  pop_compiler_frame(); free_node($1);
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* WARNING: If the local function adds more variables we are screwed */
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /* WARNING2: if add_local_name stops adding local variables at the end, * this has to be fixed. */
bad5162000-06-23Fredrik Hübinette (Hubbe)  localid=Pike_compiler->compiler_frame->current_number_of_locals-1; if(Pike_compiler->compiler_frame->variable[localid].def)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $$=copy_node(Pike_compiler->compiler_frame->variable[localid].def);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }else{
b6cdf32000-06-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & (SCOPE_SCOPE_USED | SCOPE_SCOPED))
d187072000-06-20Fredrik Hübinette (Hubbe)  { $$ = mknode(F_ASSIGN, mktrampolinenode($<number>3), mklocalnode(localid,0)); }else{ $$ = mknode(F_ASSIGN, mkidentifiernode($<number>3), mklocalnode(localid,0)); }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame();
97f6282000-03-07Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) local_function2: optional_stars TOK_IDENTIFIER push_compiler_frame1 func_args
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  char buf[40]; struct pike_string *name,*type;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int id,e;
97f6282000-03-07Fredrik Hübinette (Hubbe)  node *n; struct identifier *i=0;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  push_finished_type($<n>0->u.sval.u.string);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_return_type) free_string(Pike_compiler->compiler_frame->current_return_type); Pike_compiler->compiler_frame->current_return_type=compiler_pop_type();
97f6282000-03-07Fredrik Hübinette (Hubbe) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e=$4-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e--;
c3cfe92000-07-10Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--)
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  push_type(T_FUNCTION); type=compiler_pop_type(); /***/
97f6282000-03-07Fredrik Hübinette (Hubbe)  sprintf(buf,"__lambda_%ld_%ld",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id, (long)(Pike_compiler->local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */
97f6282000-03-07Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
97f6282000-03-07Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */ name=make_shared_string(buf);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  id=define_function(name, type, 0, IDENTIFIER_PIKE_FUNCTION,
1ef5572000-08-30Henrik Grubbström (Grubba)  0, OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  n=0; #if 0
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1 && (i=ID_FROM_INT(Pike_compiler->new_program, id)))
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  if(!(i->identifier_flags & IDENTIFIER_SCOPED))
97f6282000-03-07Fredrik Hübinette (Hubbe)  n = mkidentifiernode(id);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) #endif
97f6282000-03-07Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame->previous,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $2->u.sval.u.string, type, n); $<number>$=id; free_string(name);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  failsafe_block
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int localid;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>5);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($6); $6=mknode(F_COMMA_EXPR,$6,mknode(F_RETURN,mkintnode(0),0));
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($6);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  dooptcode(i->name,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $6,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  i->type,
97f6282000-03-07Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  pop_compiler_frame(); free_node($2);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* WARNING: If the local function adds more variables we are screwed */
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /* WARNING2: if add_local_name stops adding local variables at the end, * this has to be fixed. */
bad5162000-06-23Fredrik Hübinette (Hubbe)  localid=Pike_compiler->compiler_frame->current_number_of_locals-1; if(Pike_compiler->compiler_frame->variable[localid].def)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $$=copy_node(Pike_compiler->compiler_frame->variable[localid].def);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }else{
b6cdf32000-06-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & (SCOPE_SCOPE_USED | SCOPE_SCOPED))
d187072000-06-20Fredrik Hübinette (Hubbe)  { $$ = mknode(F_ASSIGN, mktrampolinenode($<number>5), mklocalnode(localid,0)); }else{ $$ = mknode(F_ASSIGN, mkidentifiernode($<number>5), mklocalnode(localid,0)); }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame(); free_node($2);
97f6282000-03-07Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  ;
c20a522000-07-08Henrik Grubbström (Grubba) create_arg: modifiers type_or_error optional_stars TOK_IDENTIFIER { struct pike_string *type; push_finished_type(Pike_compiler->compiler_frame->current_type); if ($3 && (Pike_compiler->compiler_pass == 2)) { yywarning("The *-syntax in types is obsolete. Use array instead."); } while($3--) push_type(T_ARRAY); type=compiler_pop_type(); if(islocal($4->u.sval.u.string) >= 0) my_yyerror("Variable '%s' appears twice in create argument list.", $4->u.sval.u.string->str); /* Add the identifier both globally and locally. */
019b3d2000-07-09Henrik Grubbström (Grubba)  define_variable($4->u.sval.u.string, type, Pike_compiler->current_modifiers);
c20a522000-07-08Henrik Grubbström (Grubba)  add_local_name($4->u.sval.u.string, type, 0); /* free_string(type); */ free_node($4); $$=0; } | modifiers type_or_error optional_stars bad_identifier { $$=0; } ; create_arguments2: create_arg { $$ = 1; } | create_arguments2 ',' create_arg { $$ = $1 + 1; } | create_arguments2 ':' create_arg { yyerror("Unexpected ':' in create argument list."); $$ = $1 + 1; } ; create_arguments: /* empty */ optional_comma { $$=0; } | create_arguments2 optional_comma ; push_compiler_frame01: /* empty */ { push_compiler_frame(SCOPE_LOCAL); } ; optional_create_arguments: /* empty */ { $$ = 0; } | '(' push_compiler_frame01 create_arguments close_paren_or_missing { int e; node *create_code = NULL; struct pike_string *type = NULL; struct pike_string *create_string = NULL; int f; MAKE_CONSTANT_SHARED_STRING(create_string, "create"); /* First: Deduce the type for the create() function. */ push_type(T_VOID); /* Return type. */ push_type(T_VOID); /* Not varargs. */ push_type(T_MANY); for(e = $3-1; e>=0; e--) { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); } push_type(T_FUNCTION); type = compiler_pop_type(); /* Second: Declare the function. */ Pike_compiler->compiler_frame->current_function_number= define_function(create_string, type,
1ef5572000-08-30Henrik Grubbström (Grubba)  ID_STATIC, IDENTIFIER_PIKE_FUNCTION, 0, OPT_SIDE_EFFECT);
c20a522000-07-08Henrik Grubbström (Grubba)  /* Third: Generate the initialization code. * * global_arg = [type]local_arg; * [,..] */ for(e=0; e<$3; e++) { if(!Pike_compiler->compiler_frame->variable[e].name || !Pike_compiler->compiler_frame->variable[e].name->len) { my_yyerror("Missing name for argument %d.",e); } else { node *local_node = mklocalnode(e, 0); /* FIXME: Should probably use some other flag. */ if ((runtime_options & RUNTIME_CHECK_TYPES) && (Pike_compiler->compiler_pass == 2) && (Pike_compiler->compiler_frame->variable[e].type != mixed_type_string)) { /* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/ /* The following is needed to go around the optimization in * mksoftcastnode(). */ free_string(local_node->type); copy_shared_string(local_node->type, mixed_type_string); local_node = mksoftcastnode(Pike_compiler->compiler_frame-> variable[e].type, local_node); } create_code = mknode(F_COMMA_EXPR, create_code, mknode(F_ASSIGN, local_node, mkidentifiernode(isidentifier(Pike_compiler-> compiler_frame-> variable[e].name)))); } } /* Fourth: Add a return 0; at the end. */ create_code = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, create_code, NULL), mknode(F_RETURN, mkintnode(0), NULL)); /* Fifth: Define the function. */ f=dooptcode(create_string, check_node_hash(create_code), type, ID_STATIC); #ifdef PIKE_DEBUG if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer) fatal("Stack error (underflow)\n"); if(Pike_compiler->compiler_pass == 1 && f!=Pike_compiler->compiler_frame->current_function_number) fatal("define_function screwed up! %d != %d\n", f, Pike_compiler->compiler_frame->current_function_number); #endif /* Done. */ pop_compiler_frame(); free_node($4); free_string(type); free_string(create_string); } ;
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
586b8a1998-04-28Henrik Grubbström (Grubba) failsafe_program: '{' program end_block
e2acf71997-04-23Henrik Grubbström (Grubba)  | error { yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("End of file where program definition expected."); }
febbc81997-04-22Fredrik Hübinette (Hubbe)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) class: modifiers TOK_CLASS optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
23eecd1999-08-06Fredrik Hübinette (Hubbe)  extern int num_parse_error;
bad5162000-06-23Fredrik Hübinette (Hubbe)  int num_errors=Pike_compiler->num_parse_error;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  if(!$3) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *s;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  char buffer[42];
bad5162000-06-23Fredrik Hübinette (Hubbe)  sprintf(buffer,"__class_%ld_%ld",(long)Pike_compiler->new_program->id,
8c64232000-06-26Henrik Grubbström (Grubba)  (long)Pike_compiler->local_class_counter++);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  s=make_shared_string(buffer); $3=mkstrnode(s); free_string(s);
c6eb961999-12-14Fredrik Hübinette (Hubbe)  $1|=ID_STATIC | ID_PRIVATE | ID_INLINE;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS start\n"); */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass==1)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8fd9311999-12-30Henrik Grubbström (Grubba)  if ($1 & ID_EXTERN) { yywarning("Extern declared class definition."); }
993ba72000-02-15Fredrik Hübinette (Hubbe)  low_start_new_program(0, $3->u.sval.u.string, $1, &$<number>$);
ff88db2000-07-12Henrik Grubbström (Grubba)  /* fprintf(stderr, "Pass 1: Program %s has id %d\n", $3->u.sval.u.string->str, Pike_compiler->new_program->id); */
58ef5e1999-10-19Fredrik Hübinette (Hubbe)  if(lex.current_file) { store_linenumber(lex.current_line, lex.current_file);
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_name(Pike_compiler->new_program, lex.current_file->str,
8fd9311999-12-30Henrik Grubbström (Grubba)  lex.current_line);
58ef5e1999-10-19Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ int i; struct program *p; struct identifier *id;
bad5162000-06-23Fredrik Hübinette (Hubbe)  int tmp=Pike_compiler->compiler_pass;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  i=isidentifier($3->u.sval.u.string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(i<0) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_start_new_program(Pike_compiler->new_program,0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  yyerror("Pass 2: program not defined!"); }else{
bad5162000-06-23Fredrik Hübinette (Hubbe)  id=ID_FROM_INT(Pike_compiler->new_program, i);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { struct svalue *s;
bad5162000-06-23Fredrik Hübinette (Hubbe)  s=&PROG_FROM_INT(Pike_compiler->new_program,i)->constants[id->func.offset].sval;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(s->type==T_PROGRAM) {
993ba72000-02-15Fredrik Hübinette (Hubbe)  low_start_new_program(s->u.program, $3->u.sval.u.string, $1, &$<number>$);
ff88db2000-07-12Henrik Grubbström (Grubba)  /* fprintf(stderr, "Pass 2: Program %s has id %d\n", $3->u.sval.u.string->str, Pike_compiler->new_program->id); */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ yyerror("Pass 2: constant redefined!");
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_start_new_program(Pike_compiler->new_program, 0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }else{ yyerror("Pass 2: class constant no longer constant!");
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_start_new_program(Pike_compiler->new_program, 0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass=tmp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->num_parse_error=num_errors; /* Kluge to prevent gazillion error messages */
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
c20a522000-07-08Henrik Grubbström (Grubba)  optional_create_arguments failsafe_program
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct program *p;
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass == 1)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  p=end_first_pass(0); else
97358e1998-04-23Fredrik Hübinette (Hubbe)  p=end_first_pass(1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS end\n"); */
2401c72000-01-03Martin Stjernholm  if(!p) {
7e50571996-11-02Fredrik Hübinette (Hubbe)  yyerror("Class definition failed.");
993ba72000-02-15Fredrik Hübinette (Hubbe)  }else{
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  free_program(p);
2401c72000-01-03Martin Stjernholm  }
993ba72000-02-15Fredrik Hübinette (Hubbe)  $$=mkidentifiernode($<number>4);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3); check_tree($$,0);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
86dd562001-04-03Henrik Grubbström (Grubba) simple_identifier: TOK_IDENTIFIER | bad_identifier { $$ = 0; } ; enum_value: /* EMPTY */ { safe_inc_enum(); } | '=' safe_expr0 { pop_stack(); /* This can be made more lenient in the future */ /* Ugly hack to make sure that $2 is optimized */ { int tmp=Pike_compiler->compiler_pass; $2=mknode(F_COMMA_EXPR,$2,0); Pike_compiler->compiler_pass=tmp; } if(!is_const($2)) { if(Pike_compiler->compiler_pass==2) yyerror("Enum definition is not constant."); push_int(0); } else { if(!Pike_compiler->num_parse_error) { ptrdiff_t tmp=eval_low($2); if(tmp < 1) { yyerror("Error in enum definition."); push_int(0); }else{ pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1))); } } else { push_int(0); } } if($2) free_node($2); } ; enum_def: /* EMPTY */ | simple_identifier enum_value { if ($1) { add_constant($1->u.sval.u.string, Pike_sp-1,
62ccea2001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
86dd562001-04-03Henrik Grubbström (Grubba)  } free_node($1); /* Update the type. */ { struct pike_type *current = pop_unfinished_type(); struct pike_type *new = get_type_of_svalue(Pike_sp-1); struct pike_type *res = or_pike_types(new, current, 1); free_type(current); free_type(new); type_stack_mark(); push_finished_type(res); } } ; enum_list: enum_def | enum_list ',' enum_def ; enum: modifiers TOK_ENUM { if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) { yywarning("Extern declared enum."); } push_int(-1); /* Last enum-value. */ type_stack_mark(); push_type(T_ZERO); /* Joined type so far. */ } optional_identifier '{' enum_list end_block { struct pike_type *t = pop_unfinished_type(); pop_stack(); if ($4) { ref_push_type_value(t); add_constant($4->u.sval.u.string, Pike_sp-1,
62ccea2001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
86dd562001-04-03Henrik Grubbström (Grubba)  pop_stack(); free_node($4); } $$ = mktypenode(t); free_type(t); } ; typedef: modifiers TOK_TYPEDEF full_type simple_identifier ';' { struct pike_type *t = compiler_pop_type(); if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) { yywarning("Extern declared typedef."); } if ($4) { ref_push_type_value(t); add_constant($4->u.sval.u.string, Pike_sp-1,
d5f07d2001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
86dd562001-04-03Henrik Grubbström (Grubba)  pop_stack(); free_node($4); } free_type(t); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) cond: TOK_IF
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement optional_else_part
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
02a79a2000-09-04Fredrik Hübinette (Hubbe)  $$=mknode('?',$5,mknode(':',$7,$8));
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$->line_number=$1; $$=mkcastnode(void_type_string,$$); $$->line_number=$1;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_cond: ')' | '}' { yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ')'."); yyerror("Unexpected end of file."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) optional_else_part: { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ELSE statement { $$=$2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
998e1f1998-04-15Henrik Grubbström (Grubba) safe_lvalue: lvalue
97358e1998-04-23Fredrik Hübinette (Hubbe)  | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ; safe_expr0: expr0
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
498ec11999-11-12Henrik Grubbström (Grubba)  | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) foreach: TOK_FOREACH
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
902c291998-07-31Fredrik Hübinette (Hubbe)  '(' expr0 ',' safe_lvalue end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
02a79a2000-09-04Fredrik Hübinette (Hubbe)  if ($7) { $$=mknode(F_FOREACH, mknode(F_VAL_LVAL,$5,$7),$9);
998e1f1998-04-15Henrik Grubbström (Grubba)  $$->line_number=$1; } else { /* Error in lvalue */
02a79a2000-09-04Fredrik Hübinette (Hubbe)  free_node($5); $$=$9;
998e1f1998-04-15Henrik Grubbström (Grubba)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) do: TOK_DO statement TOK_WHILE '(' safe_comma_expr end_cond expected_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_DO,$2,$5); $$->line_number=$1;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DO statement TOK_WHILE TOK_LEX_EOF
07f33e1998-11-05Henrik Grubbström (Grubba)  { $$=0; yyerror("Missing '(' in do-while loop."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DO statement TOK_LEX_EOF
07f33e1998-11-05Henrik Grubbström (Grubba)  { $$=0; yyerror("Missing 'while' in do-while loop."); yyerror("Unexpected end of file."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) expected_semicolon: ';'
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) for: TOK_FOR
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' unused expected_semicolon for_expr expected_semicolon unused end_cond statement
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  { int i=lex.current_line; lex.current_line=$1;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string,$5), mknode(F_FOR,$7,mknode(':',$11,$9)));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  lex.current_line=i; pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) while: TOK_WHILE
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  int i=lex.current_line; lex.current_line=$1;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  $$=mknode(F_FOR,$5,mknode(':',$7,NULL));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  lex.current_line=i; pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  for_expr: /* EMPTY */ { $$=mkintnode(1); }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) switch: TOK_SWITCH
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
02a79a2000-09-04Fredrik Hübinette (Hubbe)  $$=mknode(F_SWITCH,$5,$7);
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$->line_number=$1;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
02a79a2000-09-04Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->last_block_level=$<number>3;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) case: TOK_CASE safe_comma_expr expected_colon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_CASE,$2,0); }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_CASE safe_comma_expr expected_dot_dot optional_comma_expr expected_colon
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $$=mknode(F_CASE,$4?$2:0,$4?$4:$2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) expected_colon: ':'
76b4491999-12-09Henrik Grubbström (Grubba)  | ';' { yyerror("Missing ':'."); } | '}' { yyerror("Missing ':'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  {
3d78821999-11-06Henrik Grubbström (Grubba)  yyerror("Missing ':'.");
73a2a11998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) return: TOK_RETURN
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b8cd052000-09-26Fredrik Hübinette (Hubbe)  if(!TEST_COMPAT(0,6) && !match_types(Pike_compiler->compiler_frame->current_return_type,
7e50571996-11-02Fredrik Hübinette (Hubbe)  void_type_string)) { yyerror("Must return a value for a non-void function."); } $$=mknode(F_RETURN,mkintnode(0),0); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_RETURN safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_RETURN,$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  unused: { $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr { $$=mkcastnode(void_type_string,$1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ; unused2: comma_expr { $$=mkcastnode(void_type_string,$1); } ;
ba62cf1997-09-18Fredrik Hübinette (Hubbe) optional_comma_expr: { $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr ; safe_comma_expr: comma_expr
498ec11999-11-12Henrik Grubbström (Grubba)  | error { $$=0; }
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) comma_expr: comma_expr2
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | simple_type2 local_name_list { $$=$2; free_node($1); } | simple_identifier_type local_name_list2 { $$=$2; free_node($1); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  | simple_identifier_type local_function { $$=$2; free_node($1); } | simple_type2 local_function2 { $$=$2; free_node($1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ; comma_expr2: expr0 | comma_expr2 ',' expr0 {
3d78821999-11-06Henrik Grubbström (Grubba)  $$ = mknode(F_COMMA_EXPR,mkcastnode(void_type_string,$1),$3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr00: expr0
7e50571996-11-02Fredrik Hübinette (Hubbe)  | '@' expr0 { $$=mknode(F_PUSH_ARRAY,$2,0); };
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr0: expr01
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr4 '=' expr0 { $$=mknode(F_ASSIGN,$3,$1); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '=' error { $$=$1; reset_type_stack(); yyerrok; }
a663191998-04-17Henrik Grubbström (Grubba)  | bad_expr_ident '=' expr0 { $$=$3; }
2a32691998-01-31Fredrik Hübinette (Hubbe)  | '[' low_lvalue_list ']' '=' expr0 { $$=mknode(F_ASSIGN,$5,mknode(F_ARRAY_LVALUE,$2,0)); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr4 assign expr0 { $$=mknode($2,$1,$3); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 assign error { $$=$1; reset_type_stack(); yyerrok; }
a663191998-04-17Henrik Grubbström (Grubba)  | bad_expr_ident assign expr0 { $$=$3; }
8c77b61998-04-13Henrik Grubbström (Grubba)  | '[' low_lvalue_list ']' assign expr0 { $$=mknode($4,mknode(F_ARRAY_LVALUE,$2,0),$5); }
bdacd91998-04-15Henrik Grubbström (Grubba)  | '[' low_lvalue_list ']' error { $$=$2; reset_type_stack(); yyerrok; }
8c77b61998-04-13Henrik Grubbström (Grubba) /* | error { $$=0; reset_type_stack(); } */
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
97358e1998-04-23Fredrik Hübinette (Hubbe) expr01: expr1
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '?' expr01 ':' expr01 { $$=mknode('?',$1,mknode(':',$3,$5)); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) assign: TOK_AND_EQ { $$=F_AND_EQ; } | TOK_OR_EQ { $$=F_OR_EQ; } | TOK_XOR_EQ { $$=F_XOR_EQ; } | TOK_LSH_EQ { $$=F_LSH_EQ; } | TOK_RSH_EQ { $$=F_RSH_EQ; } | TOK_ADD_EQ { $$=F_ADD_EQ; } | TOK_SUB_EQ { $$=F_SUB_EQ; } | TOK_MULT_EQ{ $$=F_MULT_EQ; } | TOK_MOD_EQ { $$=F_MOD_EQ; } | TOK_DIV_EQ { $$=F_DIV_EQ; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) optional_comma: { $$=0; } | ',' { $$=1; };
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr_list: { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr_list2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr_list2: expr00
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr_list2 ',' expr00 { $$=mknode(F_ARG_LIST,$1,$3); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  m_expr_list: { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | m_expr_list2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  m_expr_list2: assoc_pair
998e1f1998-04-15Henrik Grubbström (Grubba)  | m_expr_list2 ',' assoc_pair { if ($3) { $$=mknode(F_ARG_LIST,$1,$3); } else { /* Error in assoc_pair */ $$=$1; } } | m_expr_list2 ',' error
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
ac87152000-09-25Fredrik Hübinette (Hubbe) assoc_pair: expr0 expected_colon expr0 { $$=mknode(F_ARG_LIST,$1,$3); }
73a2a11998-04-27Henrik Grubbström (Grubba)  | expr0 expected_colon error { free_node($1); $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr1: expr2
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LOR expr1 { $$=mknode(F_LOR,$1,$3); } | expr1 TOK_LAND expr1 { $$=mknode(F_LAND,$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '|' expr1 { $$=mkopernode("`|",$1,$3); } | expr1 '^' expr1 { $$=mkopernode("`^",$1,$3); } | expr1 '&' expr1 { $$=mkopernode("`&",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_EQ expr1 { $$=mkopernode("`==",$1,$3); } | expr1 TOK_NE expr1 { $$=mkopernode("`!=",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '>' expr1 { $$=mkopernode("`>",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_GE expr1 { $$=mkopernode("`>=",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '<' expr1 { $$=mkopernode("`<",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LE expr1 { $$=mkopernode("`<=",$1,$3); } | expr1 TOK_LSH expr1 { $$=mkopernode("`<<",$1,$3); } | expr1 TOK_RSH expr1 { $$=mkopernode("`>>",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '+' expr1 { $$=mkopernode("`+",$1,$3); } | expr1 '-' expr1 { $$=mkopernode("`-",$1,$3); } | expr1 '*' expr1 { $$=mkopernode("`*",$1,$3); } | expr1 '%' expr1 { $$=mkopernode("`%",$1,$3); } | expr1 '/' expr1 { $$=mkopernode("`/",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LOR error | expr1 TOK_LAND error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '|' error | expr1 '^' error | expr1 '&' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_EQ error | expr1 TOK_NE error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '>' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_GE error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '<' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LE error | expr1 TOK_LSH error | expr1 TOK_RSH error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '+' error | expr1 '-' error | expr1 '*' error | expr1 '%' error | expr1 '/' error
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr2: expr3
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cast expr2 {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mkcastnode($1->u.sval.u.string,$2); free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
1d73ef1999-11-23Henrik Grubbström (Grubba)  | soft_cast expr2 { $$=mksoftcastnode($1->u.sval.u.string,$2); free_node($1); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INC expr4 { $$=mknode(F_INC,$2,0); } | TOK_DEC expr4 { $$=mknode(F_DEC,$2,0); } | TOK_NOT expr2 { $$=mkopernode("`!",$2,0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | '~' expr2 { $$=mkopernode("`~",$2,0); } | '-' expr2 { $$=mkopernode("`-",$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr3: expr4
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr4 TOK_INC { $$=mknode(F_POST_INC,$1,0); } | expr4 TOK_DEC { $$=mknode(F_POST_DEC,$1,0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
a30f092000-07-12Fredrik Hübinette (Hubbe) /* FIXMEs * It would be nice if 'return' would exit from * the surrounding function rather than from the * implicit lambda. (I think) So beware that the * behaviour of 'return' might change some day. * -Hubbe * * It would also be nice if it was possible to send * arguments to the implicit function, but it would * require using ugly implicit variables or extending * the syntax, and if you extend the syntax you might * as well use lambda() instead. * -Hubbe * * We might want to allow having more than block after * a function ( ie. func(args) {} {} {} {} ) * -Hubbe */ optional_block: /* EMPTY */ { $$=0; } | '{' push_compiler_frame0 { debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type) free_string(Pike_compiler->compiler_frame->current_return_type); copy_shared_string(Pike_compiler->compiler_frame->current_return_type,any_type_string); /* block code */ $<number>1=Pike_compiler->num_used_modules; $<number>3=Pike_compiler->compiler_frame->current_number_of_locals; } statements end_block { struct pike_string *type; char buf[40]; int f,e; struct pike_string *name; /* block code */ unuse_modules(Pike_compiler->num_used_modules - $<number>1); pop_local_variables($<number>3); debug_malloc_touch($4); $4=mknode(F_COMMA_EXPR,$4,mknode(F_RETURN,mkintnode(0),0)); type=find_return_type($4); if(type) { push_finished_type(type); free_string(type); } else push_type(T_MIXED); push_type(T_VOID); push_type(T_MANY); /* e=$4-1; for(; e>=0; e--) push_finished_type(Pike_compiler->compiler_frame->variable[e].type); */ push_type(T_FUNCTION); type=compiler_pop_type(); sprintf(buf,"__lambda_%ld_%ld", (long)Pike_compiler->new_program->id, (long)(Pike_compiler->local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */ name=make_shared_string(buf); #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: IMPLICIT LAMBDA: %s 0x%08lx 0x%08lx\n", Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1); #endif /* LAMBDA_DEBUG */ f=dooptcode(name, $4, type, ID_STATIC | ID_PRIVATE | ID_INLINE); if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED) { $$ = mktrampolinenode(f); } else { $$ = mkidentifiernode(f); } free_string(name); free_string(type); pop_compiler_frame(); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) expr4: string
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | TOK_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | catch | gauge | typeof | sscanf | lambda | class
86dd562001-04-03Henrik Grubbström (Grubba)  | enum
71d9702000-06-21Henrik Grubbström (Grubba)  | idents2
a30f092000-07-12Fredrik Hübinette (Hubbe)  | expr4 '(' expr_list ')' optional_block { if($5) $3=mknode(F_ARG_LIST, $3, $5); $$=mkapplynode($1,$3); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '(' error ')' { $$=mkapplynode($1, NULL); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr4 '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ')'."); $$=mkapplynode($1, NULL); yyerror("Unexpected end of file."); } | expr4 '(' error ';' { yyerror("Missing ')'."); $$=mkapplynode($1, NULL); } | expr4 '(' error '}' { yyerror("Missing ')'."); $$=mkapplynode($1, NULL); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | expr4 '[' expr0 ']' { $$=mknode(F_INDEX,$1,$3); }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | expr4 '[' comma_expr_or_zero expected_dot_dot comma_expr_or_maxint ']'
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { $$=mknode(F_RANGE,$1,mknode(F_ARG_LIST,$3,$5)); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '[' error ']' { $$=$1; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr4 '[' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { $$=$1; yyerror("Missing ']'."); yyerror("Unexpected end of file."); } | expr4 '[' error ';' { $$=$1; yyerror("Missing ']'."); } | expr4 '[' error '}' { $$=$1; yyerror("Missing ']'."); } | expr4 '[' error ')' { $$=$1; yyerror("Missing ']'."); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | '(' comma_expr2 ')' { $$=$2; }
76b4491999-12-09Henrik Grubbström (Grubba)  | '(' '{' expr_list close_brace_or_missing ')'
42d8c41998-03-04Fredrik Hübinette (Hubbe)  { $$=mkefuncallnode("aggregate",$3); }
76b4491999-12-09Henrik Grubbström (Grubba)  | '(' '[' m_expr_list close_bracket_or_missing ')'
3803c21998-11-11Henrik Grubbström (Grubba)  { $$=mkefuncallnode("aggregate_mapping",$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_START expr_list TOK_MULTISET_END
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { $$=mkefuncallnode("aggregate_multiset",$2); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_START expr_list ')'
76b4491999-12-09Henrik Grubbström (Grubba)  { yyerror("Missing '>'."); $$=mkefuncallnode("aggregate_multiset",$2); }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error ')' { $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error ';' { $$=0; yyerror("Missing ')'."); } | '(' error '}' { $$=0; yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_START error TOK_MULTISET_END { $$=0; yyerrok; } | TOK_MULTISET_START error ')' {
76b4491999-12-09Henrik Grubbström (Grubba)  yyerror("Missing '>'."); $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_START error TOK_LEX_EOF
76b4491999-12-09Henrik Grubbström (Grubba)  { $$=0; yyerror("Missing '>)'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_START error ';' { $$=0; yyerror("Missing '>)'."); } | TOK_MULTISET_START error '}' { $$=0; yyerror("Missing '>)'."); } | expr4 TOK_ARROW magic_identifier
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mknode(F_ARROW,$1,$3);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr4 TOK_ARROW error {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
71d9702000-06-21Henrik Grubbström (Grubba) idents2: idents | TOK_LOCAL_ID TOK_COLON_COLON TOK_IDENTIFIER { int i;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
71d9702000-06-21Henrik Grubbström (Grubba) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if (((i = find_shared_string_identifier(Pike_compiler->last_identifier,
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->new_program)) >= 0) ||
de1d7d2000-07-10Henrik Grubbström (Grubba)  ((i = really_low_find_shared_string_identifier(Pike_compiler->last_identifier,
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->new_program,
71d9702000-06-21Henrik Grubbström (Grubba)  SEE_STATIC| SEE_PRIVATE)) >= 0)) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (!(Pike_compiler->new_program->identifier_references[i].id_flags & ID_HIDDEN)) {
71d9702000-06-21Henrik Grubbström (Grubba)  /* We need to generate a new reference. */ int d;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct reference funp = Pike_compiler->new_program->identifier_references[i];
71d9702000-06-21Henrik Grubbström (Grubba)  funp.id_flags |= ID_HIDDEN; i = -1;
bad5162000-06-23Fredrik Hübinette (Hubbe)  for(d = 0; d < (int)Pike_compiler->new_program->num_identifier_references; d++) {
f077582000-07-06Fredrik Hübinette (Hubbe)  struct reference *refp; refp = Pike_compiler->new_program->identifier_references + d;
71d9702000-06-21Henrik Grubbström (Grubba) 
f077582000-07-06Fredrik Hübinette (Hubbe)  if(!MEMCMP((char *)refp,(char *)&funp,sizeof funp)) {
71d9702000-06-21Henrik Grubbström (Grubba)  i = d; break; } } if (i < 0) { add_to_identifier_references(funp);
bad5162000-06-23Fredrik Hübinette (Hubbe)  i = Pike_compiler->new_program->num_identifier_references - 1;
71d9702000-06-21Henrik Grubbström (Grubba)  } } $$ = mkidentifiernode(i); } else {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (!Pike_compiler->num_parse_error) { if (Pike_compiler->compiler_pass == 2) {
de1d7d2000-07-10Henrik Grubbström (Grubba)  my_yyerror("'%s' not defined in local scope.", Pike_compiler->last_identifier->str);
71d9702000-06-21Henrik Grubbström (Grubba)  $$ = 0; } else { $$ = mknode(F_UNDEFINED, 0, 0); } } else { $$ = mkintnode(0); } } free_node($3); } | TOK_LOCAL_ID TOK_COLON_COLON bad_identifier { $$=0; } ;
591c0c1997-01-19Fredrik Hübinette (Hubbe) idents: low_idents
f76b4c2000-05-11Henrik Grubbström (Grubba)  | idents '.' TOK_IDENTIFIER
591c0c1997-01-19Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  $$=index_node($1, Pike_compiler->last_identifier?Pike_compiler->last_identifier->str:NULL,
fae37d1998-08-30Henrik Grubbström (Grubba)  $3->u.sval.u.string);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  free_node($1);
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | '.' TOK_IDENTIFIER
eb5c901998-04-19Fredrik Hübinette (Hubbe)  { node *tmp; push_text(".");
b47b111998-04-20Henrik Grubbström (Grubba)  ref_push_string(lex.current_file);
10e16f1999-11-04Henrik Grubbström (Grubba)  if (error_handler && error_handler->prog) { ref_push_object(error_handler); SAFE_APPLY_MASTER("handle_import", 3); } else { SAFE_APPLY_MASTER("handle_import", 2); }
f077582000-07-06Fredrik Hübinette (Hubbe)  tmp=mkconstantsvaluenode(Pike_sp-1);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  pop_stack();
fae37d1998-08-30Henrik Grubbström (Grubba)  $$=index_node(tmp, ".", $2->u.sval.u.string);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  free_node(tmp);
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  free_node($2); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | idents '.' bad_identifier {}
4d21331998-04-14Henrik Grubbström (Grubba)  | idents '.' error {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
82e1b72000-06-22Henrik Grubbström (Grubba) inherit_specifier: TOK_IDENTIFIER TOK_COLON_COLON {
8c64232000-06-26Henrik Grubbström (Grubba)  int e = 0;
82e1b72000-06-22Henrik Grubbström (Grubba) 
8c64232000-06-26Henrik Grubbström (Grubba)  inherit_state = Pike_compiler; for (inherit_depth = -1; inherit_depth < compilation_depth; inherit_depth++, inherit_state = inherit_state->previous) {
f077582000-07-06Fredrik Hübinette (Hubbe)  if ((e = find_inherit(inherit_state->new_program, $1->u.sval.u.string)))
8c64232000-06-26Henrik Grubbström (Grubba)  break; } if (!e) { my_yyerror("No such inherit %s.", $1->u.sval.u.string->str);
82e1b72000-06-22Henrik Grubbström (Grubba)  } free_node($1);
8c64232000-06-26Henrik Grubbström (Grubba)  $$ = e;
82e1b72000-06-22Henrik Grubbström (Grubba)  } | inherit_specifier TOK_IDENTIFIER TOK_COLON_COLON { if ($1) {
0b3d0f2000-06-26Henrik Grubbström (Grubba)  int e = 0; #if 0 /* FIXME: The inherit modifiers aren't kept. */ if (!(inherit_state->new_program->inherits[$1].flags & ID_PRIVATE)) { #endif /* 0 */ e = find_inherit(inherit_state->new_program->inherits[$1].prog, $2->u.sval.u.string); #if 0 } #endif /* 0 */
8c64232000-06-26Henrik Grubbström (Grubba)  if (!e) { if (inherit_state->new_program->inherits[$1].name) { my_yyerror("No such inherit %s::%s.", inherit_state->new_program->inherits[$1].name->str, $2->u.sval.u.string->str); } else { my_yyerror("No such inherit %s.", $2->u.sval.u.string->str); }
82e1b72000-06-22Henrik Grubbström (Grubba)  $$ = 0; } else {
8c64232000-06-26Henrik Grubbström (Grubba)  /* We know stuff about the inherit structure... */ $$ = e + $1;
82e1b72000-06-22Henrik Grubbström (Grubba)  } } free_node($2); }
8c64232000-06-26Henrik Grubbström (Grubba)  | inherit_specifier bad_identifier TOK_COLON_COLON { $$ = 0; }
82e1b72000-06-22Henrik Grubbström (Grubba)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) low_idents: TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int i; struct efun *f;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $1->u.sval.u.string);
4218011999-01-31Fredrik Hübinette (Hubbe) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(($$=lexical_islocal(Pike_compiler->last_identifier)))
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  /* done, nothing to do here */
de1d7d2000-07-10Henrik Grubbström (Grubba)  }else if((i=isidentifier(Pike_compiler->last_identifier))>=0){
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=mkidentifiernode(i);
de1d7d2000-07-10Henrik Grubbström (Grubba)  }else if(!($$=find_module_identifier(Pike_compiler->last_identifier,1))){
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->num_parse_error)
dffa011997-01-15Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass==2)
97358e1998-04-23Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  my_yyerror("'%s' undefined.", Pike_compiler->last_identifier->str);
97358e1998-04-23Fredrik Hübinette (Hubbe)  $$=0; }else{ $$=mknode(F_UNDEFINED,0,0); } }else{
1c858f1999-11-14Henrik Grubbström (Grubba)  $$=mkintnode(0);
dffa011997-01-15Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF TOK_COLON_COLON TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
45e8a81997-01-26Fredrik Hübinette (Hubbe)  node *tmp2;
ac87152000-09-25Fredrik Hübinette (Hubbe)  extern dynamic_buffer used_modules;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
ac87152000-09-25Fredrik Hübinette (Hubbe)  tmp2=mkconstantsvaluenode((struct svalue *) used_modules.s.str );
fae37d1998-08-30Henrik Grubbström (Grubba)  $$=index_node(tmp2, "predef", $3->u.sval.u.string);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if(!$$->name) add_ref( $$->name=$3->u.sval.u.string );
45e8a81997-01-26Fredrik Hübinette (Hubbe)  free_node(tmp2);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF TOK_COLON_COLON bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
82e1b72000-06-22Henrik Grubbström (Grubba)  | inherit_specifier TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
8c64232000-06-26Henrik Grubbström (Grubba)  if ($1) { int id;
fae37d1998-08-30Henrik Grubbström (Grubba) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
a005eb1999-03-04Fredrik Hübinette (Hubbe) 
8c64232000-06-26Henrik Grubbström (Grubba)  id = low_reference_inherited_identifier(inherit_state, $1,
de1d7d2000-07-10Henrik Grubbström (Grubba)  Pike_compiler->last_identifier,
8c64232000-06-26Henrik Grubbström (Grubba)  SEE_STATIC); if (id != -1) { if (inherit_depth >= 0) {
ff88db2000-07-12Henrik Grubbström (Grubba)  $$ = mkexternalnode(inherit_state->new_program, id);
8c64232000-06-26Henrik Grubbström (Grubba)  } else { $$ = mkidentifiernode(id); }
de1d7d2000-07-10Henrik Grubbström (Grubba)  } else if(ISCONSTSTR(Pike_compiler->last_identifier, "`->") || ISCONSTSTR(Pike_compiler->last_identifier, "`[]")) {
8c64232000-06-26Henrik Grubbström (Grubba)  $$ = mknode(F_MAGIC_INDEX, mknewintnode($1), mknewintnode(inherit_depth+1));
de1d7d2000-07-10Henrik Grubbström (Grubba)  } else if(ISCONSTSTR(Pike_compiler->last_identifier, "`->=") || ISCONSTSTR(Pike_compiler->last_identifier, "`[]=")) {
8c64232000-06-26Henrik Grubbström (Grubba)  $$ = mknode(F_MAGIC_SET_INDEX, mknewintnode($1), mknewintnode(inherit_depth+1)); } else { if (inherit_state->new_program->inherits[$1].name) { my_yyerror("Undefined identifier %s::%s.", inherit_state->new_program->inherits[$1].name->str,
de1d7d2000-07-10Henrik Grubbström (Grubba)  Pike_compiler->last_identifier->str);
8c64232000-06-26Henrik Grubbström (Grubba)  } else {
de1d7d2000-07-10Henrik Grubbström (Grubba)  my_yyerror("Undefined identifier %s.", Pike_compiler->last_identifier->str);
8c64232000-06-26Henrik Grubbström (Grubba)  } $$=0; } } else {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
82e1b72000-06-22Henrik Grubbström (Grubba)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c64232000-06-26Henrik Grubbström (Grubba)  | inherit_specifier bad_identifier { $$=0; } | inherit_specifier error { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_COLON_COLON TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e,i;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
fae37d1998-08-30Henrik Grubbström (Grubba) 
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  for(e=1;e<(int)Pike_compiler->new_program->num_inherits;e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->new_program->inherits[e].inherit_level!=1) continue;
8aae6d1999-08-19Fredrik Hübinette (Hubbe)  i=low_reference_inherited_identifier(0,e,$2->u.sval.u.string,SEE_STATIC);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  if(i==-1) continue; if($$) { $$=mknode(F_ARG_LIST,$$,mkidentifiernode(i)); }else{ $$=mkidentifiernode(i); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } if(!$$) {
a5787d1999-03-03Fredrik Hübinette (Hubbe)  if(ISCONSTSTR($2->u.sval.u.string,"`->") || ISCONSTSTR($2->u.sval.u.string,"`[]") ) {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=mknode(F_MAGIC_INDEX,mknewintnode(0),mknewintnode(0));
a5787d1999-03-03Fredrik Hübinette (Hubbe)  } else if(ISCONSTSTR($2->u.sval.u.string,"`->=") || ISCONSTSTR($2->u.sval.u.string,"`[]=") ) {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=mknode(F_MAGIC_SET_INDEX,mknewintnode(0),mknewintnode(0));
a5787d1999-03-03Fredrik Hübinette (Hubbe)  } else {
1c858f1999-11-14Henrik Grubbström (Grubba)  $$=mkintnode(0);
a5787d1999-03-03Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{
45e8a81997-01-26Fredrik Hübinette (Hubbe)  if($$->token==F_ARG_LIST) $$=mkefuncallnode("aggregate",$$);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_COLON_COLON bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
1c858f1999-11-14Henrik Grubbström (Grubba) comma_expr_or_zero: /* empty */ { $$=mkintnode(0); }
55356e1999-05-26Fredrik Hübinette (Hubbe)  | comma_expr
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
1c858f1999-11-14Henrik Grubbström (Grubba) comma_expr_or_maxint: /* empty */ { $$=mkintnode(0x7fffffff); }
55356e1999-05-26Fredrik Hübinette (Hubbe)  | comma_expr
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=mkintnode(0x7fffffff); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) gauge: TOK_GAUGE catch_arg
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
4868db1997-05-07Per Hedbor #ifdef HAVE_GETHRVTIME
ee2f201999-10-10Fredrik Noring  $$=mkefuncallnode("abs",
4868db1997-05-07Per Hedbor  mkopernode("`/", mkopernode("`-", mkefuncallnode("gethrvtime",0),
3d78821999-11-06Henrik Grubbström (Grubba)  mknode(F_COMMA_EXPR,$2,
4868db1997-05-07Per Hedbor  mkefuncallnode("gethrvtime",0))),
ee2f201999-10-10Fredrik Noring  mkfloatnode((FLOAT_TYPE)1000000.0)));
4868db1997-05-07Per Hedbor #else
ee2f201999-10-10Fredrik Noring  $$=mkefuncallnode("abs", mkopernode("`/", mkopernode("`-", mknode(F_INDEX,mkefuncallnode("rusage",0), mkintnode(GAUGE_RUSAGE_INDEX)),
3d78821999-11-06Henrik Grubbström (Grubba)  mknode(F_COMMA_EXPR,$2,
ee2f201999-10-10Fredrik Noring  mknode(F_INDEX,mkefuncallnode("rusage",0), mkintnode(GAUGE_RUSAGE_INDEX)))), mkfloatnode((FLOAT_TYPE)1000.0)));
4868db1997-05-07Per Hedbor #endif };
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) typeof: TOK_TYPEOF '(' expr0 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *s;
7e50571996-11-02Fredrik Hübinette (Hubbe)  node *tmp;
3d78821999-11-06Henrik Grubbström (Grubba)  /* FIXME: Why build the node at all? */
ac87152000-09-25Fredrik Hübinette (Hubbe)  /* Because the optimizer cannot optimize the root node of the * tree properly -Hubbe */
b98c612000-05-17Henrik Grubbström (Grubba)  tmp=mknode(F_COMMA_EXPR, $3, 0);
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
b98c612000-05-17Henrik Grubbström (Grubba)  s=(tmp && CAR(tmp) && CAR(tmp)->type ? CAR(tmp)->type : mixed_type_string);
ac87152000-09-25Fredrik Hübinette (Hubbe)  if(TEST_COMPAT(7,0)) { s=describe_type(s); $$ = mkstrnode(s); free_string(s); }else{ $$ = mktypenode(s); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_node(tmp);
4d21331998-04-14Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF '(' error ')' { $$=0; yyerrok; } | TOK_TYPEOF '(' error '}' { $$=0; yyerror("Missing ')'."); } | TOK_TYPEOF '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF '(' error ';' { $$=0; yyerror("Missing ')'."); }
4d21331998-04-14Henrik Grubbström (Grubba)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) catch_arg: '(' comma_expr ')' { $$=$2; }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error ')' { $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error '}' { $$=0; yyerror("Missing ')'."); } | '(' error ';' { $$=0; yyerror("Missing ')'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | block
4cb7d91999-12-10Henrik Grubbström (Grubba)  | error { $$=0; yyerror("Bad expression for catch."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) catch: TOK_CATCH
9649491998-02-27Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->catch_level++;
9649491998-02-27Fredrik Hübinette (Hubbe)  } catch_arg { $$=mknode(F_CATCH,$3,NULL);
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->catch_level--;
4d21331998-04-14Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) sscanf: TOK_SSCANF '(' expr0 ',' expr0 lvalue_list ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_SSCANF,mknode(F_ARG_LIST,$3,$5),$6); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error ')'
4d21331998-04-14Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error ';'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error ')'
4d21331998-04-14Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error ';'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' error ')' { $$=0; yyerrok; } | TOK_SSCANF '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' error '}' { $$=0; yyerror("Missing ')'."); } | TOK_SSCANF '(' error ';' { $$=0; yyerror("Missing ')'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3ddb531996-11-02Fredrik Hübinette (Hubbe) lvalue: expr4
2a32691998-01-31Fredrik Hübinette (Hubbe)  | '[' low_lvalue_list ']' { $$=mknode(F_ARRAY_LVALUE, $2,0); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | type6 TOK_IDENTIFIER
3ddb531996-11-02Fredrik Hübinette (Hubbe)  {
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string,compiler_pop_type(),0);
4218011999-01-31Fredrik Hübinette (Hubbe)  $$=mklocalnode(islocal($2->u.sval.u.string),0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
3ddb531996-11-02Fredrik Hübinette (Hubbe)  }
1d73ef1999-11-23Henrik Grubbström (Grubba)  | bad_expr_ident
498ec11999-11-12Henrik Grubbström (Grubba)  { $$=mknewintnode(0); }
39245b1998-04-17Henrik Grubbström (Grubba)  ;
bdacd91998-04-15Henrik Grubbström (Grubba) low_lvalue_list: lvalue lvalue_list { $$=mknode(F_LVALUE_LIST,$1,$2); }
2a32691998-01-31Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) lvalue_list: /* empty */ { $$ = 0; }
3ddb531996-11-02Fredrik Hübinette (Hubbe)  | ',' lvalue lvalue_list { $$ = mknode(F_LVALUE_LIST,$2,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) string: TOK_STRING | string TOK_STRING
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *a,*b; copy_shared_string(a,$1->u.sval.u.string); copy_shared_string(b,$2->u.sval.u.string); free_node($1); free_node($2); a=add_and_free_shared_strings(a,b); $$=mkstrnode(a); free_string(a);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
8c77b61998-04-13Henrik Grubbström (Grubba) /* * Some error-handling */
de1d7d2000-07-10Henrik Grubbström (Grubba) /* FIXME: Should probably set Pike_compiler->last_identifier. */
1d73ef1999-11-23Henrik Grubbström (Grubba) bad_identifier: bad_expr_ident
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CLASS
39245b1998-04-17Henrik Grubbström (Grubba)  { yyerror("class is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ARRAY_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("array is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FLOAT_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("float is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FUNCTION_ID
39245b1998-04-17Henrik Grubbström (Grubba)  { yyerror("function is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INT_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("int is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MAPPING_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("mapping is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MIXED_ID
39245b1998-04-17Henrik Grubbström (Grubba)  { yyerror("mixed is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("multiset is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OBJECT_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("object is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROGRAM_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("program is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STRING_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("string is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_VOID_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("void is a reserved word."); }
a663191998-04-17Henrik Grubbström (Grubba)  ; bad_expr_ident:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_INLINE
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("inline is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LOCAL_ID
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("local is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NO_MASK
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("nomask is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("predef is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PRIVATE
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("private is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROTECTED
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("protected is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PUBLIC
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("public is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OPTIONAL
21b2c91999-12-17Fredrik Hübinette (Hubbe)  { yyerror("optional is a reserved word."); }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { yyerror("variant is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STATIC
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("static is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_EXTERN
1c379c1999-12-30Henrik Grubbström (Grubba)  { yyerror("extern is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FINAL_ID
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("final is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DO
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("do is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ELSE
2a7c7c1999-07-18Fredrik Hübinette (Hubbe)  { yyerror("else without if."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_RETURN
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("return is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("import is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INHERIT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("inherit is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CATCH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("catch is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_GAUGE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("gauge is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LAMBDA
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("lambda is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("sscanf is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SWITCH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("switch is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("typeof is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_BREAK
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("break is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CASE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("case is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CONTINUE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("continue is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DEFAULT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("default is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOR
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("for is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOREACH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("foreach is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("if is a reserved word."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) %% void yyerror(char *str) { extern int num_parse_error;
523e641996-12-10David Hedbor  extern int cumulative_parse_error;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer)
294dc51997-08-03Fredrik Hübinette (Hubbe)  fatal("Stack error (underflow)\n"); #endif
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->num_parse_error > 10) return; Pike_compiler->num_parse_error++;
c3c7031996-12-04Fredrik Hübinette (Hubbe)  cumulative_parse_error++;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
10e16f1999-11-04Henrik Grubbström (Grubba)  if ((error_handler && error_handler->prog) || get_master())
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
52b45e1999-06-20Henrik Grubbström (Grubba)  if (lex.current_file) { ref_push_string(lex.current_file); } else { /* yyerror() can be called from define_function(), which * can be called by the C module initialization code. */ push_constant_text(""); }
2416d81998-01-27Fredrik Hübinette (Hubbe)  push_int(lex.current_line); push_text(str);
10e16f1999-11-04Henrik Grubbström (Grubba)  if (error_handler && error_handler->prog) { safe_apply(error_handler, "compile_error", 3); } else { SAFE_APPLY_MASTER("compile_error", 3); }
215bed1996-09-28Fredrik Hübinette (Hubbe)  pop_stack(); }else{
52b45e1999-06-20Henrik Grubbström (Grubba)  if (lex.current_file) { (void)fprintf(stderr, "%s:%ld: %s\n", lex.current_file->str, (long)lex.current_line, str); } else { (void)fprintf(stderr, "NULL:%ld: %s\n", (long)lex.current_line, str); }
215bed1996-09-28Fredrik Hübinette (Hubbe)  fflush(stderr); } }
120d842000-11-08Fredrik Hübinette (Hubbe) static int low_islocal(struct compiler_frame *f, struct pike_string *str) { int e; for(e=f->current_number_of_locals-1;e>=0;e--) if(f->variable[e].name==str) return e; return -1; }
97f6282000-03-07Fredrik Hübinette (Hubbe)  int low_add_local_name(struct compiler_frame *frame, struct pike_string *str, struct pike_string *type, node *def)
215bed1996-09-28Fredrik Hübinette (Hubbe) {
ac87152000-09-25Fredrik Hübinette (Hubbe)  if (str->len && !TEST_COMPAT(7,0)) {
120d842000-11-08Fredrik Hübinette (Hubbe)  int tmp=low_islocal(frame,str); if(tmp>=0 && tmp >= frame->last_block_level)
fe80612000-09-05Henrik Grubbström (Grubba)  { if(str->size_shift) my_yyerror("Duplicate local variable, " "previous declaration on line %d\n", frame->variable[tmp].line); else my_yyerror("Duplicate local variable '%s', " "previous declaration on line %d\n", STR0(str), frame->variable[tmp].line); }
f8a4be2000-10-03Fredrik Hübinette (Hubbe)  if(type == void_type_string) { if(str->size_shift) my_yyerror("Local variables cannot be of type of 'void'.\n"); else my_yyerror("Local variable '%s' is void.\n",STR0(str)); }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  debug_malloc_touch(def); debug_malloc_touch(type); debug_malloc_touch(str);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  reference_shared_string(str);
97f6282000-03-07Fredrik Hübinette (Hubbe)  if (frame->current_number_of_locals == MAX_LOCAL)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Too many local variables.");
97f6282000-03-07Fredrik Hübinette (Hubbe)  return 0;
215bed1996-09-28Fredrik Hübinette (Hubbe)  }else {
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG check_type_string(type); #endif /* PIKE_DEBUG */
df13b71999-12-18Henrik Grubbström (Grubba)  if (pike_types_le(type, void_type_string)) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass != 1) {
1191241999-12-18Henrik Grubbström (Grubba)  yywarning("Declaring local variable with type void " "(converted to type zero)."); }
5fdb4d1999-12-18Henrik Grubbström (Grubba)  free_string(type); copy_shared_string(type, zero_type_string); }
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->variable[frame->current_number_of_locals].type = type; frame->variable[frame->current_number_of_locals].name = str; frame->variable[frame->current_number_of_locals].def = def;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  frame->variable[frame->current_number_of_locals].line=lex.current_line; frame->variable[frame->current_number_of_locals].file=lex.current_file; add_ref(lex.current_file);
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->current_number_of_locals++; if(frame->current_number_of_locals > frame->max_number_of_locals)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->max_number_of_locals= frame->current_number_of_locals;
215bed1996-09-28Fredrik Hübinette (Hubbe)  }
97f6282000-03-07Fredrik Hübinette (Hubbe)  return frame->current_number_of_locals-1;
215bed1996-09-28Fredrik Hübinette (Hubbe)  } }
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* argument must be a shared string */ /* Note that this function eats a reference to 'type' */ /* If def is nonzero, it also eats a ref to def */ int add_local_name(struct pike_string *str, struct pike_string *type, node *def) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  return low_add_local_name(Pike_compiler->compiler_frame,
97f6282000-03-07Fredrik Hübinette (Hubbe)  str, type, def); }
120d842000-11-08Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) int islocal(struct pike_string *str) {
120d842000-11-08Fredrik Hübinette (Hubbe)  return low_islocal(Pike_compiler->compiler_frame, str);
215bed1996-09-28Fredrik Hübinette (Hubbe) }
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe) /* argument must be a shared string */ static node *lexical_islocal(struct pike_string *str) { int e,depth=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct compiler_frame *f=Pike_compiler->compiler_frame;
4218011999-01-31Fredrik Hübinette (Hubbe)  while(1) { for(e=f->current_number_of_locals-1;e>=0;e--) { if(f->variable[e].name==str) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct compiler_frame *q=Pike_compiler->compiler_frame;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  if(f->variable[e].def) return copy_node(f->variable[e].def);
4218011999-01-31Fredrik Hübinette (Hubbe)  while(q!=f) {
8322b62000-05-08Fredrik Hübinette (Hubbe)  q->lexical_scope|=SCOPE_SCOPED;
4218011999-01-31Fredrik Hübinette (Hubbe)  q=q->previous; }
8322b62000-05-08Fredrik Hübinette (Hubbe)  if(depth) q->lexical_scope|=SCOPE_SCOPE_USED;
4218011999-01-31Fredrik Hübinette (Hubbe)  return mklocalnode(e,depth); } }
8322b62000-05-08Fredrik Hübinette (Hubbe)  if(!(f->lexical_scope & SCOPE_LOCAL)) return 0;
4218011999-01-31Fredrik Hübinette (Hubbe)  depth++; f=f->previous; } }
86dd562001-04-03Henrik Grubbström (Grubba) static void safe_inc_enum(void) { struct svalue *save_sp = Pike_sp; JMP_BUF recovery; free_svalue(&throw_value); throw_value.type = T_INT; if (SETJMP(recovery)) { yyerror("Bad implicit enum value (failed to add 1)."); while(Pike_sp > save_sp) pop_stack(); } else { push_int(1); f_add(2); } UNSETJMP(recovery); #ifdef PIKE_DEBUG if (Pike_sp != save_sp) { fatal("stack thrashed in enum.\n"); } #endif /* PIKE_DEBUG */ }
61e9a01998-01-25Fredrik Hübinette (Hubbe) void cleanup_compiler(void) { }