Unnecessary parenthesis

Steven Ryan smryan at garth.UUCP
Thu Jul 14 05:02:23 AEST 1988


>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



More information about the Comp.lang.c mailing list