Tutorial

YooParse accepts file format like traditional yacc/bison except that certain options were not available.

YooParse usually requires YooLex to function, but it doesn't have to, as long as

	int yyLex ();
is available.

Steps

Here are the steps of using YooParse with YooLex.
  1. In section 1 of the .l (YooLex input) file, have the %option line as:
    %option noheader class="DefaultParse" ccfile="DefaultParse_lex.cc"
    One thing is very important that for both YooParse and YooLex, the default the C++ source file is DefaultParse.cc if only the class option is set. They would overwrite each other generated source code. Thus, ccfile is necessary to avoid this conflict. The noheader option tells YooLex not to generate the C++ header file at all since the one generated by YooParse is needed.
  2. In section 1 of the .y (YooParse input) file, have a line which starts w/ %option and enter configuration parameters. For example:
    %option class="DefaultParse" ccfile="DefaultParse_parse.cc"
    For the above two steps, they both assumed the C++ header file is "DefaultParse.hh". If one wishes to use a different header file for the DefaultParse class, both the .l file and the .y file need to have the following option:
    %option hhfile="DefaultParse_header.hh"
    YooParse would generate the header file if it did not exist. One can edit this header file to add variables, functions, the constructor for the parser, etc. YooParse will not overwrite this file.
  3. Another important thing to setup is _yyValue data type, which is necessary for passing values from YooLex to YooParse. If one is not going to do memory allocations (as in calculators) or likes to manipulate memories manually, the default int data type will usually work, provided that it is casted to the desired data type. Otherwise, one could specify a different data type:
    %option yyvalue="double"
    Note: std::auto_ptr<> cannot be used as _yyValue data type. The data type also must have a default constructor.
  4. After running yooparse on the .y input file, the C++ header file specified by the user would be created if it did not exist. Modify this header file to suit for the need.

Error Recovery

The default error recovery works much like yacc/bison (there are some differences, see Reference). If you wish to have your own error recovery routine, overload
bool yyParseError (int yychar);
yychar is the translated lookahead character. The function returns true to terminate yyParse (). Please read yooparse.hh for more details.
$Id: tutorial.html,v 1.3 2002/07/27 03:47:33 coconut Exp $