In this lab assignment, you will extend your solution from the previous lab assignment to: (1) record attributes for some of the tokens recognized during scanning (specifically, the "values" of label and number tokens); (2) construct an abstract representation of recognized Horn clauses during the operation of the parsing function(s) you developed in the previous lab assignment; and (3) in a separate semantic analysis function use the abstract representation to print out ordered lists of the unique label and number tokens that were seen, and to translate and output recognized Horn clauses in a different but similar syntax, based on a simple output grammar.
cse425_lab1
.Delete the automatically generated main source file from your lab 1 project and from the new project's source file folder.
In the ReadMe.txt file, put the lab number and names of the people submitting the lab solution, and as you work on this lab please record your design, implementation, and testing approach in this file as your project report.
Copy the source and header files you wrote for lab 0 into the corresponding directory for lab 1, and add them to your lab 1 project.
Please make sure you make separate copies of the files in the directory where Visual Studio 2013 expects to find source and header files from the project, rather than attempting to add the original lab 0 files into the lab 1 project - not only will you make it easier for Visual Studio 2013 to find things where it expects them (and thus avoid some errors that can crop up otherwise), but you also will have a version of your code that you can look back at (and possibly revert back to) even as you're making changes to the version that you're updating in lab 1.
When we return your graded lab 0 solution to you, please also incorporate fixes to any problems we pointed out in your lab 1 code, even (or perhaps especially) in code that you moved over from lab 0.
UNKNOWN
and leaves the
string member variable empty.
LABEL
and the passed string parameter.
unsigned int
, and a public
constructor that takes a reference to a (C++ style) string and calls the appropriate
base struct type's constructor with NUMBER
and the passed string parameter.
The body of the constructor should then assign the numeric value represented by the
passed string parameter, to the unsigned int
member variable (hint:
it is easy to convert the string representation of an unsigned number into its equivalent
unsigned
int
representation using the >>
extraction operator of an
istringstream
with which you can wrap the string parameter).
new
operator) and stores
aliases to token objects rather than storing the objects themselves by value. This will
preserve polymorphism and avoid the "class slicing problem" for the derived label and
number struct types. Please make sure to use a reference counted smart pointer type
like the C++11 shared_ptr
, and/or other techniques to ensure that dynamically
allocated objects are not leaked, cleaned up too soon, etc.Modify your scanner class so that when it recognizes a label token or number token it constructs the appropriate derived struct type for each of those, but constructs the base struct type for each of the other kinds of tokens, using the appropriate constructor and storing an alias to the (dynamically allocated) token object in each case.
shared_ptr
between the scanner and parser, as a handle for
each dynamically allocated token object -- when neither the scanner nor the parser (nor
any other part of the program) has a reference to a token object, it will be deallocated
dynamically by the destructor of the last smart pointer object that had an alias to
it.Also modify your parsing function so that for all of the well formed input Horn clauses it recognizes, it builds (and makes available to the main function) an abstract representation that is easily translated into a comparable output Horn clause format whose structure is defined by the following output grammar (where the metasymbols and terminal tokens have the same definitions as in the lab 0 assignment):
hornclause -> LEFTPAREN head [body] RIGHTPAREN
head -> predicate
body -> LEFTPAREN predicate {predicate} RIGHTPAREN
predicate -> LEFTPAREN name {symbol} RIGHTPAREN
name -> LABEL
symbol -> LABEL | NUMBER
For example, the input Horn clauses
ancestor ( x , z ) :- parent ( x , y ) ^ ancestor ( y , z )
age ( x , 78 )
age ( y , 53 )
age ( z , 2 )
would produce the lexically ordered labels
age
ancestor
parent
x
y
z
and the numerically ordered numbers
2
53
78
and would be translated into output Horn clauses closely resembling
( ( ancestor x z ) ( ( parent x y ) ( ancestor y z ) ) )
( ( age x 78 ) )
( ( age y 53 ) )
( ( age z 2 ) )
but possibly with different spacing between the symbols.
In your project report, please describe the abstract representation that you used, and how that choice affected your implementation of output functions that generated the output Horn clauses from it.
Before submitting your solution for this lab, please read our grading comments on your solution to the previous lab and address any problems that we pointed out - our evaluation of your solution for this lab may include regression testing of features from the previous lab as well as testing new features for this one.
In your project report please document which cases you ran, summarize what your program did and whether or not that was correct behavior (and why or why not), in each case. Please make sure to distinguish which cases you ran as regression tests of the functionality that was retained from the previous lab, versus cases you ran to test the new functionality you developed for this lab.
IMPORTANT:please make sure that no .exe file is included in any .zip file you send, as the WUSTL e-mail servers will block delivery of email with a .zip attachment that includes a .exe file. Please also make sure to send a .zip file (not a .7z file or other zip format) when you send your solutions.
Please add an extra credit section to your project report documenting your design and implementation of that additional capability (clearly identifying which parts were completed in the previous lab and which parts were completed in this lab), including showing how the input and output grammars grammars were extended to support that feature, and describe how you modified your implementation to parse and emit those grammatical extensions. In that same section, please show examples of input and output from the different cases that you tested in order to validate that it is working correctly.
Please submit both the required and extra credit portions of your program code and your project report together (rather than in a separate directory).