Commit f9b9fb82 by Jerry DeLisle

re PR fortran/34325 (Wrong error message for syntax error)

2007-12-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/34325
	* match.h: New function declaration.
	* match.c (gfc_match_parens): New function to look for mismatched
	parenthesis. (gfc_match_if): Use new function to catch missing '('.

From-SVN: r131052
parent c2cc7922
2007-12-19 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/34325
* match.h: New function declaration.
* match.c (gfc_match_parens): New function to look for mismatched
parenthesis. (gfc_match_if): Use new function to catch missing '('.
2007-12-19 Daniel Franke <franke.daniel@gmail.com> 2007-12-19 Daniel Franke <franke.daniel@gmail.com>
PR fortran/34495 PR fortran/34495
......
...@@ -104,6 +104,68 @@ gfc_op2string (gfc_intrinsic_op op) ...@@ -104,6 +104,68 @@ gfc_op2string (gfc_intrinsic_op op)
/******************** Generic matching subroutines ************************/ /******************** Generic matching subroutines ************************/
/* This function scans the current statement counting the opened and closed
parenthesis to make sure they are balanced. */
match
gfc_match_parens (void)
{
locus old_loc, where;
int c, count, instring;
char quote;
old_loc = gfc_current_locus;
count = 0;
instring = 0;
quote = ' ';
for (;;)
{
c = gfc_next_char_literal (instring);
if (c == '\n')
break;
if (quote == ' ' && ((c == '\'') || (c == '"')))
{
quote = (char) c;
instring = 1;
continue;
}
if (quote != ' ' && c == quote)
{
quote = ' ';
instring = 0;
continue;
}
if (c == '(' && quote == ' ')
{
count++;
where = gfc_current_locus;
}
if (c == ')' && quote == ' ')
{
count--;
where = gfc_current_locus;
}
}
gfc_current_locus = old_loc;
if (count > 0)
{
gfc_error ("Missing ')' in statement before %L", &where);
return MATCH_ERROR;
}
if (count < 0)
{
gfc_error ("Missing '(' in statement before %L", &where);
return MATCH_ERROR;
}
return MATCH_YES;
}
/* See if the next character is a special character that has /* See if the next character is a special character that has
escaped by a \ via the -fbackslash option. */ escaped by a \ via the -fbackslash option. */
...@@ -1321,7 +1383,7 @@ gfc_match_if (gfc_statement *if_type) ...@@ -1321,7 +1383,7 @@ gfc_match_if (gfc_statement *if_type)
{ {
gfc_expr *expr; gfc_expr *expr;
gfc_st_label *l1, *l2, *l3; gfc_st_label *l1, *l2, *l3;
locus old_loc; locus old_loc, old_loc2;
gfc_code *p; gfc_code *p;
match m, n; match m, n;
...@@ -1335,6 +1397,14 @@ gfc_match_if (gfc_statement *if_type) ...@@ -1335,6 +1397,14 @@ gfc_match_if (gfc_statement *if_type)
if (m != MATCH_YES) if (m != MATCH_YES)
return m; return m;
old_loc2 = gfc_current_locus;
gfc_current_locus = old_loc;
if (gfc_match_parens () == MATCH_ERROR)
return MATCH_ERROR;
gfc_current_locus = old_loc2;
if (gfc_match_char (')') != MATCH_YES) if (gfc_match_char (')') != MATCH_YES)
{ {
gfc_error ("Syntax error in IF-expression at %C"); gfc_error ("Syntax error in IF-expression at %C");
...@@ -1386,7 +1456,7 @@ gfc_match_if (gfc_statement *if_type) ...@@ -1386,7 +1456,7 @@ gfc_match_if (gfc_statement *if_type)
if (n == MATCH_YES) if (n == MATCH_YES)
{ {
gfc_error ("Block label is not appropriate IF statement at %C"); gfc_error ("Block label is not appropriate for IF statement at %C");
gfc_free_expr (expr); gfc_free_expr (expr);
return MATCH_ERROR; return MATCH_ERROR;
} }
......
...@@ -54,6 +54,7 @@ match gfc_match_intrinsic_op (gfc_intrinsic_op *); ...@@ -54,6 +54,7 @@ match gfc_match_intrinsic_op (gfc_intrinsic_op *);
match gfc_match_char (char); match gfc_match_char (char);
match gfc_match (const char *, ...); match gfc_match (const char *, ...);
match gfc_match_iterator (gfc_iterator *, int); match gfc_match_iterator (gfc_iterator *, int);
match gfc_match_parens (void);
/* Statement matchers. */ /* Statement matchers. */
match gfc_match_program (void); match gfc_match_program (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment