next up previous
Next: 2.3 Logic Up: 2 Notes on Code Previous: 2.1 Utilities


2.2 Parser

In the parser/ directory, follex.y and fol.y are the input files for Flex (lexical analyzer) and Bison (parser generator) respectively. fol.y contains the grammar rules that are used to parse first-order logic formulas, and the code that fires when each rule is encountered. folhelper.h contains our variables and functions that are used in fol.y and follex.y. All Flex and Bison variables and functions begin with the characters yy. Using a similar convention, all of our variables and functions that are used in follex.y, fol.y and folhelper.h begin with zz. The main function is runYYParser() that parses a .mln file and creates an MLN and Domain (see Section 2.3 below). If you want to add variables to be used in fol.y or folhelper.h, please see the note at the top of folhelper.h. You can also change the default weights given to hard clauses and clauses derived from formulas containing mutually exclusive and exhaustive values by setting HARD_WEIGHT_MULTIPLIER/HARD_WEIGHT and EXIST_UNIQUE_WEIGHT_MULTIPLIER/EXIST_UNIQUE_WEIGHT at the top of folhelper.h. StrFifoList is a list used in fol.y to hold tokens in the order that they are extracted by Flex. ListObj contains the algorithm to convert a first-order formula to CNF. It approximates lisp in its use of lists to represent a prefix form of first-order logic. replacefolcpp.pl is a perl script that replaces certain code in fol.cpp (generated by Bison from fol.y) so that it is C++ compliant. If you are using a version of Bison that is less than 2.0, you may have to uncomment the lines at the bottom of the file. For debugging purposes, you can set the variables follexDbg (in follex.y) and folDbg (in fol.y) to see the order in which tokens are extracted, as well as the order in which the grammar rules are executed.


next up previous
Next: 2.3 Logic Up: 2 Notes on Code Previous: 2.1 Utilities
Marc Sumner 2007-01-16