Usage of pbyacc

Filed under: Perl tips — vincent @ 00:00

Yacc, and its GNU replacement Bison is a parser generator, i.e. a program to generate some routines which can parse some text and data according to a user-specified grammar.The basic Yacc documentation is availlable on the net, or with man yacc. We detail here only some points.


The method yyparse of the object generated by pbyacc takes one argument, which is passed to the function yylex.

The function yylex should return one of:

  • 0: to indicate that there is no tokens left.
  • a literal number: given by ord($c) on a character, to indicate a character literal.
  • a list ($type,$value): where $type is one of the constants corresponding to the defined after the %TOKEN directive of the grammar, and the value is an associated value.

Note that the same argument of yyparse is given as the second argument of yyerror if it is called, the first argument being an error message.

The only two usages of the argument of yyparse are for calling yylex and yyerror, which are written by the user. Therefore, anything can be given: nothing (i.e. undef), a string, an object (like a stream handle,…) or a hash or list reference, to be able to simulate passing more than one value.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.