Path: utzoo!attcan!uunet!lll-winken!lll-tis!mordor!joyce!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.c Subject: Re: Unnecessary parenthesis Message-ID: <953@garth.UUCP> Date: 13 Jul 88 19:02:23 GMT References: <326@marob.MASA.COM> <175@lakart.UUCP> <1988Jul10.201845.27751@utzoo.uucp> <3863@rpp386.UUCP> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 38 >the geneal case of trying to reduce the recursion present in the parser >would seem to require a potentially arbitrary amount of look ahead, or >as a minimum, the same amount of lookahead as the length of the shortest >sentence the parser is trying to recognize. clarifications, henry? I'm not Henry, but ..... A context free grammar is union of Dyck set and a linear (regular expression) grammar. The regular expression part of the grammar can be parsed with loops and conditionals (actually just an FSM) and recursion isn't necessary. One of the optimisations is to recognise linear parts of language and translate them into your favorite version of an FSM. C has three symbol pairs which form embedding constructs: () [] {}. [] can be embedded in (), () in [], and () and [] in {} so that in general, some form of stack is necessary. This can still be optimise some what by counting when () is directly embedded in (), [] in [], {} in {}, instead of stacking. In something like ((a+b)+c[(d)]) the expression scanner can count the parentheses and only need recurse to handle the subscript: ((a+b)+c[(d)]) expr: 12 2 1 subscript: 1 1 expr: 1 1 Because on most machines, recursion is slower than looping, it is a tradeoff between a more complicated or faster parser. >>Anyone who buys Wisconsin cheese is | Henry Spencer @ U of Toronto Zoology >>a traitor to mankind. --Pournelle | {ihnp4,decvax,uunet!mnetor}!utzoo!henry > >and what the hell does this mean??? Does anybody even try to understand? Hafa an godne daege. sm ryan