This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Handle comments in the C expression parser



This patch adds C-style comment handling to the expression parser.

That way, we can add comments to output of various places, and still
be able to paste it back in.
(gdb) p 5 /* / */ / 3
$1 = 1
(gdb) p 5 /* / */ / 3 */* 333333 blah */ 2
$2 = 2
(gdb) p 5 /* / */ / 3 */* 333333 blah */ 2
$3 = 2
(gdb) p 5 /* / */ / 3 */* 333333 blah */ 2
$4 = 2
(gdb) p 5 /* / */ / 3 */* 333333 blah *// 2
A parse error in expression, near ` 2'.
(gdb) p 5 /* / */ / 3 */* 333333 blah *// 2
A parse error in expression, near ` 2'.
(gdb) p 5 /* / */ / 3 */* 333333 blah */2/ 2
$5 = 1
(gdb)


(The parse errors are because, if you look closely, it's really 5 / 3
* / 2, so the parse error is correct. )

2001-02-13  Daniel Berlin  <dberlin@redhat.com>

        * c-exp.y : Handle C style comments in expression parser,
        ignoring them.

Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.3
diff -c -3 -p -r1.3 c-exp.y
*** c-exp.y	2000/06/05 20:49:53	1.3
--- c-exp.y	2001/02/14 04:02:25
*************** yylex ()
*** 1187,1193 ****
    char * token_string = NULL;
    int class_prefix = 0;
    int unquoted_expr;
!    
   retry:
  
    unquoted_expr = 1;
--- 1187,1194 ----
    char * token_string = NULL;
    int class_prefix = 0;
    int unquoted_expr;
!   int maybe_comment;
! 
   retry:
  
    unquoted_expr = 1;
*************** yylex ()
*** 1215,1227 ****
      {
      case 0:
        return 0;
! 
      case ' ':
      case '\t':
      case '\n':
        lexptr++;
        goto retry;
! 
      case '\'':
        /* We either have a character constant ('0' or '\177' for example)
  	 or we have a quoted symbol reference ('foo(int,int)' in C++
--- 1216,1249 ----
      {
      case 0:
        return 0;
!       
      case ' ':
      case '\t':
      case '\n':
        lexptr++;
        goto retry;
!     case '/':
!       lexptr++;
!       maybe_comment = *lexptr;
!       if (maybe_comment != '*')
! 	{		  
! 	  //	  lexptr--;
! 	  return c;
! 	}
!       else
! 	{
! 	  lexptr++;
! 	keepgoing:
! 	  while (*lexptr != '*')
! 	    lexptr++;
! 	  maybe_comment = *++lexptr;
! 	  if (maybe_comment != '/')	    
! 	    goto keepgoing;
! 	}
!       lexptr++;
!       goto retry;
!       
! 	  
      case '\'':
        /* We either have a character constant ('0' or '\177' for example)
  	 or we have a quoted symbol reference ('foo(int,int)' in C++
*************** yylex ()
*** 1344,1350 ****
      case '+':
      case '-':
      case '*':
-     case '/':
      case '%':
      case '|':
      case '&':
--- 1366,1371 ----

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]