Next Higher-Order Parsing 20 

選択Alternation

        atom → NUMBER | VAR | function "(" expression ")"
        sub atom {
          my $in = shift;
          my ($result, $out);
          my $alt3 = conc(lookfor("FUNC"), 
                          lookfor("("), $EXPRESSION,  lookfor(")"),
                         );
     
          if (     ($result, $out) = lookfor("NUMBER")->($in)) {
            return ($result, $out);
          } elsif (($result, $out) = lookfor("VAR")->($in)) {
            return ($result, $out);
          } elsif (($result, $out) = $alt3->($in)) {
            return ($result, $out);
          } else {
            return;
          }
        }
        alt(A, B, ...)

Next Copyright © 2007 M. J. Dominus