From: skaller <sk...@us...> - 2004-07-29 20:36:46
|
On Fri, 2004-07-30 at 02:04, Brian Hurt wrote: > On 29 Jul 2004, skaller wrote: > > Before you laugh too hard at this example -- > > THE most common lexer and parser combination > > in the world must do precisely what I described, > > its called a C compiler :) > > Actually, in the case of C this isn't true. There is enough information > in the grammar to be able to differentiate type names from variable names. I'm afraid not: counter-example: (A)(B)(C) Here's an actual example, which compiles and runs fine under gcc: int f(int x){ return 1; } typedef int (*fp)(int); fp g(fp x){ return x; } int main() { int x = (int)(f)(1); // parsed as (int)(f(1)) int y = (g)(f)(1); // parsed as (g(f))(1) printf("%d, %d\n", x,y); } Application has a higher precedence than casts in C:) There are other cases which are merely LR(1) ambiguous but which can be parsed correctly, as you claim, provided you can look ahead to the end of statement. -- John Skaller, mailto:sk...@us... voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net |