pike.git/
src/
language.yacc
Branch:
Tag:
Non-build tags
All tags
No tags
1998-04-14
1998-04-14 19:17:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>
4d21332362b0105f2b29155c534cf0b1c4079d8c (
90
lines) (+
67
/-
23
)
[
Show
|
Annotate
]
Branch:
7.9
Improved error-handling some more.
Rev: src/language.yacc:1.76
171:
/* This is the grammar definition of Pike. */ #include "global.h"
-
RCSID("$Id: language.yacc,v 1.
75
1998/04/14 17:
02:04
grubba Exp $");
+
RCSID("$Id: language.yacc,v 1.
76
1998/04/14
19:
17:
43
grubba Exp $");
#ifdef HAVE_MEMORY_H #include <memory.h> #endif
313:
%type <n> catch %type <n> catch_arg %type <n> class
+
%type <n> safe_comma_expr
%type <n> comma_expr %type <n> comma_expr2 %type <n> comma_expr_or_maxint
387:
optional_rename_inherit: ':' F_IDENTIFIER { $$=$2; } | ':' bad_identifier { $$=0; }
+
| ':' error { $$=0; }
| { $$=0; } ;
481:
free_node($1); } | bad_identifier '=' expr0 { if ($3) free_node($3); }
+
| error '=' expr0 { if ($3) free_node($3); }
; constant_list: constant_name
611:
} | error '}' {
-
YYBACKUP('}',
0
);
+
YYSTYPE foo;
+
foo.number = 0;
+
YYBACKUP('}',
foo
);
reset_type_stack(); yyerrok; }
1002:
| break ';' | continue ';' | error ';' { reset_type_stack(); $$=0; yyerrok; }
+
| error '}'
+
{
+
YYSTYPE foo;
+
foo.number = 0;
+
YYBACKUP('}', foo);
+
reset_type_stack();
+
yyerrok;
+
}
| ';' { $$=0; } ; break: F_BREAK { $$=mknode(F_BREAK,0,0); } ;
-
default: F_DEFAULT ':' { $$=mknode(F_DEFAULT,0,0); } ;
+
default: F_DEFAULT ':' { $$=mknode(F_DEFAULT,0,0); }
+
| F_DEFAULT
+
{
+
$$=mknode(F_DEFAULT,0,0)
;
yyerror("Expected ':' after default.");
+
}
+
;
+
continue: F_CONTINUE { $$=mknode(F_CONTINUE,0,0); } ; lambda: F_LAMBDA
1149:
{ $<number>$=compiler_frame->current_number_of_locals; }
-
'(' comma_expr ')' statement optional_else_part
+
'('
safe_
comma_expr ')' statement optional_else_part
{ $$=mknode('?',$4,mknode(':',$6,$7)); $$->line_number=$1;
1175:
} ;
-
do: F_DO statement F_WHILE '(' comma_expr ')' ';'
+
do: F_DO statement F_WHILE '('
safe_
comma_expr ')' ';'
{ $$=mknode(F_DO,$2,$5); $$->line_number=$1;
1201:
{ $<number>$=compiler_frame->current_number_of_locals; }
-
'(' comma_expr ')' statement
+
'('
safe_
comma_expr ')' statement
{ int i=lex.current_line; lex.current_line=$1;
1212:
; for_expr: /* EMPTY */ { $$=mkintnode(1); }
-
| comma_expr
+
|
safe_
comma_expr
; switch: F_SWITCH { $<number>$=compiler_frame->current_number_of_locals; }
-
'(' comma_expr ')' statement
+
'('
safe_
comma_expr ')' statement
{ $$=mknode(F_SWITCH,$4,$6); $$->line_number=$1;
1227:
} ;
-
case: F_CASE comma_expr ':'
+
case: F_CASE
safe_
comma_expr ':'
{ $$=mknode(F_CASE,$2,0); }
-
| F_CASE comma_expr F_DOT_DOT optional_comma_expr ':'
+
| F_CASE
safe_
comma_expr F_DOT_DOT optional_comma_expr ':'
{ $$=mknode(F_CASE,$4?$2:0,$4?$4:$2); }
1246:
} $$=mknode(F_RETURN,mkintnode(0),0); }
-
| F_RETURN comma_expr
+
| F_RETURN
safe_
comma_expr
{ $$=mknode(F_RETURN,$2,0); } ; unused: { $$=0; }
-
|
unused2
+
|
safe_comma_expr { $$=mkcastnode(void_type_string,$1); }
; unused2: comma_expr { $$=mkcastnode(void_type_string,$1); } ; optional_comma_expr: { $$=0; }
-
| comma_expr
+
|
safe_
comma_expr
;
-
+
safe_comma_expr: comma_expr
+
| error { $$=mkintnode(0); }
+
;
+
comma_expr: comma_expr2 | simple_type2 local_name_list { $$=$2; free_node($1); } | simple_identifier_type local_name_list2 { $$=$2; free_node($1); }
1396:
$$=mknode(F_ARROW,$1,$3); } | expr4 F_ARROW bad_identifier {}
+
| expr4 F_ARROW error {}
; idents: low_idents
1408:
free_node($3); } | idents '.' bad_identifier {}
+
| idents '.' error {}
; low_idents: F_IDENTIFIER
1508:
{ $$=$1; }
+
| F_IDENTIFIER F_COLON_COLON error
+
{
+
$$=$1;
+
}
| F_COLON_COLON F_IDENTIFIER { int e,i;
1540:
; comma_expr_or_zero: /* empty */ { $$=mkintnode(0); }
-
| comma_expr
+
|
safe_
comma_expr
; comma_expr_or_maxint: /* empty */ { $$=mkintnode(0x7fffffff); }
-
| comma_expr
+
|
safe_
comma_expr
; gauge: F_GAUGE catch_arg
1577:
$$=mkstrnode(s); free_string(s); free_node(tmp);
-
} ;
+
}
+
| F_TYPEOF '(' error ')' { $$=mkintnode(0)
;
yyerrok; }
+
;
catch_arg: '(' comma_expr ')' { $$=$2; } | '(' error ')' { $$=mkintnode(0); yyerrok; }
1592:
{ $$=mknode(F_CATCH,$3,NULL); catch_level--;
-
} ;
+
}
+
;
sscanf: F_SSCANF '(' expr0 ',' expr0 lvalue_list ')' { $$=mknode(F_SSCANF,mknode(F_ARG_LIST,$3,$5),$6); }
-
+
| F_SSCANF '(' expr0 ',' expr0 error ')'
+
{
+
$$=mkintnode(0);
+
free_node($3);
+
free_node($5);
+
yyerrok;
+
}
+
| F_SSCANF '(' expr0 error ')'
+
{
+
$$=mkintnode(0);
+
free_node($3);
+
yyerrok;
+
}
+
| F_SSCANF '(' error ')' { $$=mkintnode(0); yyerrok; }
; lvalue: expr4
1635:
* Some error-handling */
-
bad_identifier
:
bad_def_identifier
-
|
F_INLINE
+
bad_identifier:
+
F_INLINE
{ yyerror("inline is a reserved word."); } | F_LOCAL { yyerror("local is a reserved word."); }
1666:
{ yyerror("string is a reserved word."); } | F_VOID_ID { yyerror("void is a reserved word."); }
-
;
-
-
bad_def_identifier
-
:
F_DO
+
|
F_DO
{ yyerror("do is a reserved word."); } | F_ELSE { yyerror("else is a reserved word."); }