pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:103:   %left TOK_LSH TOK_RSH   %left '+' '-'   %left '*' '%' '/'   %right TOK_NOT '~'   %nonassoc TOK_INC TOK_DEC      %{   /* This is the grammar definition of Pike. */      #include "global.h" - RCSID("$Id: language.yacc,v 1.209 2000/08/30 21:58:15 grubba Exp $"); + RCSID("$Id: language.yacc,v 1.210 2000/09/05 02:18:12 hubbe Exp $");   #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"
pike.git/src/language.yacc:1511:    free_node($1);    }    | bad_identifier '=' safe_expr0 { $$=$3; }    ;      block:'{'    {    $<number>1=Pike_compiler->num_used_modules;    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    statements end_block    {    unuse_modules(Pike_compiler->num_used_modules - $<number>1);    pop_local_variables($<number>2); -  $$=$3; +  Pike_compiler->compiler_frame->last_block_level=$<number>3; +  $$=$4;    }    ;      end_block: '}'    | TOK_LEX_EOF    {    yyerror("Missing '}'.");    yyerror("Unexpected end of file.");    }    ;
pike.git/src/language.yacc:2174:       free_node($3);    check_tree($$,0);    }    ;      cond: TOK_IF    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    '(' safe_comma_expr end_cond statement optional_else_part    { -  $$=mknode('?',$4,mknode(':',$6,$7)); +  $$=mknode('?',$5,mknode(':',$7,$8));    $$->line_number=$1;    $$=mkcastnode(void_type_string,$$);    $$->line_number=$1;    pop_local_variables($<number>2); -  +  Pike_compiler->compiler_frame->last_block_level=$<number>3;    }    ;      end_cond: ')'    | '}' { yyerror("Missing ')'."); }    | TOK_LEX_EOF    {    yyerror("Missing ')'.");    yyerror("Unexpected end of file.");    }
pike.git/src/language.yacc:2210:      safe_expr0: expr0    | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }    | error { $$=0; }    ;      foreach: TOK_FOREACH    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    '(' expr0 ',' safe_lvalue end_cond statement    { -  if ($6) { -  $$=mknode(F_FOREACH, mknode(F_VAL_LVAL,$4,$6),$8); +  if ($7) { +  $$=mknode(F_FOREACH, mknode(F_VAL_LVAL,$5,$7),$9);    $$->line_number=$1;    } else {    /* Error in lvalue */ -  free_node($4); -  $$=$8; +  free_node($5); +  $$=$9;    }    pop_local_variables($<number>2); -  +  Pike_compiler->compiler_frame->last_block_level=$<number>3;    }    ;      do: TOK_DO statement TOK_WHILE '(' safe_comma_expr end_cond expected_semicolon    {    $$=mknode(F_DO,$2,$5);    $$->line_number=$1;    }    | TOK_DO statement TOK_WHILE TOK_LEX_EOF    {
pike.git/src/language.yacc:2255:    {    yyerror("Missing ';'.");    yyerror("Unexpected end of file.");    }    ;      for: TOK_FOR    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    '(' unused expected_semicolon for_expr expected_semicolon unused end_cond    statement    {    int i=lex.current_line;    lex.current_line=$1; -  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string,$4), -  mknode(F_FOR,$6,mknode(':',$10,$8))); +  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string,$5), +  mknode(F_FOR,$7,mknode(':',$11,$9)));    lex.current_line=i;    pop_local_variables($<number>2); -  +  Pike_compiler->compiler_frame->last_block_level=$<number>3;    }    ;         while: TOK_WHILE    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } -  +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    '(' safe_comma_expr end_cond statement    {    int i=lex.current_line;    lex.current_line=$1; -  $$=mknode(F_FOR,$4,mknode(':',$6,NULL)); +  $$=mknode(F_FOR,$5,mknode(':',$7,NULL));    lex.current_line=i;    pop_local_variables($<number>2); -  +  Pike_compiler->compiler_frame->last_block_level=$<number>3;    }    ;      for_expr: /* EMPTY */ { $$=mkintnode(1); }    | safe_comma_expr    ;      switch: TOK_SWITCH    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    } -  +  { +  /* Trick to store more than one number on compiler stack - Hubbe */ +  $<number>$=Pike_compiler->compiler_frame->last_block_level; +  Pike_compiler->compiler_frame->last_block_level=$<number>2; +  }    '(' safe_comma_expr end_cond statement    { -  $$=mknode(F_SWITCH,$4,$6); +  $$=mknode(F_SWITCH,$5,$7);    $$->line_number=$1;    pop_local_variables($<number>2); -  +  Pike_compiler->compiler_frame->last_block_level=$<number>3;    }    ;      case: TOK_CASE safe_comma_expr expected_colon    {    $$=mknode(F_CASE,$2,0);    }    | TOK_CASE safe_comma_expr expected_dot_dot optional_comma_expr expected_colon    {    $$=mknode(F_CASE,$4?$2:0,$4?$4:$2);
pike.git/src/language.yacc:3272:    fflush(stderr);    }   }         int low_add_local_name(struct compiler_frame *frame,    struct pike_string *str,    struct pike_string *type,    node *def)   { +  int tmp=islocal(str); +  if(tmp >= frame->last_block_level) +  { +  if(str->size_shift) +  my_yyerror("Duplicate local variable, previous declaration on line %d\n", +  frame->variable[tmp].line); +  else +  my_yyerror("Duplicate local variable '%s', previous declaration on line %d\n",STR0(str),frame->variable[tmp].line); +  } +     debug_malloc_touch(def);    debug_malloc_touch(type);    debug_malloc_touch(str);    reference_shared_string(str);    if (frame->current_number_of_locals == MAX_LOCAL)    {    yyerror("Too many local variables.");    return 0;    }else {   #ifdef PIKE_DEBUG
pike.git/src/language.yacc:3295:    if (Pike_compiler->compiler_pass != 1) {    yywarning("Declaring local variable with type void "    "(converted to type zero).");    }    free_string(type);    copy_shared_string(type, zero_type_string);    }    frame->variable[frame->current_number_of_locals].type = type;    frame->variable[frame->current_number_of_locals].name = str;    frame->variable[frame->current_number_of_locals].def = def; +  +  frame->variable[frame->current_number_of_locals].line=lex.current_line; +  frame->variable[frame->current_number_of_locals].file=lex.current_file; +  add_ref(lex.current_file); +     frame->current_number_of_locals++;    if(frame->current_number_of_locals >    frame->max_number_of_locals)    {    frame->max_number_of_locals=    frame->current_number_of_locals;    }       return frame->current_number_of_locals-1;    }