Assignment 1 First Order Languages | Software Engineering 211 | Java Assignments

Goal:

In this assignment, we want to implement the operational semantics of rst order languages and get a feeling for their importance for databases.

Problem Statement:

For this goal, you write an interpreter for formulae of the rst order language. The formulae used here have a free variable and are used to query a database that is given as part of the input. The query result is comprised of those values for the free variable that make the formula true.

In order to make the interpretation of the formulae easier, we represent formulae in this assignment not in the in x notation that we use otherwise but in Polish notation, which eliminates parentheses and the need for operator precedence, and also makes the processing of the expression tree easier. As Boolean operators we use only & ; _;:. To make it possible to use predicates without parentheses, we furthermore require that every predicate name is used only for a single arity, i.e. if "mail" is used for a ternary predicate, it must not be used for a unary predicate as well. Polish notation works as follows: the dyadic operators & ;_ are written before their arguments, just like the predicate names, followed by their arguments without separation except whitespaces. For example for the formula (:P(x) _ Q(y)) & 8z R(x; y; z) in in x notation, the corresponding formula in Polish notation is & _ :P x Q y 8 z R x y z. We allow objects from the universe as constants in the formulae; the universe consists of exactly all those objects named in the ground atoms in the database.

In order to restrict ourselves to ASCII, we represent the negation with a minus sign 􀀀, and the _ with the lowercase letter v; we represent the four rallcannti er with an uppercase A and the exists quanti er with an uppercase E. We use always x as the free variable. Therefore we disallow v, A and E as names for the predicates.

Input:

The input begins with an integer n representing the number of test cases. Each test case begins with a line with a single number m1 representing the number of atoms with unary predicates. Following this will be m1 lines, each line contains a string red representing a unary predicate name, followed by a single parameter. This block is repeated, i.e., every next block is starting with a line with a single number mn representing the number of atoms with n-ary predicates, Followed by mn lines, each line contains a string pred representing an n-ary predicate name, followed by an arbitrary number of parameters. This stops with the rst mn that is 0. This concludes the database that will be queried. As usual, this database will be interpreted with the closed world assumption. We use closed world semantics. Then follows a line with a single number k of queries. Following this will be k lines, each line contains a formula in Polish notation in the format given above, with x as the only free variable. The delimiters of the individual tokens on each line are the whitespaces.

Screenshots:




Get Project Solution Now

Comments