Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: whats wrong with this lex grammer? (help) Message-ID: <8765@mimsy.UUCP> Date: Fri, 25-Sep-87 09:07:27 EDT Article-I.D.: mimsy.8765 Posted: Fri Sep 25 09:07:27 1987 Date-Received: Sat, 26-Sep-87 19:59:21 EDT References: <443@aucs.UUCP> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 26 In article <443@aucs.UUCP> 820785gm@aucs.UUCP (ANDREW MACLEOD) writes: >... For recognizing comments (ie (*...*) ) I have this horrible long >statement that works. However, I have a much nicer one that I don't >understand why it doesn't work. ... Here is the short lex program: > >"(*"([^*]|("*"/[^)]))*"*)" printf("&%s&\n", yytext); >(*andrew*) macleod (*was*) here >&(*andrew*& >) macleod &(*was*& >) here Your `/' (right context) causes lex to back up one character after matching a string that contains one `*)'. In general, right context does not work; it should be used sparingly, if at all. The expression \(\*(\*[^)]|[^*])*\*+\) should work. You should be aware that this stores the entire comment in the array `yytext'---whether it fits or not. Comments can easily overrun lex's token buffer. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris