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. */
7202151998-04-29Fredrik Hübinette (Hubbe) %token F_OFFSET
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_PREFIX_256 F_PREFIX_512 F_PREFIX_768 F_PREFIX_1024 %token F_PREFIX_CHARX256 F_PREFIX_WORDX256 F_PREFIX_24BITX256
fe574a1998-11-16Fredrik Hübinette (Hubbe) %token F_POP_VALUE F_POP_N_ELEMS F_MARK F_MARK2 F_MARK_X F_POP_MARK %token F_LDA 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
a7538d1998-05-12Fredrik Hübinette (Hubbe) %token F_BRANCH_IF_LOCAL F_BRANCH_IF_NOT_LOCAL %token F_BRANCH_IF_NOT_LOCAL_ARROW
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_INC_LOOP F_DEC_LOOP %token F_INC_NEQ_LOOP F_DEC_NEQ_LOOP
4218011999-01-31Fredrik Hübinette (Hubbe) %token F_LEXICAL_LOCAL F_LEXICAL_LOCAL_LVALUE
dffa011997-01-15Fredrik Hübinette (Hubbe) %token F_INDEX F_ARROW F_INDIRECT F_STRING_INDEX F_LOCAL_INDEX
a7538d1998-05-12Fredrik Hübinette (Hubbe) %token F_LOCAL_LOCAL_INDEX F_LOCAL_ARROW F_GLOBAL_LOCAL_INDEX
624f571999-03-11Fredrik Hübinette (Hubbe) %token F_POS_INT_INDEX F_NEG_INT_INDEX F_MAGIC_INDEX F_MAGIC_SET_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 */
4218011999-01-31Fredrik Hübinette (Hubbe) %token F_LFUN F_TRAMPOLINE
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %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
ece3201999-08-02Fredrik Hübinette (Hubbe) %token F_UNDEFINED
215bed1996-09-28Fredrik Hübinette (Hubbe) /* * 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
0f19431999-11-29Fredrik Hübinette (Hubbe) %token F_RETURN_IF_TRUE 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
a7538d1998-05-12Fredrik Hübinette (Hubbe) %token F_LOCAL_2_LOCAL F_LOCAL_2_GLOBAL F_GLOBAL_2_LOCAL
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
1d73ef1999-11-23Henrik Grubbström (Grubba) %token F_SOFT_CAST
215bed1996-09-28Fredrik Hübinette (Hubbe) %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 */
a7538d1998-05-12Fredrik Hübinette (Hubbe) %token F_MAX_OPCODE
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. */ %token F_LEX_EOF
215bed1996-09-28Fredrik Hübinette (Hubbe) %token F_ADD_EQ %token F_AND_EQ %token F_ARG_LIST
3d78821999-11-06Henrik Grubbström (Grubba) %token F_COMMA_EXPR
215bed1996-09-28Fredrik Hübinette (Hubbe) %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
21b2c91999-12-17Fredrik Hübinette (Hubbe) %token F_OPTIONAL
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"
df13b71999-12-18Henrik Grubbström (Grubba) RCSID("$Id: language.yacc,v 1.152 1999/12/18 02:13:20 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"
215bed1996-09-28Fredrik Hübinette (Hubbe) #include "error.h" #include "docode.h"
4868db1997-05-07Per Hedbor #include "machine.h"
b9188f1999-12-13Henrik Grubbström (Grubba) #include "main.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) 
a566ca1999-12-14Fredrik Hübinette (Hubbe) void add_local_name(struct pike_string *,struct pike_string *,node *);
4218011999-01-31Fredrik Hübinette (Hubbe) static node *lexical_islocal(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) 
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;
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) %}
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_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 %type <number> optional_dot_dot_dot %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 %type <n> F_STRING
011ad31999-10-22Fredrik Hübinette (Hubbe) %type <n> F_NUMBER
3c0c281998-01-26Fredrik Hübinette (Hubbe) %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
a566ca1999-12-14Fredrik Hübinette (Hubbe) %type <n> local_function %type <n> local_function2
315aa81999-12-17Fredrik Hübinette (Hubbe) %type <n> magic_identifier
215bed1996-09-28Fredrik Hübinette (Hubbe) %%
db271d1998-04-27Henrik Grubbström (Grubba) all: program { YYACCEPT; } | program F_LEX_EOF { YYACCEPT; }
73a2a11998-04-27Henrik Grubbström (Grubba) /* | error F_LEX_EOF { YYABORT; } */
8c77b61998-04-13Henrik Grubbström (Grubba)  ;
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) 
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)  if(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);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  $$=mksvaluenode(sp-1);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if($$->name) free_string($$->name);
454d541999-09-18Fredrik Hübinette (Hubbe)  add_ref( $$->name=sp[-2].u.string );
61e9a01998-01-25Fredrik Hübinette (Hubbe)  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) 
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)  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; }
db271d1998-04-27Henrik Grubbström (Grubba)  | modifiers F_INHERIT low_program_ref error F_LEX_EOF { free_node($3); yyerror("Missing ';'."); yyerror("Unexpected end of file."); } | modifiers F_INHERIT low_program_ref error '}' { free_node($3); yyerror("Missing ';'."); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers F_INHERIT error ';' { yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | modifiers F_INHERIT error F_LEX_EOF { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } | modifiers F_INHERIT error '}' { yyerror("Missing ';'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
97358e1998-04-23Fredrik Hübinette (Hubbe) import: F_IMPORT idents ';'
591c0c1997-01-19Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  resolv_constant($2); free_node($2);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  use_module(sp-1);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  pop_stack();
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | F_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); }
eb5c901998-04-19Fredrik Hübinette (Hubbe)  use_module(sp-1); pop_stack(); }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | F_IMPORT error ';' { yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | F_IMPORT error F_LEX_EOF { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } | F_IMPORT error '}' { yyerror("Missing ';'."); }
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;
3d78821999-11-06Henrik Grubbström (Grubba)  $3=mknode(F_COMMA_EXPR,$3,0);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  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.");
a786431999-11-18Martin Stjernholm  else add_constant($1->u.sval.u.string,0, current_modifiers);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } else {
57cddc1998-04-19Per Hedbor  if(!num_parse_error)
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  {
57cddc1998-04-19Per Hedbor  tmp=eval_low($3); if(tmp < 1) { yyerror("Error in constant definition."); }else{ pop_n_elems(tmp-1); add_constant($1->u.sval.u.string,sp-1,current_modifiers); 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 ;
3bcd581997-04-08Marcus Comstedt constant: modifiers F_CONSTANT constant_list ';' {}
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers F_CONSTANT error ';' { yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | modifiers F_CONSTANT error F_LEX_EOF { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } | modifiers F_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; } | F_LEX_EOF { yyerror("Expected ';'."); $$ = NULL; } | 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 */
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)  ;
76b4491999-12-09Henrik Grubbström (Grubba)  close_paren_or_missing: ')' | /* empty */ { yyerror("Missing ')'."); } ; 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)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  push_compiler_frame(0);
b5aa651999-12-16Henrik Grubbström (Grubba) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  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); } }
3ec3df1999-12-16Henrik Grubbström (Grubba)  ; def: modifiers type_or_error optional_stars F_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 */
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);
4142a61998-05-19Fredrik Hübinette (Hubbe)  compiler_frame->current_return_type=compiler_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) 
3ec3df1999-12-16Henrik Grubbström (Grubba)  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)  {
4142a61998-05-19Fredrik Hübinette (Hubbe)  struct pike_string *s=compiler_pop_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $<n>$=mkstrnode(s); free_string(s); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(compiler_pass==1) {
3ec3df1999-12-16Henrik Grubbström (Grubba)  $<number>5=define_function(check_node_hash($4)->u.sval.u.string,
498ec11999-11-12Henrik Grubbström (Grubba)  check_node_hash($<n>$)->u.sval.u.string, $1, IDENTIFIER_PIKE_FUNCTION, 0);
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;
3ec3df1999-12-16Henrik Grubbström (Grubba)  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)
b9188f1999-12-13Henrik Grubbström (Grubba)  { my_yyerror("Missing name for argument %d.",e); } else { /* FIXME: Should probably use some other flag. */
7d955e1999-12-13Henrik Grubbström (Grubba)  if ((runtime_options & RUNTIME_CHECK_TYPES) && (compiler_pass == 2) &&
b9188f1999-12-13Henrik Grubbström (Grubba)  (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(compiler_frame->variable[e].type, local_node));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
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) 
3ec3df1999-12-16Henrik Grubbström (Grubba)  f=dooptcode(check_node_hash($4)->u.sval.u.string, check_node_hash($10), check_node_hash($<n>9)->u.sval.u.string, $1);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
294dc51997-08-03Fredrik Hübinette (Hubbe)  if(recoveries && sp-evaluator_stack < recoveries->sp) fatal("Stack error (underflow)\n");
ae95031999-04-07Fredrik Hübinette (Hubbe) 
3ec3df1999-12-16Henrik Grubbström (Grubba)  if(compiler_pass == 1 && f!=$<number>5) fatal("define_function screwed up! %d != %d\n",f,$<number>5);
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);
3ec3df1999-12-16Henrik Grubbström (Grubba)  free_node($<n>9);
b5aa651999-12-16Henrik Grubbström (Grubba)  } | modifiers type_or_error optional_stars F_IDENTIFIER push_compiler_frame0 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 '(' arguments ')' block_or_semi {
4142a61998-05-19Fredrik Hübinette (Hubbe)  free_string(compiler_pop_type());
8c77b61998-04-13Henrik Grubbström (Grubba)  }
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); }
db271d1998-04-27Henrik Grubbström (Grubba)  | error F_LEX_EOF { reset_type_stack(); yyerror("Missing ';'."); yyerror("Unexpected end of file"); }
07f33e1998-11-05Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); yyerrok; /* if(num_parse_error>5) YYACCEPT; */ }
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)  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
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)  { 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) 
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) 
76b4491999-12-09Henrik Grubbström (Grubba) func_args: '(' arguments close_paren_or_missing { $$=$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)  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; }
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | F_OPTIONAL { $$ = ID_OPTIONAL; }
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) 
315aa81999-12-17Fredrik Hübinette (Hubbe) magic_identifiers1: F_NO_MASK { $$ = "nomask"; } | F_FINAL_ID { $$ = "final"; } | F_STATIC { $$ = "static"; } | F_PRIVATE { $$ = "private"; } | F_LOCAL_ID { $$ = "local"; } | F_PUBLIC { $$ = "public"; } | F_PROTECTED { $$ = "protected"; } | F_INLINE { $$ = "inline"; }
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | F_OPTIONAL { $$ = "optional"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers2: F_VOID_ID { $$ = "void"; } | F_MIXED_ID { $$ = "mixed"; } | F_ARRAY_ID { $$ = "array"; } | F_MAPPING_ID { $$ = "mapping"; } | F_MULTISET_ID { $$ = "multiset"; } | F_OBJECT_ID { $$ = "object"; } | F_FUNCTION_ID { $$ = "function"; } | F_PROGRAM_ID { $$ = "program"; } | F_STRING_ID { $$ = "string"; } | F_FLOAT_ID { $$ = "float"; } | F_INT_ID { $$ = "int"; } ; magic_identifiers3: F_IF { $$ = "if"; } | F_DO { $$ = "do"; } | F_FOR { $$ = "for"; } | F_WHILE { $$ = "while"; } | F_ELSE { $$ = "else"; } | F_FOREACH { $$ = "foreach"; } | F_CATCH { $$ = "catch"; } | F_GAUGE { $$ = "gauge"; } | F_CLASS { $$ = "class"; } | F_BREAK { $$ = "break"; } | F_CASE { $$ = "case"; } | F_CONSTANT { $$ = "constant"; } | F_CONTINUE { $$ = "continue"; } | F_DEFAULT { $$ = "default"; } | F_IMPORT { $$ = "import"; } | F_INHERIT { $$ = "inherit"; } | F_LAMBDA { $$ = "lambda"; } | F_PREDEF { $$ = "predef"; } | F_RETURN { $$ = "return"; } | F_SSCANF { $$ = "sscanf"; } | F_SWITCH { $$ = "switch"; } | F_TYPEOF { $$ = "typeof"; } ;
21b2c91999-12-17Fredrik Hübinette (Hubbe) magic_identifiers: magic_identifiers1 | magic_identifiers2 | magic_identifiers3 ; magic_identifier: F_IDENTIFIER | 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 { $$=current_modifiers=$1 | (lex.pragmas & ID_MODIFIER_MASK); } ;
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); } ;
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 {
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 { struct program *p; resolv_program($1); if((p=program_from_svalue(sp-1))) {
34224f1998-04-18Fredrik Hübinette (Hubbe)  push_type_int(p->id);
6bc9281998-04-10Fredrik Hübinette (Hubbe)  }else{ push_type_int(0); } push_type(0); push_type(T_OBJECT); pop_stack(); free_node($1); } ;
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) 
b660c81999-03-01Fredrik Hübinette (Hubbe) type3: F_INT_ID opt_int_range { 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); }
b660c81999-03-01Fredrik Hübinette (Hubbe)  | F_STRING_ID { 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) 
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)  } | F_NUMBER ; number_or_minint: /* Empty */ {
011ad31999-10-22Fredrik Hübinette (Hubbe)  $$ = mkintnode(MIN_INT32);
f5fd531999-03-29Henrik Grubbström (Grubba)  } | F_NUMBER ; opt_int_range: /* Empty */ { push_type_int(MAX_INT32); push_type_int(MIN_INT32); } | '(' number_or_minint F_DOT_DOT number_or_maxint ')' { /* FIXME: Check that $4 is >= $2. */
011ad31999-10-22Fredrik Hübinette (Hubbe)  if($2->token == F_CONSTANT && $2->u.sval.type == T_INT) { 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: * sp-2: Name of the program reference (string). * sp-1: The resolved program (program|function|zero). */
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{
a786431999-11-18Martin Stjernholm  if (compiler_pass!=1) { if ((sp[-2].type == T_STRING) && (sp[-2].u.string->len > 0) && (sp[-2].u.string->len < 256)) { my_yyerror("Not a valid program specifier: '%s'", sp[-2].u.string->str); } 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) { 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);
327c051999-11-24Fredrik Hübinette (Hubbe)  push_type(T_VOID); push_type(T_OR);
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
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)  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);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_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);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_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 {
3d78821999-11-06Henrik Grubbström (Grubba)  init_node=mknode(F_COMMA_EXPR,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)  }
2968361998-04-14Henrik Grubbström (Grubba)  | optional_stars F_IDENTIFIER '=' error { free_node($2); }
e67c861998-08-01Henrik Grubbström (Grubba)  | optional_stars F_IDENTIFIER '=' F_LEX_EOF { 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)  new_local_name: optional_stars F_IDENTIFIER
6bbfee1999-11-21Henrik Grubbström (Grubba)  {
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);
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; } | optional_stars F_IDENTIFIER '=' expr0
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);
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)  } | optional_stars F_IDENTIFIER '=' error { 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)  }
e67c861998-08-01Henrik Grubbström (Grubba)  | optional_stars F_IDENTIFIER '=' F_LEX_EOF { 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) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) new_local_name2: F_IDENTIFIER {
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; }
998e1f1998-04-15Henrik Grubbström (Grubba)  | F_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)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  $<number>1=num_used_modules;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  $<number>$=compiler_frame->current_number_of_locals;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
73a2a11998-04-27Henrik Grubbström (Grubba)  statements end_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  unuse_modules(num_used_modules - $<number>1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=$3; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_block: '}' | F_LEX_EOF { yyerror("Missing '}'."); yyerror("Unexpected end of file."); } ;
01d3e21997-04-23Fredrik Hübinette (Hubbe) failsafe_block: block
73a2a11998-04-27Henrik Grubbström (Grubba)  | error { $$=0; } | F_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
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 {
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) 
97358e1998-04-23Fredrik Hübinette (Hubbe) statement: unused2 ';' | import { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cond | while | do | for | switch | case | default
586b8a1998-04-28Henrik Grubbström (Grubba)  | return expected_semicolon
97358e1998-04-23Fredrik Hübinette (Hubbe)  | block
7e50571996-11-02Fredrik Hübinette (Hubbe)  | foreach
586b8a1998-04-28Henrik Grubbström (Grubba)  | break expected_semicolon | continue expected_semicolon
e2acf71997-04-23Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); $$=0; yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | error F_LEX_EOF { 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)  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); } ;
b5aa651999-12-16Henrik Grubbström (Grubba) push_compiler_frame1: /* empty */
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  push_compiler_frame(1);
b5aa651999-12-16Henrik Grubbström (Grubba)  } ; lambda: F_LAMBDA push_compiler_frame1 { debug_malloc_touch(compiler_frame->current_return_type);
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;
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($5); $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0)); type=find_return_type($5);
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;
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);
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", (long)new_program->id,
c4d4681998-06-06Henrik Grubbström (Grubba)  (long)(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", compiler_pass, buf, (long)new_program->id, local_class_counter-1); #endif /* LAMBDA_DEBUG */
8267f41998-01-28Fredrik Hübinette (Hubbe)  f=dooptcode(name,
b5aa651999-12-16Henrik Grubbström (Grubba)  $5,
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) 
498ec11999-11-12Henrik Grubbström (Grubba)  if(compiler_frame->lexical_scope == 2) { $$ = 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)  }
b5aa651999-12-16Henrik Grubbström (Grubba)  | F_LAMBDA push_compiler_frame1 error { pop_compiler_frame(); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba) local_function: F_IDENTIFIER push_compiler_frame1
a566ca1999-12-14Fredrik Hübinette (Hubbe)  { debug_malloc_touch(compiler_frame->current_return_type); if(compiler_frame->current_return_type) free_string(compiler_frame->current_return_type);
b5aa651999-12-16Henrik Grubbström (Grubba)  copy_shared_string(compiler_frame->current_return_type, $<n>0->u.sval.u.string);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  } func_args failsafe_block { struct pike_string *type; char buf[40]; int f,e; struct pike_string *name;
b5aa651999-12-16Henrik Grubbström (Grubba)  $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0));
a566ca1999-12-14Fredrik Hübinette (Hubbe)  push_finished_type(compiler_frame->current_return_type);
b5aa651999-12-16Henrik Grubbström (Grubba)  e=$4-1;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  if(varargs) { push_finished_type(compiler_frame->variable[e].type); e--; varargs=0; pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) push_finished_type(compiler_frame->variable[e].type); push_type(T_FUNCTION); type=compiler_pop_type(); sprintf(buf,"__lambda_%ld_%ld", (long)new_program->id, (long)(local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */ name=make_shared_string(buf); #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n", compiler_pass, buf, (long)new_program->id, local_class_counter-1); #endif /* LAMBDA_DEBUG */
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($5);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  f=dooptcode(name,
b5aa651999-12-16Henrik Grubbström (Grubba)  $5,
a566ca1999-12-14Fredrik Hübinette (Hubbe)  type,
c6eb961999-12-14Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  if(compiler_frame->lexical_scope == 2) { $$ = mktrampolinenode(f); } else { $$ = mkidentifiernode(f); } debug_malloc_touch($$); pop_compiler_frame(); add_local_name($1->u.sval.u.string, type, copy_node( $$ )); free_node($1); free_string(name); }
b5aa651999-12-16Henrik Grubbström (Grubba)  | F_IDENTIFIER push_compiler_frame1 error { pop_compiler_frame(); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  ;
b5aa651999-12-16Henrik Grubbström (Grubba) local_function2: optional_stars F_IDENTIFIER push_compiler_frame1
a566ca1999-12-14Fredrik Hübinette (Hubbe)  { debug_malloc_touch(compiler_frame->current_return_type); push_finished_type($<n>0->u.sval.u.string); while($1--) push_type(T_ARRAY); if(compiler_frame->current_return_type) free_string(compiler_frame->current_return_type); compiler_frame->current_return_type=compiler_pop_type(); } func_args failsafe_block { struct pike_string *type; char buf[40]; int f,e; struct pike_string *name;
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)  push_finished_type(compiler_frame->current_return_type);
b5aa651999-12-16Henrik Grubbström (Grubba)  e=$5-1;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  if(varargs) { push_finished_type(compiler_frame->variable[e].type); e--; varargs=0; pop_type_stack(); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) push_finished_type(compiler_frame->variable[e].type); push_type(T_FUNCTION); type=compiler_pop_type(); sprintf(buf,"__lambda_%ld_%ld", (long)new_program->id, (long)(local_class_counter++ & 0xffffffff)); /* OSF/1 cc bug. */ name=make_shared_string(buf); #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n", compiler_pass, buf, (long)new_program->id, local_class_counter-1); #endif /* LAMBDA_DEBUG */
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($6);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  f=dooptcode(name,
b5aa651999-12-16Henrik Grubbström (Grubba)  $6,
a566ca1999-12-14Fredrik Hübinette (Hubbe)  type,
c6eb961999-12-14Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  if(compiler_frame->lexical_scope == 2) { $$ = mktrampolinenode(f); } else { $$ = mkidentifiernode(f); } debug_malloc_touch($$); pop_compiler_frame(); add_local_name($2->u.sval.u.string, type, copy_node( $$ )); free_node($2); free_string(name); }
b5aa651999-12-16Henrik Grubbström (Grubba)  | optional_stars F_IDENTIFIER push_compiler_frame1 error { pop_compiler_frame(); free_node($2); }
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; }
e67c861998-08-01Henrik Grubbström (Grubba)  | F_LEX_EOF { yyerror("End of file where program definition expected."); }
febbc81997-04-22Fredrik Hübinette (Hubbe)  ;
51ffdb1998-01-19Fredrik Hübinette (Hubbe) class: modifiers F_CLASS optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
23eecd1999-08-06Fredrik Hübinette (Hubbe)  extern int num_parse_error; int num_errors=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];
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);
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"); */
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);
58ef5e1999-10-19Fredrik Hübinette (Hubbe)  if(lex.current_file) { store_linenumber(lex.current_line, lex.current_file); debug_malloc_name(new_program, lex.current_file->str, lex.current_line); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ int i; struct program *p; struct identifier *id;
e37a3e1999-10-09Fredrik Hübinette (Hubbe)  int tmp=compiler_pass;
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;
43fc171999-09-19Fredrik Hübinette (Hubbe)  s=&PROG_FROM_INT(new_program,i)->constants[id->func.offset].sval;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  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); } }
e37a3e1999-10-09Fredrik Hübinette (Hubbe)  compiler_pass=tmp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
23eecd1999-08-06Fredrik Hübinette (Hubbe)  num_parse_error=num_errors; /* Kluge to prevent gazillion error messages */
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
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"); */
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; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond 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) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_cond: ')' | '}' { yyerror("Missing ')'."); } | F_LEX_EOF { yyerror("Missing ')'."); yyerror("Unexpected end of file."); } ;
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
97358e1998-04-23Fredrik Hübinette (Hubbe)  | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ; safe_expr0: expr0
498ec11999-11-12Henrik Grubbström (Grubba)  | F_LEX_EOF { yyerror("Unexpected end of file."); $$=0; } | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) foreach: F_FOREACH { $<number>$=compiler_frame->current_number_of_locals; }
902c291998-07-31Fredrik Hübinette (Hubbe)  '(' expr0 ',' safe_lvalue end_cond 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) 
73a2a11998-04-27Henrik Grubbström (Grubba) do: F_DO statement F_WHILE '(' safe_comma_expr end_cond expected_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_DO,$2,$5); $$->line_number=$1; }
07f33e1998-11-05Henrik Grubbström (Grubba)  | F_DO statement F_WHILE F_LEX_EOF { $$=0; yyerror("Missing '(' in do-while loop."); yyerror("Unexpected end of file."); } | F_DO statement F_LEX_EOF { $$=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: ';' | F_LEX_EOF { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } ;
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; }
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;
3d78821999-11-06Henrik Grubbström (Grubba)  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string,$4), mknode(F_FOR,$6,mknode(':',$10,$8)));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  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; }
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; $$=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; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond 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) 
73a2a11998-04-27Henrik Grubbström (Grubba) case: F_CASE safe_comma_expr expected_colon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_CASE,$2,0); }
73a2a11998-04-27Henrik Grubbström (Grubba)  | F_CASE safe_comma_expr F_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 ':'."); } | '}' { yyerror("Missing ':'."); }
73a2a11998-04-27Henrik Grubbström (Grubba)  | F_LEX_EOF {
3d78821999-11-06Henrik Grubbström (Grubba)  yyerror("Missing ':'.");
73a2a11998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); } ;
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
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)  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; }
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) 
73a2a11998-04-27Henrik Grubbström (Grubba) assoc_pair: expr0 expected_colon expr1 { $$=mknode(F_ARG_LIST,$1,$3); } | expr0 expected_colon error { free_node($1); $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
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); }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 F_LOR error | expr1 F_LAND error | expr1 '|' error | expr1 '^' error | expr1 '&' error | expr1 F_EQ error | expr1 F_NE error | expr1 '>' error | expr1 F_GE error | expr1 '<' error | expr1 F_LE error | expr1 F_LSH error | expr1 F_RSH error | 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); }
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
011ad31999-10-22Fredrik Hübinette (Hubbe)  | F_NUMBER
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; }
db271d1998-04-27Henrik Grubbström (Grubba)  | expr4 '(' error F_LEX_EOF { 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); } | 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; }
db271d1998-04-27Henrik Grubbström (Grubba)  | expr4 '[' error F_LEX_EOF { $$=$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); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | F_MULTISET_START expr_list F_MULTISET_END { $$=mkefuncallnode("aggregate_multiset",$2); }
76b4491999-12-09Henrik Grubbström (Grubba)  | F_MULTISET_START expr_list ')' { yyerror("Missing '>'."); $$=mkefuncallnode("aggregate_multiset",$2); }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error ')' { $$=0; yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | '(' error F_LEX_EOF {
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 ')'."); }
76b4491999-12-09Henrik Grubbström (Grubba)  | F_MULTISET_START error F_MULTISET_END { $$=0; yyerrok; } | F_MULTISET_START error ')' { yyerror("Missing '>'."); $$=0; yyerrok; } | F_MULTISET_START error F_LEX_EOF { $$=0; yyerror("Missing '>)'."); yyerror("Unexpected end of file."); } | F_MULTISET_START error ';' { $$=0; yyerror("Missing '>)'."); } | F_MULTISET_START error '}' { $$=0; yyerror("Missing '>)'."); }
315aa81999-12-17Fredrik Hübinette (Hubbe)  | expr4 F_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)  }
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 {
fae37d1998-08-30Henrik Grubbström (Grubba)  $$=index_node($1, last_identifier?last_identifier->str:NULL, $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)  }
eb5c901998-04-19Fredrik Hübinette (Hubbe)  | '.' F_IDENTIFIER { 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); }
eb5c901998-04-19Fredrik Hübinette (Hubbe)  tmp=mkconstantsvaluenode(sp-1); 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); if(last_identifier) free_string(last_identifier); copy_shared_string(last_identifier, $2->u.sval.u.string); 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)  ; 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);
4218011999-01-31Fredrik Hübinette (Hubbe)  if(($$=lexical_islocal(last_identifier)))
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  /* done, nothing to do here */
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))){
d43aff1997-08-03Fredrik Hübinette (Hubbe)  if(!num_parse_error)
dffa011997-01-15Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  if(compiler_pass==2) { my_yyerror("'%s' undefined.", last_identifier->str); $$=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)  } | 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__ */
fae37d1998-08-30Henrik Grubbström (Grubba)  if(last_identifier) free_string(last_identifier); copy_shared_string(last_identifier, $3->u.sval.u.string);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  tmp.u.mapping=get_builtin_constants(); tmp2=mkconstantsvaluenode(&tmp);
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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_PREDEF F_COLON_COLON bad_identifier {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_IDENTIFIER F_COLON_COLON F_IDENTIFIER {
fae37d1998-08-30Henrik Grubbström (Grubba)  if(last_identifier) free_string(last_identifier); copy_shared_string(last_identifier, $3->u.sval.u.string);
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);
a005eb1999-03-04Fredrik Hübinette (Hubbe) 
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);
498ec11999-11-12Henrik Grubbström (Grubba)  $$=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
4d21331998-04-14Henrik Grubbström (Grubba)  | F_IDENTIFIER F_COLON_COLON error
7e50571996-11-02Fredrik Hübinette (Hubbe)  | F_COLON_COLON F_IDENTIFIER { int e,i;
fae37d1998-08-30Henrik Grubbström (Grubba)  if(last_identifier) free_string(last_identifier); copy_shared_string(last_identifier, $2->u.sval.u.string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=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;
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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_COLON_COLON bad_identifier {
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
498ec11999-11-12Henrik Grubbström (Grubba)  | F_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
1c858f1999-11-14Henrik Grubbström (Grubba)  | F_LEX_EOF { yyerror("Unexpected end of file."); $$=mkintnode(0x7fffffff); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  gauge: F_GAUGE catch_arg {
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)  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;
3d78821999-11-06Henrik Grubbström (Grubba)  /* FIXME: Why build the node at all? */ tmp=mknode(F_COMMA_EXPR,$3,0);
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
b660c81999-03-01Fredrik Hübinette (Hubbe)  s=describe_type( tmp && CAR(tmp) && CAR(tmp)->type ? CAR(tmp)->type : mixed_type_string);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  $$=mkstrnode(s); free_string(s);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_node(tmp);
4d21331998-04-14Henrik Grubbström (Grubba)  }
498ec11999-11-12Henrik Grubbström (Grubba)  | F_TYPEOF '(' error ')' { $$=0; yyerrok; } | F_TYPEOF '(' error '}' { $$=0; yyerror("Missing ')'."); }
db271d1998-04-27Henrik Grubbström (Grubba)  | F_TYPEOF '(' error F_LEX_EOF {
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)  | F_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; }
db271d1998-04-27Henrik Grubbström (Grubba)  | '(' error F_LEX_EOF {
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) 
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 ')' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | F_SSCANF '(' expr0 ',' expr0 error F_LEX_EOF {
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."); } | F_SSCANF '(' expr0 ',' expr0 error '}' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); } | F_SSCANF '(' expr0 ',' expr0 error ';' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); }
4d21331998-04-14Henrik Grubbström (Grubba)  | F_SSCANF '(' expr0 error ')' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | F_SSCANF '(' expr0 error F_LEX_EOF {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); yyerror("Unexpected end of file."); } | F_SSCANF '(' expr0 error '}' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); } | F_SSCANF '(' expr0 error ';' {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); }
498ec11999-11-12Henrik Grubbström (Grubba)  | F_SSCANF '(' error ')' { $$=0; yyerrok; }
db271d1998-04-27Henrik Grubbström (Grubba)  | F_SSCANF '(' error F_LEX_EOF {
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)  | F_SSCANF '(' error '}' { $$=0; yyerror("Missing ')'."); } | F_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); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | type6 F_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) 
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 */
07f85b1998-08-30Henrik Grubbström (Grubba) /* FIXME: Should probably set last_identifier. */
1d73ef1999-11-23Henrik Grubbström (Grubba) bad_identifier: bad_expr_ident
39245b1998-04-17Henrik Grubbström (Grubba)  | F_CLASS { yyerror("class is a reserved word."); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_ARRAY_ID { yyerror("array is a reserved word."); } | F_FLOAT_ID { yyerror("float is a reserved word.");}
39245b1998-04-17Henrik Grubbström (Grubba)  | F_FUNCTION_ID { yyerror("function is a reserved word.");}
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_INT_ID { yyerror("int is a reserved word."); } | F_MAPPING_ID { yyerror("mapping is a reserved word."); }
39245b1998-04-17Henrik Grubbström (Grubba)  | F_MIXED_ID { yyerror("mixed is a reserved word."); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_MULTISET_ID { yyerror("multiset is a reserved word."); }
39245b1998-04-17Henrik Grubbström (Grubba)  | F_OBJECT_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("object is a reserved word."); }
39245b1998-04-17Henrik Grubbström (Grubba)  | F_PROGRAM_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("program is a reserved word."); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | F_STRING_ID { yyerror("string is a reserved word."); } | F_VOID_ID { yyerror("void is a reserved word."); }
a663191998-04-17Henrik Grubbström (Grubba)  ; bad_expr_ident: F_INLINE { yyerror("inline is a reserved word."); } | F_LOCAL_ID { 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."); }
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | F_OPTIONAL { yyerror("optional is a reserved word."); }
a663191998-04-17Henrik Grubbström (Grubba)  | F_STATIC { yyerror("static is a reserved word."); } | F_FINAL_ID { yyerror("final 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
2a7c7c1999-07-18Fredrik Hübinette (Hubbe)  { yyerror("else without if."); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | 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_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_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) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
294dc51997-08-03Fredrik Hübinette (Hubbe)  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) 
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); } }
3c0c281998-01-26Fredrik Hübinette (Hubbe) /* argument must be a shared string */
e73dae1998-04-17Fredrik Hübinette (Hubbe) /* Note that this function eats a reference to 'type' */
a566ca1999-12-14Fredrik Hübinette (Hubbe) /* If def is nonzero, it also eats a ref to def */
215bed1996-09-28Fredrik Hübinette (Hubbe) void add_local_name(struct pike_string *str,
a566ca1999-12-14Fredrik Hübinette (Hubbe)  struct pike_string *type, node *def)
215bed1996-09-28Fredrik 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);
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 {
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)) {
5fdb4d1999-12-18Henrik Grubbström (Grubba)  yywarning("Declaring local variable with type void " "(converted to type zero)."); free_string(type); copy_shared_string(type, zero_type_string); }
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;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  compiler_frame->variable[compiler_frame->current_number_of_locals].def = def;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  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) 
4218011999-01-31Fredrik Hübinette (Hubbe) /* argument must be a shared string */ static node *lexical_islocal(struct pike_string *str) { int e,depth=0; struct compiler_frame *f=compiler_frame; while(1) { for(e=f->current_number_of_locals-1;e>=0;e--) { if(f->variable[e].name==str) { struct compiler_frame *q=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) { q->lexical_scope=2; q=q->previous; } return mklocalnode(e,depth); } } if(!f->lexical_scope) return 0; depth++; f=f->previous; } }
61e9a01998-01-25Fredrik Hübinette (Hubbe) void cleanup_compiler(void) { if(last_identifier) { free_string(last_identifier); last_identifier=0; } }