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. \*/ %pure_parser /* * These values are used by the stack machine, and can not be directly * called from Pike. */ %token F_PREFIX_256 F_PREFIX_512 F_PREFIX_768 F_PREFIX_1024 %token F_PREFIX_CHARX256 F_PREFIX_WORDX256 F_PREFIX_24BITX256
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_POP_VALUE F_POP_N_ELEMS F_MARK F_MARK2 F_MARK_X F_LDA
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %token F_CALL_LFUN F_CALL_LFUN_AND_POP F_CALL_LFUN_AND_RETURN
3c04e81997-03-13Fredrik Hübinette (Hubbe) %token F_APPLY F_APPLY_AND_POP F_MARK_APPLY F_MARK_APPLY_POP
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_APPLY_AND_RETURN F_MARK_AND_STRING %token F_APPLY_ASSIGN_LOCAL F_APPLY_ASSIGN_LOCAL_AND_POP
215bed1996-09-28Fredrik Hübinette (Hubbe)  %token F_BRANCH F_BRANCH_WHEN_ZERO F_BRANCH_WHEN_NON_ZERO
596e361998-03-31Fredrik Hübinette (Hubbe) %token F_BRANCH_AND_POP_WHEN_ZERO F_BRANCH_AND_POP_WHEN_NON_ZERO
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_BRANCH_WHEN_LT F_BRANCH_WHEN_GT %token F_BRANCH_WHEN_LE F_BRANCH_WHEN_GE %token F_BRANCH_WHEN_EQ F_BRANCH_WHEN_NE
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_BRANCH_IF_LOCAL
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_INC_LOOP F_DEC_LOOP %token F_INC_NEQ_LOOP F_DEC_NEQ_LOOP
dffa011997-01-15Fredrik Hübinette (Hubbe) %token F_INDEX F_ARROW F_INDIRECT F_STRING_INDEX F_LOCAL_INDEX
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_LOCAL_LOCAL_INDEX
2bab9a1998-04-05Fredrik Hübinette (Hubbe) %token F_POS_INT_INDEX F_NEG_INT_INDEX
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_LTOSVAL F_LTOSVAL2 %token F_PUSH_ARRAY %token F_RANGE F_COPY_VALUE /* * Basic value pushing */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %token F_LFUN %token F_GLOBAL F_GLOBAL_LVALUE %token F_LOCAL F_2_LOCALS F_LOCAL_LVALUE F_MARK_AND_LOCAL %token F_EXTERNAL F_EXTERNAL_LVALUE
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_CLEAR_LOCAL F_CLEAR_2_LOCAL F_CLEAR_4_LOCAL %token F_CLEAR_STRING_SUBTYPE
dffa011997-01-15Fredrik Hübinette (Hubbe) %token F_CONSTANT F_FLOAT F_STRING F_ARROW_STRING
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_NUMBER F_NEG_NUMBER F_CONST_1 F_CONST0 F_CONST1 F_BIGNUM /* * These are the predefined functions that can be accessed from Pike. */ %token F_INC F_DEC F_POST_INC F_POST_DEC F_INC_AND_POP F_DEC_AND_POP %token F_INC_LOCAL F_INC_LOCAL_AND_POP F_POST_INC_LOCAL %token F_DEC_LOCAL F_DEC_LOCAL_AND_POP F_POST_DEC_LOCAL
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_RETURN F_DUMB_RETURN F_RETURN_0 F_RETURN_1 F_RETURN_LOCAL %token F_THROW_ZERO
215bed1996-09-28Fredrik Hübinette (Hubbe)  %token F_ASSIGN F_ASSIGN_AND_POP %token F_ASSIGN_LOCAL F_ASSIGN_LOCAL_AND_POP %token F_ASSIGN_GLOBAL F_ASSIGN_GLOBAL_AND_POP
3c04e81997-03-13Fredrik Hübinette (Hubbe) %token F_ADD F_SUBTRACT F_ADD_INT F_ADD_NEG_INT
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %token F_ADD_TO_AND_POP
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_MULTIPLY F_DIVIDE F_MOD %token F_LT F_GT F_EQ F_GE F_LE F_NE %token F_NEGATE F_NOT F_COMPL %token F_AND F_OR F_XOR %token F_LSH F_RSH %token F_LAND F_LOR
2d12341997-03-10Fredrik Hübinette (Hubbe) %token F_EQ_OR F_EQ_AND
215bed1996-09-28Fredrik Hübinette (Hubbe)  %token F_SWITCH F_SSCANF F_CATCH %token F_CAST %token F_FOREACH %token F_SIZEOF F_SIZEOF_LOCAL
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %token F_CALL_FUNCTION F_CALL_FUNCTION_AND_RETURN
215bed1996-09-28Fredrik Hübinette (Hubbe)  /* * These are token values that needn't have an associated code for the * compiled file */ %token F_MAX_OPCODE %token F_ADD_EQ %token F_AND_EQ %token F_ARG_LIST %token F_ARRAY_ID %token F_BREAK %token F_CASE %token F_CLASS %token F_COLON_COLON %token F_COMMA %token F_CONTINUE %token F_DEFAULT %token F_DIV_EQ %token F_DO %token F_DOT_DOT %token F_DOT_DOT_DOT
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_REDEF
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_EFUN_CALL %token F_ELSE %token F_FLOAT_ID %token F_FOR %token F_FUNCTION_ID %token F_GAUGE %token F_IDENTIFIER %token F_IF
591c0c1997-01-19Fredrik Hübinette (Hubbe) %token F_IMPORT
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_INHERIT %token F_INLINE
6bc9281998-04-10Fredrik Hübinette (Hubbe) %token F_LOCAL_ID %token F_FINAL_ID
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_INT_ID %token F_LAMBDA %token F_MULTISET_ID %token F_MULTISET_END %token F_MULTISET_START %token F_LOCAL %token F_LSH_EQ %token F_LVALUE_LIST
2a32691998-01-31Fredrik Hübinette (Hubbe) %token F_ARRAY_LVALUE
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_MAPPING_ID %token F_MIXED_ID %token F_MOD_EQ %token F_MULT_EQ %token F_NO_MASK %token F_OBJECT_ID %token F_OR_EQ %token F_PRIVATE %token F_PROGRAM_ID %token F_PROTECTED
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_PREDEF
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_PUBLIC %token F_RSH_EQ %token F_STATIC %token F_STATUS %token F_STRING_ID %token F_SUBSCRIPT %token F_SUB_EQ %token F_TYPEOF %token F_VAL_LVAL %token F_VOID_ID %token F_WHILE %token F_XOR_EQ
89c5491997-03-04Fredrik Hübinette (Hubbe) %token F_NOP
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %token F_UNDEFINED
215bed1996-09-28Fredrik Hübinette (Hubbe)  %token F_ALIGN %token F_POINTER %token F_LABEL
e82b301997-01-29Fredrik Hübinette (Hubbe) %token F_BYTE
9b08a21998-03-31Fredrik Hübinette (Hubbe) %token F_DATA
215bed1996-09-28Fredrik Hübinette (Hubbe)  %token F_MAX_INSTR %right '=' %right '?' %left F_LOR %left F_LAND %left '|' %left '^' %left '&' %left F_EQ F_NE %left '>' F_GE '<' F_LE /* nonassoc? */ %left F_LSH F_RSH %left '+' '-'
413c8e1996-11-01Fredrik Hübinette (Hubbe) %left '*' '%' '/'
215bed1996-09-28Fredrik Hübinette (Hubbe) %right F_NOT '~' %nonassoc F_INC F_DEC %{ /* This is the grammar definition of Pike. */ #include "global.h"
9770301998-04-17Henrik Grubbström (Grubba) RCSID("$Id: language.yacc,v 1.79 1998/04/17 01:22:34 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 "lex.h" #include "program.h" #include "pike_types.h" #include "constants.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) #include "error.h" #include "docode.h"
4868db1997-05-07Per Hedbor #include "machine.h"
63c6751998-04-09Fredrik Hübinette (Hubbe) #include "cyclic.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #define YYMAXDEPTH 1000
215bed1996-09-28Fredrik Hübinette (Hubbe) 
189fd01997-01-28Fredrik Hübinette (Hubbe) #ifdef 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) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void add_local_name(struct pike_string *,struct pike_string *);
215bed1996-09-28Fredrik Hübinette (Hubbe)  static int varargs; static INT32 current_modifiers;
8d7bda1997-02-10Fredrik Hübinette (Hubbe) static struct pike_string *last_identifier=0;
215bed1996-09-28Fredrik Hübinette (Hubbe)  void fix_comp_stack(int sp) { if(comp_stackp>sp) { yyerror("Compiler stack fixed."); comp_stackp=sp; }else if(comp_stackp<sp){ fatal("Compiler stack frame underflow."); } }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
cd89d71997-09-10Henrik Grubbström (Grubba) /* * Kludge for Bison not using prototypes. */ #ifndef __GNUC__ #ifndef __cplusplus
903e821997-09-11Henrik Grubbström (Grubba) static void __yy_memcpy(char *to, char *from, int 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; }
e2acf71997-04-23Henrik Grubbström (Grubba) %{ int yylex(YYSTYPE *yylval); %}
215bed1996-09-28Fredrik Hübinette (Hubbe) %type <fnum> F_FLOAT
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> F_ARRAY_ID %type <number> F_BREAK %type <number> F_CASE %type <number> F_CATCH %type <number> F_CONTINUE %type <number> F_DEFAULT %type <number> F_DO %type <number> F_ELSE %type <number> F_FLOAT_ID %type <number> F_FOR %type <number> F_FOREACH %type <number> F_FUNCTION_ID %type <number> F_GAUGE %type <number> F_IF %type <number> F_INHERIT %type <number> F_INLINE %type <number> F_INT_ID %type <number> F_LAMBDA %type <number> F_LOCAL %type <number> F_MAPPING_ID %type <number> F_MIXED_ID %type <number> F_MULTISET_ID %type <number> F_NO_MASK %type <number> F_NUMBER %type <number> F_OBJECT_ID %type <number> F_PREDEF %type <number> F_PRIVATE %type <number> F_PROGRAM_ID %type <number> F_PROTECTED %type <number> F_PUBLIC %type <number> F_RETURN %type <number> F_SSCANF %type <number> F_STATIC %type <number> F_STRING_ID %type <number> F_SWITCH %type <number> F_VOID_ID %type <number> F_WHILE %type <number> arguments %type <number> arguments2
febbc81997-04-22Fredrik Hübinette (Hubbe) %type <number> func_args
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> assign %type <number> modifier %type <number> modifier_list %type <number> modifiers
8c77b61998-04-13Henrik Grubbström (Grubba) %type <number> opt_string_type
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> optional_dot_dot_dot %type <number> optional_stars
215bed1996-09-28Fredrik Hübinette (Hubbe) 
8c77b61998-04-13Henrik Grubbström (Grubba) /* The following symbols return type information */
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> cast %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 %type <n> F_STRING %type <n> optional_rename_inherit %type <n> optional_identifier %type <n> F_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> assoc_pair %type <n> block
01d3e21997-04-23Fredrik Hübinette (Hubbe) %type <n> failsafe_block
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
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
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
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> optional_else_part %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
215bed1996-09-28Fredrik Hübinette (Hubbe) %%
8c77b61998-04-13Henrik Grubbström (Grubba) all: program ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  program: program def optional_semi_colon
bdacd91998-04-15Henrik Grubbström (Grubba) /* | error { yyerrok; } */
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_semi_colon: /* empty */
3301d21996-11-25Fredrik Hübinette (Hubbe)  | ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
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)  optional_rename_inherit: ':' F_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) 
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);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  SAFE_APPLY_MASTER("handle_inherit", 2); if(sp[-1].type != T_PROGRAM)
3c0c281998-01-26Fredrik Hübinette (Hubbe)  my_yyerror("Couldn't cast string \"%s\" to program",$1->u.sval.u.string->str); free_node($1);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  $$=mksvaluenode(sp-1); pop_stack();
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } | idents {
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  if(last_identifier) {
61e9a01998-01-25Fredrik Hübinette (Hubbe)  ref_push_string(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) 
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)  inheritance: modifiers F_INHERIT low_program_ref optional_rename_inherit ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!(new_program->flags & PROGRAM_PASS_1_DONE))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
61e9a01998-01-25Fredrik Hübinette (Hubbe)  struct pike_string *s=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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers F_INHERIT low_program_ref error ';' { free_node($3); yyerrok; } | modifiers F_INHERIT error ';' { yyerrok; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
591c0c1997-01-19Fredrik Hübinette (Hubbe) import: modifiers F_IMPORT idents ';' { resolv_constant($3); free_node($3); use_module(sp-1);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  pop_stack();
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers F_IMPORT error ';' { yyerrok; }
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
998e1f1998-04-15Henrik Grubbström (Grubba) constant_name: F_IDENTIFIER '=' safe_expr0
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { int tmp; /* This can be made more lenient in the future */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  /* Ugly hack to make sure that $3 is optimized */ tmp=compiler_pass; $3=mknode(F_ARG_LIST,$3,0); compiler_pass=tmp; if(!is_const($3))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_pass==2) yyerror("Constant definition is not constant.");
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_constant($1->u.sval.u.string,0, current_modifiers); /* Prototype */
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } else {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  tmp=eval_low($3);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  if(tmp < 1)
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  {
d2c6081996-11-07Fredrik Hübinette (Hubbe)  yyerror("Error in constant definition.");
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  }else{ pop_n_elems(tmp-1);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_constant($1->u.sval.u.string,sp-1,current_modifiers);
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  pop_stack(); }
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 ;
3bcd581997-04-08Marcus Comstedt constant: modifiers F_CONSTANT constant_list ';' {}
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers F_CONSTANT error ';' { yyerrok; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) block_or_semi: block { $$ = mknode(F_ARG_LIST,$1,mknode(F_RETURN,mkintnode(0),0)); } | ';' { $$ = NULL;} ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  type_or_error: simple_type
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_frame->current_type) free_string(compiler_frame->current_type);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  copy_shared_string(compiler_frame->current_type,$1->u.sval.u.string); free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) def: modifiers type_or_error optional_stars F_IDENTIFIER { push_compiler_frame(); if(!compiler_frame->previous || !compiler_frame->previous->current_type) {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Internal compiler fault.");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  copy_shared_string(compiler_frame->current_type, mixed_type_string); }else{ copy_shared_string(compiler_frame->current_type, compiler_frame->previous->current_type); } } '(' arguments ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e; /* construct the function type */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->current_type);
febbc81997-04-22Fredrik Hübinette (Hubbe)  while(--$3>=0) push_type(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_frame->current_return_type) free_string(compiler_frame->current_return_type); compiler_frame->current_return_type=pop_type();
7e50571996-11-02Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->current_return_type);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  e=$7-1;
7e50571996-11-02Fredrik Hübinette (Hubbe)  if(varargs) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--; varargs=0; pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } push_type(T_FUNCTION);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  { struct pike_string *s=pop_type(); $<n>$=mkstrnode(s); free_string(s); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_pass==1) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  define_function($4->u.sval.u.string, $<n>$->u.sval.u.string,
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $1, IDENTIFIER_PIKE_FUNCTION, 0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } block_or_semi { int e;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if($10)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
22edc21998-01-29Fredrik Hübinette (Hubbe)  int f;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  for(e=0; e<$7; e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!compiler_frame->variable[e].name || !compiler_frame->variable[e].name->len) {
8c77b61998-04-13Henrik Grubbström (Grubba)  my_yyerror("Missing name for argument %d.",e);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
329cc01997-02-17Fredrik Hübinette (Hubbe) 
22edc21998-01-29Fredrik Hübinette (Hubbe)  f=dooptcode($4->u.sval.u.string, $10, $<n>9->u.sval.u.string, $1);
294dc51997-08-03Fredrik Hübinette (Hubbe) #ifdef DEBUG if(recoveries && sp-evaluator_stack < recoveries->sp) fatal("Stack error (underflow)\n"); #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); free_node($<n>9);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers type_or_error optional_stars bad_identifier '(' arguments ')' block_or_semi { free_string(pop_type()); }
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); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | error ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { reset_type_stack();
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerrok;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) /* if(num_parse_error>5) YYACCEPT; */
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
2968361998-04-14Henrik Grubbström (Grubba)  | error '}' {
4d21331998-04-14Henrik Grubbström (Grubba)  YYSTYPE foo; foo.number = 0;
2968361998-04-14Henrik Grubbström (Grubba)  reset_type_stack();
998e1f1998-04-15Henrik Grubbström (Grubba)  YYBACKUP('}', foo);
2968361998-04-14Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_dot_dot_dot: F_DOT_DOT_DOT { $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_identifier: F_IDENTIFIER
8c77b61998-04-13Henrik Grubbström (Grubba)  | 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)  { if(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); varargs=1; }
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 && 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) 
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_local_name($3->u.sval.u.string, pop_type()); free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
febbc81997-04-22Fredrik Hübinette (Hubbe) func_args: '(' arguments ')' { $$=$2; }
e2acf71997-04-23Henrik Grubbström (Grubba)  | '(' error ')' { $$=0; yyerrok; }
01d3e21997-04-23Fredrik Hübinette (Hubbe)  | error { $$=0; yyerrok; }
febbc81997-04-22Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) arguments: /* empty */ optional_comma { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | arguments2 optional_comma { $$=$1; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  arguments2: new_arg_name { $$ = 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | arguments2 ',' new_arg_name { $$ = $1 + 1; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  modifier: F_NO_MASK { $$ = ID_NOMASK; }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | F_FINAL_ID { $$ = ID_NOMASK; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_STATIC { $$ = ID_STATIC; }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | F_PRIVATE { $$ = ID_PRIVATE | ID_STATIC; } | F_LOCAL_ID { $$ = ID_INLINE; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_PUBLIC { $$ = ID_PUBLIC; } | F_PROTECTED { $$ = ID_PROTECTED; }
61e9a01998-01-25Fredrik Hübinette (Hubbe)  | F_INLINE { $$ = ID_INLINE; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
61e9a01998-01-25Fredrik Hübinette (Hubbe) modifiers: modifier_list { $$=current_modifiers=$1 | lex.pragmas; } ;
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 ')' { struct pike_string *s=pop_type(); $$=mkstrnode(s); free_string(s); }
2e4e451997-02-13Fredrik Hübinette (Hubbe)  ;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type6: type | identifier_type ;
2e4e451997-02-13Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) type: type '*' { push_type(T_ARRAY); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | type2 ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) type7: type7 '*' { push_type(T_ARRAY); } | type4 ; simple_type: type4 { struct pike_string *s=pop_type(); $$=mkstrnode(s); free_string(s); } ; simple_type2: type2 { struct pike_string *s=pop_type(); $$=mkstrnode(s); free_string(s); } ; simple_identifier_type: identifier_type
3c0c281998-01-26Fredrik Hübinette (Hubbe)  { struct pike_string *s=pop_type(); $$=mkstrnode(s); free_string(s); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) identifier_type: idents { struct program *p; resolv_program($1); if((p=program_from_svalue(sp-1))) { push_type_int(sp[-1].u.program->id); }else{ push_type_int(0); } push_type(0); push_type(T_OBJECT); pop_stack(); free_node($1); } ; type4: type2 | identifier_type
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)  type3: F_INT_ID { push_type(T_INT); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_FLOAT_ID { push_type(T_FLOAT); } | F_PROGRAM_ID { push_type(T_PROGRAM); } | F_VOID_ID { push_type(T_VOID); } | F_MIXED_ID { push_type(T_MIXED); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_STRING_ID opt_string_type { push_type(T_STRING); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | F_OBJECT_ID opt_object_type { push_type(T_OBJECT); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_MAPPING_ID opt_mapping_type { push_type(T_MAPPING); } | F_ARRAY_ID opt_array_type { push_type(T_ARRAY); } | F_MULTISET_ID opt_array_type { push_type(T_MULTISET); } | F_FUNCTION_ID opt_function_type { push_type(T_FUNCTION); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
8c77b61998-04-13Henrik Grubbström (Grubba) opt_string_type: /* Empty */ { $$=1; } | '(' F_NUMBER ')' { if ($2 != 1) yyerror("Wide strings are not supported."); $$=1; }
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 ')' {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct program *p=program_from_svalue(sp-1); 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{
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Not a valid program specifier.");
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) { push_type(T_MANY); type_stack_reverse(); }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); push_type(T_MIXED); push_type(T_MANY); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  function_type_list: /* Empty */ optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  | function_type_list2 optional_comma ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) function_type_list2: type7
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)  new_name: optional_stars F_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { struct pike_string *type;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->current_type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY); type=pop_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  define_variable($2->u.sval.u.string, type, 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 {}
7e50571996-11-02Fredrik Hübinette (Hubbe)  | optional_stars F_IDENTIFIER '=' { struct pike_string *type;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->current_type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY); type=pop_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $<number>$=define_variable($2->u.sval.u.string, type, current_modifiers);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(type); } expr0 { init_node=mknode(F_ARG_LIST,init_node, 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)  }
2968361998-04-14Henrik Grubbström (Grubba)  | optional_stars F_IDENTIFIER '=' error { 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)  new_local_name: optional_stars F_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4943aa1998-04-09Fredrik Hübinette (Hubbe)  push_finished_type($<n>0->u.sval.u.string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string, pop_type());
6bc9281998-04-10Fredrik Hübinette (Hubbe)  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($2->u.sval.u.string)));
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 {}
7e50571996-11-02Fredrik Hübinette (Hubbe)  | optional_stars F_IDENTIFIER '=' expr0 {
4943aa1998-04-09Fredrik Hübinette (Hubbe)  push_finished_type($<n>0->u.sval.u.string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string, pop_type()); $$=mknode(F_ASSIGN,$4,mklocalnode(islocal($2->u.sval.u.string))); free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier '=' expr0 { free_node($4); } | optional_stars F_IDENTIFIER '=' error { free_node($2); /* No yyerok here since we aren't done yet. */ }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) new_local_name2: F_IDENTIFIER { add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string); $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($1->u.sval.u.string))); free_node($1); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | bad_identifier { $$=mkintnode(0); }
998e1f1998-04-15Henrik Grubbström (Grubba)  | F_IDENTIFIER '=' safe_expr0
6bc9281998-04-10Fredrik Hübinette (Hubbe)  { add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string); $$=mknode(F_ASSIGN,$3, mklocalnode(islocal($1->u.sval.u.string))); 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)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $<number>$=compiler_frame->current_number_of_locals;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } statements '}' {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=$3; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
01d3e21997-04-23Fredrik Hübinette (Hubbe) failsafe_block: block
8c77b61998-04-13Henrik Grubbström (Grubba)  | error { $$=0; yyerrok }
01d3e21997-04-23Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) local_name_list: new_local_name
4943aa1998-04-09Fredrik Hübinette (Hubbe)  | local_name_list ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_ARG_LIST,$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 | local_name_list2 ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_ARG_LIST,$1,$4); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) statements: { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | statements statement { $$=mknode(F_ARG_LIST,$1,mkcastnode(void_type_string,$2)); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  statement: unused2 ';' { $$=$1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cond | while | do | for | switch | case | default | return ';' | block {} | foreach | break ';' | continue ';'
e2acf71997-04-23Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); $$=0; yyerrok; }
4d21331998-04-14Henrik Grubbström (Grubba)  | error '}' { YYSTYPE foo; foo.number = 0; reset_type_stack();
998e1f1998-04-15Henrik Grubbström (Grubba)  yyerror("Missing ';'."); YYBACKUP('}', foo);
4d21331998-04-14Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | ';' { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  break: F_BREAK { $$=mknode(F_BREAK,0,0); } ;
4d21331998-04-14Henrik Grubbström (Grubba) default: F_DEFAULT ':' { $$=mknode(F_DEFAULT,0,0); } | F_DEFAULT { $$=mknode(F_DEFAULT,0,0); yyerror("Expected ':' after default."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) continue: F_CONTINUE { $$=mknode(F_CONTINUE,0,0); } ; lambda: F_LAMBDA
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  $<number>$=comp_stackp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_frame->current_return_type) free_string(compiler_frame->current_return_type); copy_shared_string(compiler_frame->current_return_type,any_type_string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
01d3e21997-04-23Fredrik Hübinette (Hubbe)  func_args 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; fix_comp_stack($<number>2);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  $4=mknode(F_ARG_LIST,$4,mknode(F_RETURN,mkintnode(0),0)); type=find_return_type($4); if(type) push_finished_type(type); else push_type(T_MIXED);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
febbc81997-04-22Fredrik Hübinette (Hubbe)  e=$3-1;
7e50571996-11-02Fredrik Hübinette (Hubbe)  if(varargs) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--; varargs=0; pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_FUNCTION); type=pop_type();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
22edc21998-01-29Fredrik Hübinette (Hubbe)  sprintf(buf,"__lambda_%ld_%ld", (long)new_program->id, local_class_counter++);
8267f41998-01-28Fredrik Hübinette (Hubbe)  name=make_shared_string(buf); f=dooptcode(name, $4, type,
22edc21998-01-29Fredrik Hübinette (Hubbe)  ID_PRIVATE | ID_INLINE);
8267f41998-01-28Fredrik Hübinette (Hubbe)  $$=mkidentifiernode(f);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(name); free_string(type);
febbc81997-04-22Fredrik Hübinette (Hubbe)  comp_stackp=$<number>2;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
febbc81997-04-22Fredrik Hübinette (Hubbe) failsafe_program: '{' program '}'
e2acf71997-04-23Henrik Grubbström (Grubba)  | error { yyerrok; }
febbc81997-04-22Fredrik Hübinette (Hubbe)  ;
51ffdb1998-01-19Fredrik Hübinette (Hubbe) class: modifiers F_CLASS optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
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];
22edc21998-01-29Fredrik Hübinette (Hubbe)  sprintf(buffer,"__class_%ld_%ld",(long)new_program->id, local_class_counter++);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  s=make_shared_string(buffer); $3=mkstrnode(s); free_string(s);
22edc21998-01-29Fredrik Hübinette (Hubbe)  $1|=ID_PRIVATE | ID_INLINE;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS start\n"); */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_pass==1) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  low_start_new_program(0, $3->u.sval.u.string, $1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ int i; struct program *p; struct identifier *id;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  i=isidentifier($3->u.sval.u.string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(i<0) { low_start_new_program(new_program,0,0); yyerror("Pass 2: program not defined!"); }else{ id=ID_FROM_INT(new_program, i); if(IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { struct svalue *s; s=PROG_FROM_INT(new_program,i)->constants+id->func.offset; if(s->type==T_PROGRAM) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  low_start_new_program(s->u.program, $3->u.sval.u.string, $1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ yyerror("Pass 2: constant redefined!"); low_start_new_program(new_program, 0,0); } }else{ yyerror("Pass 2: class constant no longer constant!"); low_start_new_program(new_program, 0,0); } } }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
febbc81997-04-22Fredrik Hübinette (Hubbe)  failsafe_program
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct program *p; if(compiler_pass == 1) p=end_first_pass(0); else p=end_program();
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS end\n"); */
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mkidentifiernode(isidentifier($3->u.sval.u.string));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!p)
7e50571996-11-02Fredrik Hübinette (Hubbe)  yyerror("Class definition failed.");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  else free_program(p);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3); check_tree($$,0);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) cond: F_IF { $<number>$=compiler_frame->current_number_of_locals; }
4d21331998-04-14Henrik Grubbström (Grubba)  '(' safe_comma_expr ')' statement optional_else_part
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $$=mknode('?',$4,mknode(':',$6,$7));
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);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_else_part: { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_ELSE statement { $$=$2; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
998e1f1998-04-15Henrik Grubbström (Grubba) safe_lvalue: lvalue | error { $$=0 } ; safe_expr0: expr0 | error { $$=mkintnode(0); } ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) foreach: F_FOREACH { $<number>$=compiler_frame->current_number_of_locals; }
998e1f1998-04-15Henrik Grubbström (Grubba)  '(' safe_expr0 ',' safe_lvalue ')' statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
998e1f1998-04-15Henrik Grubbström (Grubba)  if ($6) { $$=mknode(F_FOREACH, mknode(F_VAL_LVAL,$4,$6),$8); $$->line_number=$1; } else { /* Error in lvalue */ free_node($4); $$=$8; }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
4d21331998-04-14Henrik Grubbström (Grubba) do: F_DO statement F_WHILE '(' safe_comma_expr ')' ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_DO,$2,$5); $$->line_number=$1; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) for: F_FOR
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $<number>$=compiler_frame->current_number_of_locals; } '(' unused ';' for_expr ';' unused ')' statement { int i=lex.current_line; lex.current_line=$1; $$=mknode(F_ARG_LIST,mkcastnode(void_type_string,$4),mknode(F_FOR,$6,mknode(':',$10,$8))); lex.current_line=i; pop_local_variables($<number>2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) while: F_WHILE { $<number>$=compiler_frame->current_number_of_locals; }
4d21331998-04-14Henrik Grubbström (Grubba)  '(' safe_comma_expr ')' statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  int i=lex.current_line; lex.current_line=$1; $$=mknode(F_FOR,$4,mknode(':',$6,NULL)); lex.current_line=i; pop_local_variables($<number>2);
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) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) switch: F_SWITCH { $<number>$=compiler_frame->current_number_of_locals; }
4d21331998-04-14Henrik Grubbström (Grubba)  '(' safe_comma_expr ')' statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $$=mknode(F_SWITCH,$4,$6);
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$->line_number=$1;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
4d21331998-04-14Henrik Grubbström (Grubba) case: F_CASE safe_comma_expr ':'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_CASE,$2,0); }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_CASE safe_comma_expr F_DOT_DOT optional_comma_expr ':'
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)  return: F_RETURN
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!match_types(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); }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_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 | error { $$=mkintnode(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); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ; comma_expr2: expr0 | comma_expr2 ',' expr0 { $$ = mknode(F_ARG_LIST,mkcastnode(void_type_string,$1),$3); } ;
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; }
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; } | '[' 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)  expr01: expr1 { $$ = $1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '?' expr01 ':' expr01 { $$=mknode('?',$1,mknode(':',$3,$5)); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  assign: F_AND_EQ { $$=F_AND_EQ; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_OR_EQ { $$=F_OR_EQ; } | F_XOR_EQ { $$=F_XOR_EQ; } | F_LSH_EQ { $$=F_LSH_EQ; } | F_RSH_EQ { $$=F_RSH_EQ; } | F_ADD_EQ { $$=F_ADD_EQ; } | F_SUB_EQ { $$=F_SUB_EQ; } | F_MULT_EQ{ $$=F_MULT_EQ; } | F_MOD_EQ { $$=F_MOD_EQ; } | F_DIV_EQ { $$=F_DIV_EQ; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_comma: | ',' ; expr_list: { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr_list2 optional_comma { $$=$1; } ;
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; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | m_expr_list2 optional_comma { $$=$1; } ;
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 { $$=$1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
998e1f1998-04-15Henrik Grubbström (Grubba) assoc_pair: expr0 ':' expr1 { $$=mknode(F_ARG_LIST,$1,$3); } | expr0 ':' error { free_node($1); $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr1: expr2
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 F_LOR expr1 { $$=mknode(F_LOR,$1,$3); } | expr1 F_LAND expr1 { $$=mknode(F_LAND,$1,$3); } | expr1 '|' expr1 { $$=mkopernode("`|",$1,$3); } | expr1 '^' expr1 { $$=mkopernode("`^",$1,$3); } | expr1 '&' expr1 { $$=mkopernode("`&",$1,$3); } | expr1 F_EQ expr1 { $$=mkopernode("`==",$1,$3); } | expr1 F_NE expr1 { $$=mkopernode("`!=",$1,$3); } | expr1 '>' expr1 { $$=mkopernode("`>",$1,$3); } | expr1 F_GE expr1 { $$=mkopernode("`>=",$1,$3); } | expr1 '<' expr1 { $$=mkopernode("`<",$1,$3); } | expr1 F_LE expr1 { $$=mkopernode("`<=",$1,$3); } | expr1 F_LSH expr1 { $$=mkopernode("`<<",$1,$3); } | expr1 F_RSH expr1 { $$=mkopernode("`>>",$1,$3); } | 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); }
998e1f1998-04-15Henrik Grubbström (Grubba)  | expr1 F_LOR error { $$=$1; } | expr1 F_LAND error { $$=$1; } | expr1 '|' error { $$=$1; } | expr1 '^' error { $$=$1; } | expr1 '&' error { $$=$1; } | expr1 F_EQ error { $$=$1; } | expr1 F_NE error { $$=$1; } | expr1 '>' error { $$=$1; } | expr1 F_GE error { $$=$1; } | expr1 '<' error { $$=$1; } | expr1 F_LE error { $$=$1; } | expr1 F_LSH error { $$=$1; } | expr1 F_RSH error { $$=$1; } | expr1 '+' error { $$=$1; } | expr1 '-' error { $$=$1; } | expr1 '*' error { $$=$1; } | expr1 '%' error { $$=$1; } | expr1 '/' error { $$=$1; }
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)  } | F_INC expr4 { $$=mknode(F_INC,$2,0); } | F_DEC expr4 { $$=mknode(F_DEC,$2,0); } | F_NOT expr2 { $$=mkopernode("`!",$2,0); } | '~' expr2 { $$=mkopernode("`~",$2,0); } | '-' expr2 { $$=mkopernode("`-",$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr3: expr4
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr4 F_INC { $$=mknode(F_POST_INC,$1,0); } | expr4 F_DEC { $$=mknode(F_POST_DEC,$1,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr4: string
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_NUMBER { $$=mkintnode($1); }
d0a7ac1998-04-11Henrik Grubbström (Grubba)  | F_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | catch | gauge | typeof | sscanf | lambda | class
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | idents | expr4 '(' expr_list ')' { $$=mkapplynode($1,$3); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '(' error ')' { $$=mkapplynode($1, NULL); yyerrok; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | expr4 '[' expr0 ']' { $$=mknode(F_INDEX,$1,$3); } | expr4 '[' comma_expr_or_zero F_DOT_DOT comma_expr_or_maxint ']' { $$=mknode(F_RANGE,$1,mknode(F_ARG_LIST,$3,$5)); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '[' error ']' { $$=$1; yyerrok; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | '(' comma_expr2 ')' { $$=$2; } | '(' '{' expr_list '}' ')'
42d8c41998-03-04Fredrik Hübinette (Hubbe)  { $$=mkefuncallnode("aggregate",$3); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | '(' '[' m_expr_list ']' ')'
42d8c41998-03-04Fredrik Hübinette (Hubbe)  { $$=mkefuncallnode("aggregate_mapping",$3); };
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | F_MULTISET_START expr_list F_MULTISET_END { $$=mkefuncallnode("aggregate_multiset",$2); }
9770301998-04-17Henrik Grubbström (Grubba)  | '(' error ')' { $$=mkintnode(0); yyerrok; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | expr4 F_ARROW F_IDENTIFIER {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mknode(F_ARROW,$1,$3);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 F_ARROW bad_identifier {}
4d21331998-04-14Henrik Grubbström (Grubba)  | expr4 F_ARROW error {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
591c0c1997-01-19Fredrik Hübinette (Hubbe) idents: low_idents | idents '.' F_IDENTIFIER {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=index_node($1, $3->u.sval.u.string);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  free_node($1);
e319bb1997-02-28Fredrik Hübinette (Hubbe)  if(last_identifier) free_string(last_identifier);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  copy_shared_string(last_identifier, $3->u.sval.u.string); free_node($3);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | idents '.' bad_identifier {}
4d21331998-04-14Henrik Grubbström (Grubba)  | idents '.' error {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ; low_idents: F_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int i; struct efun *f;
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  if(last_identifier) free_string(last_identifier);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  copy_shared_string(last_identifier, $1->u.sval.u.string); if((i=islocal(last_identifier))>=0)
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mklocalnode(i);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  }else if((i=isidentifier(last_identifier))>=0){
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=mkidentifiernode(i);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  }else if(!($$=find_module_identifier(last_identifier))){
591c0c1997-01-19Fredrik Hübinette (Hubbe)  $$=0;
d43aff1997-08-03Fredrik Hübinette (Hubbe)  if(!num_parse_error)
dffa011997-01-15Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(get_master())
63c6751998-04-09Fredrik Hübinette (Hubbe)  { DECLARE_CYCLIC(); if(BEGIN_CYCLIC(last_identifier, lex.current_file))
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  my_yyerror("Recursive module dependency in %s.", last_identifier->str);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{
63c6751998-04-09Fredrik Hübinette (Hubbe)  SET_CYCLIC_RET(1); ref_push_string(last_identifier); ref_push_string(lex.current_file); SAFE_APPLY_MASTER("resolv", 2); if(throw_value.type == T_STRING) { if(compiler_pass==2) my_yyerror("%s",throw_value.u.string->str); else $$=mknode(F_UNDEFINED,0,0); } else if(IS_ZERO(sp-1) && sp[-1].subtype==1) { if(compiler_pass==2) my_yyerror("'%s' undefined.", last_identifier->str); else $$=mknode(F_UNDEFINED,0,0); }else{ $$=mkconstantsvaluenode(sp-1); } pop_stack(); END_CYCLIC();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }else{ if(compiler_pass==2) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  my_yyerror("'%s' undefined.", last_identifier->str);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ $$=mknode(F_UNDEFINED,0,0); } }
4579e31998-03-04Henrik Grubbström (Grubba)  } else {
3195221998-03-04Henrik 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)  } | F_PREDEF F_COLON_COLON F_IDENTIFIER {
45e8a81997-01-26Fredrik Hübinette (Hubbe)  struct svalue tmp; node *tmp2; tmp.type=T_MAPPING;
94a2971997-03-01Henrik Grubbström (Grubba) #ifdef __CHECKER__ tmp.subtype=0; #endif /* __CHECKER__ */
45e8a81997-01-26Fredrik Hübinette (Hubbe)  tmp.u.mapping=get_builtin_constants(); tmp2=mkconstantsvaluenode(&tmp);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=index_node(tmp2, $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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_PREDEF F_COLON_COLON bad_identifier { $$=mkintnode(0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_IDENTIFIER F_COLON_COLON F_IDENTIFIER {
d429a71998-02-24Fredrik Hübinette (Hubbe)  $$=reference_inherited_identifier($1->u.sval.u.string,
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $3->u.sval.u.string);
d429a71998-02-24Fredrik Hübinette (Hubbe)  if (!$$)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  my_yyerror("Undefined identifier %s::%s", $1->u.sval.u.string->str, $3->u.sval.u.string->str);
dffa011997-01-15Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1); free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_IDENTIFIER F_COLON_COLON bad_identifier { $$=$1; }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_IDENTIFIER F_COLON_COLON error { $$=$1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_COLON_COLON F_IDENTIFIER { int e,i; $$=0;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  for(e=1;e<(int)new_program->num_inherits;e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(new_program->inherits[e].inherit_level!=1) continue;
d429a71998-02-24Fredrik Hübinette (Hubbe)  i=low_reference_inherited_identifier(0,e,$2->u.sval.u.string);
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(!$$) {
45e8a81997-01-26Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_COLON_COLON bad_identifier { $$=mkintnode(0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  comma_expr_or_zero: /* empty */ { $$=mkintnode(0); }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  comma_expr_or_maxint: /* empty */ { $$=mkintnode(0x7fffffff); }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  gauge: F_GAUGE catch_arg {
4868db1997-05-07Per Hedbor #ifdef HAVE_GETHRVTIME
215bed1996-09-28Fredrik Hübinette (Hubbe)  $$=mkopernode("`-",
4868db1997-05-07Per Hedbor  mkopernode("`/", mkopernode("`-", mkefuncallnode("gethrvtime",0), mknode(F_ARG_LIST,$2, mkefuncallnode("gethrvtime",0))), mkintnode(1000)), 0); #else $$=mkopernode("`-",
215bed1996-09-28Fredrik Hübinette (Hubbe)  mkopernode("`-", mknode(F_INDEX,mkefuncallnode("rusage",0), mkintnode(GAUGE_RUSAGE_INDEX)), mknode(F_ARG_LIST,$2, mknode(F_INDEX,mkefuncallnode("rusage",0), mkintnode(GAUGE_RUSAGE_INDEX)))),0);
4868db1997-05-07Per Hedbor #endif };
215bed1996-09-28Fredrik Hübinette (Hubbe)  typeof: F_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; tmp=mknode(F_ARG_LIST,$3,0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  s=describe_type( $3 && $3->type ? $3->type : mixed_type_string); $$=mkstrnode(s); free_string(s);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_node(tmp);
4d21331998-04-14Henrik Grubbström (Grubba)  } | F_TYPEOF '(' error ')' { $$=mkintnode(0); yyerrok; } ;
7e50571996-11-02Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) catch_arg: '(' comma_expr ')' { $$=$2; }
8c77b61998-04-13Henrik Grubbström (Grubba)  | '(' error ')' { $$=mkintnode(0); yyerrok; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | block ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
9649491998-02-27Fredrik Hübinette (Hubbe) catch: F_CATCH { catch_level++; } catch_arg { $$=mknode(F_CATCH,$3,NULL); catch_level--;
4d21331998-04-14Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  sscanf: F_SSCANF '(' expr0 ',' expr0 lvalue_list ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_SSCANF,mknode(F_ARG_LIST,$3,$5),$6); }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_SSCANF '(' expr0 ',' expr0 error ')' { $$=mkintnode(0); free_node($3); free_node($5); yyerrok; } | F_SSCANF '(' expr0 error ')' { $$=mkintnode(0); free_node($3); yyerrok; } | F_SSCANF '(' error ')' { $$=mkintnode(0); yyerrok; }
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); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | type6 F_IDENTIFIER
3ddb531996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  add_local_name($2->u.sval.u.string,pop_type()); $$=mklocalnode(islocal($2->u.sval.u.string)); free_node($2);
3ddb531996-11-02Fredrik Hübinette (Hubbe)  }
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) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) string: F_STRING | string F_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 */
4d21331998-04-14Henrik Grubbström (Grubba) bad_identifier:
998e1f1998-04-15Henrik Grubbström (Grubba)  F_INLINE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("inline is a reserved word."); } | F_LOCAL { yyerror("local is a reserved word."); } | F_NO_MASK { yyerror("nomask is a reserved word."); } | F_PREDEF { yyerror("predef is a reserved word."); } | F_PRIVATE { yyerror("private is a reserved word."); } | F_PROTECTED { yyerror("protected is a reserved word."); } | F_PUBLIC { yyerror("public is a reserved word."); } | F_STATIC { yyerror("static is a reserved word."); } | F_ARRAY_ID { yyerror("array is a reserved word."); } | F_FLOAT_ID { yyerror("float is a reserved word.");} | F_INT_ID { yyerror("int is a reserved word."); } | F_MAPPING_ID { yyerror("mapping is a reserved word."); } | F_MULTISET_ID { yyerror("multiset is a reserved word."); } | F_STRING_ID { yyerror("string is a reserved word."); } | F_VOID_ID { yyerror("void is a reserved word."); }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_DO
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("do is a reserved word."); } | F_ELSE { yyerror("else is a reserved word."); } | F_RETURN { yyerror("return is a reserved word."); } | F_CONSTANT { yyerror("constant is a reserved word."); } | F_IMPORT { yyerror("import is a reserved word."); } | F_INHERIT { yyerror("inherit is a reserved word."); } | F_CLASS { yyerror("class is a reserved word."); } | F_CATCH { yyerror("catch is a reserved word."); } | F_GAUGE { yyerror("gauge is a reserved word."); } | F_LAMBDA { yyerror("lambda is a reserved word."); } | F_SSCANF { yyerror("sscanf is a reserved word."); } | F_SIZEOF { yyerror("sizeof is a reserved word."); } | F_SWITCH { yyerror("switch is a reserved word."); } | F_TYPEOF { yyerror("typeof is a reserved word."); } | F_BREAK { yyerror("break is a reserved word."); } | F_CASE { yyerror("case is a reserved word."); } | F_CONTINUE { yyerror("continue is a reserved word."); } | F_DEFAULT { yyerror("default is a reserved word."); } | F_FOR { yyerror("for is a reserved word."); } | F_FOREACH { yyerror("foreach is a reserved word."); } | F_IF { 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) 
294dc51997-08-03Fredrik Hübinette (Hubbe) #ifdef DEBUG if(recoveries && sp-evaluator_stack < recoveries->sp) fatal("Stack error (underflow)\n"); #endif
8c77b61998-04-13Henrik Grubbström (Grubba)  if (num_parse_error > 10) return;
215bed1996-09-28Fredrik Hübinette (Hubbe)  num_parse_error++;
c3c7031996-12-04Fredrik Hübinette (Hubbe)  cumulative_parse_error++;
215bed1996-09-28Fredrik Hübinette (Hubbe)  if ( get_master() ) {
2416d81998-01-27Fredrik Hübinette (Hubbe)  ref_push_string(lex.current_file); push_int(lex.current_line); push_text(str);
215bed1996-09-28Fredrik Hübinette (Hubbe)  SAFE_APPLY_MASTER("compile_error",3); pop_stack(); }else{ (void)fprintf(stderr, "%s:%ld: %s\n",
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  lex.current_file->str, (long)lex.current_line,
215bed1996-09-28Fredrik Hübinette (Hubbe)  str); fflush(stderr); } }
3c0c281998-01-26Fredrik Hübinette (Hubbe) /* argument must be a shared string */
215bed1996-09-28Fredrik Hübinette (Hubbe) void add_local_name(struct pike_string *str, struct pike_string *type) {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  reference_shared_string(str);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if (compiler_frame->current_number_of_locals == MAX_LOCAL)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Too many local variables.");
215bed1996-09-28Fredrik Hübinette (Hubbe)  }else {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  compiler_frame->variable[compiler_frame->current_number_of_locals].type = type; compiler_frame->variable[compiler_frame->current_number_of_locals].name = str; compiler_frame->current_number_of_locals++; if(compiler_frame->current_number_of_locals > compiler_frame->max_number_of_locals)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  compiler_frame->max_number_of_locals= compiler_frame->current_number_of_locals;
215bed1996-09-28Fredrik Hübinette (Hubbe)  } } } /* argument must be a shared string */ int islocal(struct pike_string *str) { int e;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  for(e=compiler_frame->current_number_of_locals-1;e>=0;e--) if(compiler_frame->variable[e].name==str)
215bed1996-09-28Fredrik Hübinette (Hubbe)  return e; return -1; }
61e9a01998-01-25Fredrik Hübinette (Hubbe)  void cleanup_compiler(void) { if(last_identifier) { free_string(last_identifier); last_identifier=0; } }