Copyright © 1997-1998, Compiler Resources, Inc.
New Features in Revision 2.2

Yacc++ and the Language Objects Library

New Features in Revision 2.2

Decision Predicates for Lookahead and Backtracking the Parser

A small extract from the tutorial on this feature is shown below:

Syntactic and semantic decision predicates may sound intimidating at first, but just think of them as an "IF THEN ELSE" feature of grammars. They give you control to direct the parser when it might otherwise be unable to make the choice on its own. If you can write a grammar without decision predicates, do so. If you have a tricky language with difficult to solve conflicts and ambiguities in the grammar, decision predicates provide the control you may need to give the parser explicit directions. They can make your grammar and semantic processing less complex.

Syntactic Predicates define a condition using a regular expression. Regular expressions are the list of tokens, symbols and repetition factors which make up the syntactic rule. Whether the regular expression preceding the ">>" IF TRUE operator parses successfully or not determines what will be parsed next. At runtime, the parser will do a special lookahead and backtrack to determine if the predicate matches.

Take a look at this fragment from preda.yxx with its action code removed. The first syntactic predicate uses the add rule as the lookahead.


grammar      :  calculations+
             ;

calculations :  "=" add >> add
             |  "=" sub >> sub
             |  "=" mul 
             ;

add          :  NUMBER+ "+"
             ;

sub          :  NUMBER+ "-"
             ;

mul          :  NUMBER+ "*"
             ;

  1. If it sees a list of one or more numbers followed by a "+" it backtracks and continues parsing using add.
  2. If it doesn't successfully parse add, it backtracks but continues with the next alternative.

In this case, there is an additional predicate which uses sub as the lookahead. Again, it checks if there is a list of numbers followed by a "-". If yes, it backtracks and then parses sub. Otherwise, it backtracks, but resumes parsing with the next alternative.

Semantic Type Extension to the Keyword Declaration

The KEYWORD declaration now optionally accepts an initialization value for the semantic type field in keyword symbols. This initialization occurs at the time the lexer object is created.

KEYWORD REGISTER "GR1"  { 1 }
                 "GR2"  { 2 }
                 "GR3"  { 3 }
                 ;

Long Pathname Support

When customers were first transitioning applications built by Yacc++ from DOS/Windows to Windows NT/95, we were requested to provide one set of executables that would run on all Microsoft configurations. The Least Common Denominator was DOS and the executables were thus restricted to short pathnames.

This has become a significant hindrance to many of us. Revision 2.2 for Windows NT/95 now supports long pathnames.

A separate DOS/Windows release is maintained for those who continue to work with "8 dot 3" file systems.

New Command Line Option -output_directory

A recent addition to yxx.exe, yy_etbl.exe and yy_stbl.exe is a new command line option for specifying an alternate directory for the generation of the output files. The default is the current directory. Use -output_directory to specify an alternate pathname. For example:

-output_directory "\put my files here"

-od \anyplaceUSA\myState

Microsoft Visual C++ Project Builds

In addition to standalone makefiles, Revision 2.2 ships with MVC++ *.dsp files to build the Language Objects Library and the "Hello World!" installation test case from within the Developer Studio.

ANSI C++ Standard Headers

The Language Objects Library was made configurable to choose ANSI C++ standard headers or the existing headers. For example, <iostream> vs <iostream.h>.

Choose the ANSI C++ standard header configuration for the Language Objects Library when you are using the Standard Template Library (STL) classes in your parser.

Documentation

Tutorial PRED is a new tutorial for Decision Predicates.


Last updated on March 11, 1998. To send email to Compiler Resources, Inc.

Return to Yacc++ Home Page