pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:169:   %left F_LSH F_RSH   %left '+' '-'   %left '*' '%' '/'   %right F_NOT '~'   %nonassoc F_INC F_DEC      %{   /* This is the grammar definition of Pike. */      #include "global.h" - RCSID("$Id: language.yacc,v 1.91 1998/04/27 18:37:39 grubba Exp $"); + RCSID("$Id: language.yacc,v 1.92 1998/04/27 21:04:53 grubba 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:350:   %type <n> typeof   %type <n> unused   %type <n> unused2   %type <n> while   %type <n> optional_comma_expr   %type <n> low_program_ref   %%      all: program { YYACCEPT; }    | program F_LEX_EOF { YYACCEPT; } + /* | error F_LEX_EOF { YYABORT; } */    ;      program: program def optional_semi_colon   /* | error { yyerrok; } */    | /* empty */    ;      optional_semi_colon: /* empty */    | ';'    ;
pike.git/src/language.yacc:995:    | F_IDENTIFIER '=' safe_expr0    {    add_ref($<n>0->u.sval.u.string);    add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string);    $$=mknode(F_ASSIGN,$3, mklocalnode(islocal($1->u.sval.u.string)));    free_node($1);    }    | bad_identifier '=' safe_expr0 { $$=$3; }    ;    -  +    block:'{'    {    $<number>1=num_used_modules;    $<number>$=compiler_frame->current_number_of_locals;    } -  statements '}' +  statements end_block    {    unuse_modules(num_used_modules - $<number>1);    pop_local_variables($<number>2);    $$=$3;    }    ;    -  + end_block: '}' +  | F_LEX_EOF +  { +  yyerror("Missing '}'."); +  yyerror("Unexpected end of file."); +  } +  ; +    failsafe_block: block -  | error { $$=0; yyerrok; } +  | error { $$=0; } +  | F_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }    ;         local_name_list: new_local_name    | local_name_list ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_ARG_LIST,$1,$4); }    ;      local_name_list2: new_local_name2    | local_name_list2 ',' { $<n>$=$<n>0; } new_local_name { $$=mknode(F_ARG_LIST,$1,$4); }    ;
pike.git/src/language.yacc:1206:       free_node($3);    check_tree($$,0);    }    ;      cond: F_IF    {    $<number>$=compiler_frame->current_number_of_locals;    } -  '(' safe_comma_expr ')' statement optional_else_part +  '(' safe_comma_expr end_cond statement optional_else_part    {    $$=mknode('?',$4,mknode(':',$6,$7));    $$->line_number=$1;    $$=mkcastnode(void_type_string,$$);    $$->line_number=$1;    pop_local_variables($<number>2);    }    ;    -  + end_cond: ')' +  | '}' { yyerror("Missing ')'."); } +  | F_LEX_EOF +  { +  yyerror("Missing ')'."); +  yyerror("Unexpected end of file."); +  } +  ; +    optional_else_part: { $$=0; }    | F_ELSE statement { $$=$2; }    ;      safe_lvalue: lvalue    | error { $$=0; }    ;      safe_expr0: expr0    | error { $$=mkintnode(0); }    ;      foreach: F_FOREACH    {    $<number>$=compiler_frame->current_number_of_locals;    } -  '(' safe_expr0 ',' safe_lvalue ')' statement +  '(' safe_expr0 ',' safe_lvalue end_cond statement    {    if ($6) {    $$=mknode(F_FOREACH, mknode(F_VAL_LVAL,$4,$6),$8);    $$->line_number=$1;    } else {    /* Error in lvalue */    free_node($4);    $$=$8;    }    pop_local_variables($<number>2);    }    ;    - do: F_DO statement F_WHILE '(' safe_comma_expr ')' ';' + do: F_DO statement F_WHILE '(' safe_comma_expr end_cond expected_semicolon    {    $$=mknode(F_DO,$2,$5);    $$->line_number=$1;    }    ;    -  + expected_semicolon: ';' +  | F_LEX_EOF +  { +  yyerror("Missing ';'."); +  yyerror("Unexpected end of file."); +  } +  ; +    for: F_FOR    {    $<number>$=compiler_frame->current_number_of_locals;    } -  '(' unused ';' for_expr ';' unused ')' statement +  '(' unused expected_semicolon for_expr expected_semicolon unused end_cond +  statement    {    int i=lex.current_line;    lex.current_line=$1;    $$=mknode(F_ARG_LIST,mkcastnode(void_type_string,$4),mknode(F_FOR,$6,mknode(':',$10,$8)));    lex.current_line=i;    pop_local_variables($<number>2);    }    ;         while: F_WHILE    {    $<number>$=compiler_frame->current_number_of_locals;    } -  '(' safe_comma_expr ')' statement +  '(' safe_comma_expr end_cond statement    {    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);    }    ;      for_expr: /* EMPTY */ { $$=mkintnode(1); }    | safe_comma_expr    ;      switch: F_SWITCH    {    $<number>$=compiler_frame->current_number_of_locals;    } -  '(' safe_comma_expr ')' statement +  '(' safe_comma_expr end_cond statement    {    $$=mknode(F_SWITCH,$4,$6);    $$->line_number=$1;    pop_local_variables($<number>2);    }    ;    - case: F_CASE safe_comma_expr ':' + case: F_CASE safe_comma_expr expected_colon    {    $$=mknode(F_CASE,$2,0);    } -  | F_CASE safe_comma_expr F_DOT_DOT optional_comma_expr ':' +  | F_CASE safe_comma_expr F_DOT_DOT optional_comma_expr expected_colon    {    $$=mknode(F_CASE,$4?$2:0,$4?$4:$2);    }    ;    -  + expected_colon: ':' +  | F_LEX_EOF +  { +  yyerror("Missing ';'."); +  yyerror("Unexpected end of file."); +  } +  ; +    return: F_RETURN    {    if(!match_types(compiler_frame->current_return_type,    void_type_string))    {    yyerror("Must return a value for a non-void function.");    }    $$=mknode(F_RETURN,mkintnode(0),0);    }    | F_RETURN safe_comma_expr
pike.git/src/language.yacc:1410:    if ($3) {    $$=mknode(F_ARG_LIST,$1,$3);    } else {    /* Error in assoc_pair */    $$=$1;    }    }    | m_expr_list2 ',' error    ;    - assoc_pair: expr0 ':' expr1 { $$=mknode(F_ARG_LIST,$1,$3); } -  | expr0 ':' error { free_node($1); $$=0; } + assoc_pair: expr0 expected_colon expr1 { $$=mknode(F_ARG_LIST,$1,$3); } +  | expr0 expected_colon error { free_node($1); $$=0; }    ;      expr1: expr2    | 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); }