Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83 (MC840302); site turing.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!mcvax!turing!aeb
From: aeb@turing.UUCP
Newsgroups: net.sources.bugs,net.lang.c
Subject: Re: C grammar
Message-ID: <257@turing.UUCP>
Date: Tue, 12-Feb-85 15:43:50 EST
Article-I.D.: turing.257
Posted: Tue Feb 12 15:43:50 1985
Date-Received: Thu, 14-Feb-85 01:47:13 EST
Organization: CWI, Amsterdam
Lines: 55
Xref: watmath net.sources.bugs:223 net.lang.c:4361
Apparently-To: rnews@mcvax.LOCAL

Having the personality of a kumquat and wanting to befuddle my friends
I cranked some of my C programs through the recently posted parser.
Unfortunately it complained about correct fragments like

    ...
    if ((*buf == ':') || (('a' <= *buf) && ('z' >= *buf)))
    ...

because it parsed all of ':') || ..... ('z' as one single character constant.
Also the handling of backslashes in strings was not quite correct.

The diff below shows how one might change scan.l in order to improve
the parser's behaviour. I am not sure about the + . Are multi-character
character constants permitted by the new standard? (I hope not.)

*** scan.l.orig	Tue Feb 12 11:38:07 1985
--- scan.l	Tue Feb 12 17:16:09 1985
***************
*** 56,62
  0{D}+{US}?{LS}?		{ count(); return(CONSTANT); }
  {D}+{LS}?{US}?		{ count(); return(CONSTANT); }
  {D}+{US}?{LS}?		{ count(); return(CONSTANT); }
! '.*'			{ count(); return(CONSTANT); }
  
  {D}+{E}{LS}?		{ count(); return(CONSTANT); }
  {D}*"."{D}+({E})?{LS}?	{ count(); return(CONSTANT); }

--- 56,62 -----
  0{D}+{US}?{LS}?		{ count(); return(CONSTANT); }
  {D}+{LS}?{US}?		{ count(); return(CONSTANT); }
  {D}+{US}?{LS}?		{ count(); return(CONSTANT); }
! '(\\.|[^\\'])+'		{ count(); return(CONSTANT); }
  
  {D}+{E}{LS}?		{ count(); return(CONSTANT); }
  {D}*"."{D}+({E})?{LS}?	{ count(); return(CONSTANT); }
***************
*** 62,68
  {D}*"."{D}+({E})?{LS}?	{ count(); return(CONSTANT); }
  {D}+"."{D}*({E})?{LS}?	{ count(); return(CONSTANT); }
  
! \"(\\\"|[^"])*\"	{ count(); return(STRING_LITERAL); }
  
  ">>="			{ count(); return(RIGHT_ASSIGN); }
  "<<="			{ count(); return(LEFT_ASSIGN); }

--- 62,68 -----
  {D}*"."{D}+({E})?{LS}?	{ count(); return(CONSTANT); }
  {D}+"."{D}*({E})?{LS}?	{ count(); return(CONSTANT); }
  
! \"(\\.|[^\\"])*\"	{ count(); return(STRING_LITERAL); }
  
  ">>="			{ count(); return(RIGHT_ASSIGN); }
  "<<="			{ count(); return(LEFT_ASSIGN); }
-- 
      Andries Brouwer -- CWI, Amsterdam -- {philabs,decvax}!mcvax!aeb