InutitionTC  0.30
Data Structures | Macros | Typedefs | Enumerations | Functions
parserHelpers.h File Reference

Functions that help making yacc file concise. More...

#include "envmap_base.h"
#include "vars_set.h"
#include "checker.h"
#include "y.tab.h"

Go to the source code of this file.

Data Structures

struct  string
 A wrapper structure to pass along identifier names within the parser. More...
 
union  YYSTYPE
 The union type of the values passed as the return value in the parser. More...
 

Macros

#define YYSTYPE_IS_DECLARED   1
 The guard to make sure the union YYSTYPE is declared only once.
 

Typedefs

typedef struct string string
 A wrapper structure to pass along identifier names within the parser.
 

Enumerations

enum  eAnyH {
  eAnyTypeH, eAnyTermH, eAnyKindH, eAnyNameH,
  eAnyBindH, eConnDoubleArrow, eConnRightArrow, eConnLeftArrow,
  eConnOr, eConnXor, eConnNor, eConnNand,
  eConnNot, eConnForall, eConnExists, eConnUnhandled
}
 The type of the values located in the first field of the union YYSTYPE passed as the return value in the parser. More...
 

Functions

int yyparse (void)
 The procedure parses the content of the file opened for parsing. More...
 
AnycreateBasicBinary (eType kind, Any *arg1, Any *arg2)
 The procedure creates a basic binary operator such as AND or OR. More...
 
Name createWord (YYSTYPE *res)
 The procedure creates a string to be used as identifier. More...
 
AnycomposeAnyType (eType tp, Any *first, Any *second)
 The procedure composes a new type from the arguments and the kind of the type to be created. More...
 
AnycomposeBinaryConnective (YYSTYPE res, Any *arg1, Any *arg2)
 The procedure composes a new type from the arguments and the information on the expected result contained in the YYSTYPE union in the first argument. More...
 
AnycomposeUnaryConnective (YYSTYPE res, Any *arg)
 The procedure composes a new type from the argument and unary connective prescribed in the YYSTYPE union in the first argument. More...
 
void freeQChain (Type *start)
 The procedure frees memory of a quantifier chain allocated in composeQuantifier. More...
 
AnycomposeQuantifier (eAnyH tp, nameSet *ns, Any *formula)
 The procedure is used to create a formula that starts with either universal or existential quantifier. More...
 
AnycomposeTermVariable (string arg)
 The procedure is used to create Term in Any wrapper with variable the name of which is given in the argument string. More...
 
AnycomposeTypeVariable (string arg)
 The procedure is used to create Type in Any wrapper with variable the name of which is given in the argument string. More...
 
AnycomposeFunctorWithArguments (string name, envmap *arguments)
 The procedure creates a Type that is a predicate variable applied to the given sequence of arguments. More...
 
AnytypeToTerm (Any *mtype)
 The procedure translates given Type to Term if this is possible. More...
 
TermtypeToTermRaw (Type *mtype)
 The procedure translates given Type to Term if this is possible. More...
 
AnycreateExFalso (Any *term, Any *formula)
 The procedure creates the ex falso quod libet proof term from given Term and Type. More...
 
AnycreateLambda (string vname, Any *vtype, Any *term)
 The procedure creates the lambda proof term from given Name of the argument, its Type and body Term. More...
 
AnycreateApp (Any *term1, Any *term2)
 The procedure creates the application proof term from given two Term terms. More...
 
AnycreateAbstract (string name1, Any *type2, string name3, Any *type4, Any *term5, Any *term6)
 The procedure creates the abstraction (i.e. existential quantifier elimination) proof term from given two names of fresh variables, their types, implementation term and usage term. More...
 
AnycreateExists (Any *type, Any *term1, Any *term2)
 The procedure creates the exists (i.e. existential quantifier introduction) proof term from given result type, the witness term and the implementation term. More...
 
AnycreateCase (Any *term, McasIn *case1, McasIn *case2)
 The procedure creates the case (i.e. alternative elimination) proof term from given implementation term and cases. More...
 
AnycreateIn (Any *term, Any *type, int which)
 The procedure creates the injection (i.e. alternative introduction) proof term from given implementation and the resulting type. More...
 
AnycreateProj (Any *term, int which)
 The procedure creates the projection (i.e. conjunction elimination) proof term from given product term. More...
 
AnycreateTuple (Any *type, Any *term1, Any *term2)
 The procedure creates the tuple (i.e. conjunction introduction) proof term from given two product terms and type of the result. More...
 
AnycreateTermVar (string vname)
 The procedure creates the term variable proof term name of the variable. More...
 
McasIncreateCaseTerm (string name, Any *type, Any *term)
 The procedure creates the case subexpression from given name of the variable, its type and the implementation term. More...
 
Name getFreshName (envmap *env)
 The procedure creates a name that does not occur in the given environment. More...
 

Detailed Description

Functions that help making yacc file concise.

Author
Aleksy Schubert

Enumeration Type Documentation

enum eAnyH

The type of the values located in the first field of the union YYSTYPE passed as the return value in the parser.

In some cases only this value is used to inform on which symbol has been encountered by the parser. The first 5 values match the ones of the enum type eAny.

Enumerator
eAnyTypeH 

The value contains Type structure

eAnyTermH 

The value contains Term structure

eAnyKindH 

The value contains Kind structure

eAnyNameH 

The value contains Name

eAnyBindH 

The value contains Bind structure

eConnDoubleArrow 

Information that equivalence symbol was encountered

eConnRightArrow 

Information that implication symbol was encountered

eConnLeftArrow 

Information that reverse implication symbol was encountered

eConnOr 

Information that disjunction symbol was encountered

eConnXor 

Information that XOR symbol was encountered

eConnNor 

Information that NOR symbol was encountered

eConnNand 

Information that NAND symbol was encountered

eConnNot 

Information that negation symbol was encountered

eConnForall 

Information that universal quantifier symbol was encountered

eConnExists 

Information that existential quantifier symbol was encountered

eConnUnhandled 

Information that unhandled symbol was encountered

Function Documentation

Any* composeAnyType ( eType  tp,
Any first,
Any second 
)

The procedure composes a new type from the arguments and the kind of the type to be created.

It checks if the arguments are indeed types. It handles currently only AND and OR types. All other kinds of types are not handled here and treated as errors.

Parameters
tpthe kind of type to be created
firstthe first argument of the newly created type
secondthe second argument of the newly created type
Returns
the Any structure that holds the type created in the procedure or NULL in case of error
Any* composeBinaryConnective ( YYSTYPE  res,
Any arg1,
Any arg2 
)

The procedure composes a new type from the arguments and the information on the expected result contained in the YYSTYPE union in the first argument.

It checks if the second and third arguments are indeed types. It handles currently: left arrow, right arrow, double arrow, NOR, NAND, OR. All other kinds of types, especially those that do not represent connectives or represent unary ones, are not handled here and treated as errors.

Parameters
resthe structure for the expected return type
arg1the first argument of the newly created type
arg2the second argument of the newly created type
Returns
the Any structure that holds the type created in the procedure or NULL in case of error
Any* composeFunctorWithArguments ( string  name,
envmap arguments 
)

The procedure creates a Type that is a predicate variable applied to the given sequence of arguments.

The function creates a sequence of applications that starts with the type variable the name of which is given in name parameter and arguments of which are stored in the arguments parameter. It emits a message and returns NULL on error.

Parameters
namethe string with the name of the predicate variable that is to be applied to the given arguments
argumentsenvmap with arguments to the predicate variable
Returns
the newly allocated Any structure with the new Type in its contents or NULL on error
Any* composeQuantifier ( eAnyH  tp,
nameSet ns,
Any formula 
)

The procedure is used to create a formula that starts with either universal or existential quantifier.

It checks if the given formula is accessible and then gradually creates a series of formulas with bigger and bigger number of initial quantifiers. It uses the strings in ns for the variable names to quantify for. In case tp is not of an appropriate type it generates error.

Parameters
tpthe variety of the quantifier formula to create
nsthe set of names for the quantified variables
formulathe Type that constitutes the body of the formula
Returns
the Any structure that contains the type with the quantified formula inside or NULL in case of error
Any* composeTermVariable ( string  arg)

The procedure is used to create Term in Any wrapper with variable the name of which is given in the argument string.

The memory for the new representation is freshly allocated here and the content of the string is copied there.

Parameters
argthe string with name of the variable
Returns
the newly allocated Any structure with the new variable term in its contents or NULL on error
Any* composeTypeVariable ( string  arg)

The procedure is used to create Type in Any wrapper with variable the name of which is given in the argument string.

The memory for the new representation is freshly allocated here and the content of the string is copied there.

Parameters
argthe string with name of the variable
Returns
the newly allocated Any structure with the new type variable in its contents or NULL on error
Any* composeUnaryConnective ( YYSTYPE  res,
Any arg 
)

The procedure composes a new type from the argument and unary connective prescribed in the YYSTYPE union in the first argument.

It checks if the second argument is indeed a type. It handles currently negation only. All other kinds of types, especially those that do not represent connectives or represent binary ones, are not handled here and treated as errors.

Parameters
resthe structure for the expected return type
argthe argument of the newly created type
Returns
the Any structure that holds the type created in the procedure or NULL in case of error
Any* createAbstract ( string  name1,
Any type2,
string  name3,
Any type4,
Any term5,
Any term6 
)

The procedure creates the abstraction (i.e. existential quantifier elimination) proof term from given two names of fresh variables, their types, implementation term and usage term.

The procedure checks shallowly if the arguments are correctly formed and creates abstraction term proof (i.e. existential quantifier elimination term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
name1the string with the name of the abstracted object
type2the type of the abstracted object
name3the string with the name of the abstracted implementation
type4the type of the abstracted implementation
term5the term with the abstracted implementation
term6the term which used the abstracted implementation
Returns
Any structure that contains the resulting abstraction term or NULL on error
Any* createApp ( Any term1,
Any term2 
)

The procedure creates the application proof term from given two Term terms.

The procedure checks shallowly if the arguments are correctly formed and creates application term proof which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
term1the operand term
term2the argument term
Returns
Any structure that contains the resulting application term or NULL on error
Any* createBasicBinary ( eType  kind,
Any arg1,
Any arg2 
)

The procedure creates a basic binary operator such as AND or OR.

It allocates fresh memory for the new Type to represent the operator as well as Any container for the type. The arguments of the type are retrieved from arg1 and arg2 Any arguments. It does not check if the arguments are well formed, but it checks if local operations (allocation and filling the arguments) are correct.

Parameters
kindthe kind of the binary operator to create
arg1the first argument of the operator
arg2the second argument of the operator
Returns
a new Any container for the new type or NULL in case of error, it emits error message in case of error
Any* createCase ( Any term,
McasIn case1,
McasIn case2 
)

The procedure creates the case (i.e. alternative elimination) proof term from given implementation term and cases.

The procedure checks shallowly if the arguments are correctly formed and creates case term proof (i.e. alternative elimination term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
termthe implementation term of the alternative elimination
case1the case expression to handle the first option of the alternative
case2the case expression to handle the second option of the alternative
Returns
Any structure that contains the resulting case term or NULL on error
McasIn* createCaseTerm ( string  name,
Any type,
Any term 
)

The procedure creates the case subexpression from given name of the variable, its type and the implementation term.

The procedure checks shallowly if the arguments are correctly formed and creates case subexpression that is subsequently used in creation of case proofs (i.e. alternative elimination proof terms). Note that we do not check the logical structure here.

Parameters
namethe name of the case analysed term when it matches the current case
term1the type of the current case
term2the term that realises handling of the current case
Returns
McasIn structure that contains the resulting case subexpression or NULL on error
Any* createExFalso ( Any term,
Any formula 
)

The procedure creates the ex falso quod libet proof term from given Term and Type.

The procedure checks shallowly if the arguments are correctly formed and creates ex falso quod libet proof term which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here. In particular term parameter need not be a proof of falsity here.

Parameters
terma Term that is turned into ex falso proof
formulathe Type with the resulting formula
Returns
Any structure that contains the resulting ex falso term or NULL on error
Any* createExists ( Any type,
Any term1,
Any term2 
)

The procedure creates the exists (i.e. existential quantifier introduction) proof term from given result type, the witness term and the implementation term.

The procedure checks shallowly if the arguments are correctly formed and creates exists term proof (i.e. existential quantifier introduction term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
typethe existential type of the resulting term
term1the witness term of the existential quantifier introduction
term1the implementation term of the existential quantifier introduction
Returns
Any structure that contains the resulting exists term or NULL on error
Any* createIn ( Any term,
Any type,
int  which 
)

The procedure creates the injection (i.e. alternative introduction) proof term from given implementation and the resulting type.

The procedure checks shallowly if the arguments are correctly formed and creates injection term proof (i.e. alternative introduction term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
termthe implementation term of the alternative introduction
typethe type of the resulting term
whichinformation on which of the two injections is created (it is equal to either 1 or 2)
Returns
Any structure that contains the resulting injection term or NULL on error
Any* createLambda ( string  vname,
Any vtype,
Any term 
)

The procedure creates the lambda proof term from given Name of the argument, its Type and body Term.

The procedure checks shallowly if the arguments are correctly formed and creates lambda term proof which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
vnamethe string with the name of the argument variable
vtypethe Type of the argument
termthe Term with the body of the lambda term
Returns
Any structure that contains the resulting lambda term or NULL on error
Any* createProj ( Any term,
int  which 
)

The procedure creates the projection (i.e. conjunction elimination) proof term from given product term.

The procedure checks shallowly if the arguments are correctly formed and creates projection term proof (i.e. conjunction elimination term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
termthe product term of the conjunction elimination
whichinformation on which of the two projections is created (it is equal to either 1 or 2)
Returns
Any structure that contains the resulting projection term or NULL on error
Any* createTermVar ( string  vname)

The procedure creates the term variable proof term name of the variable.

The procedure creates term variable proof (i.e. axiom proof term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
vnamethe name of the term variable
Returns
Any structure that contains the resulting variable term or NULL on error
Any* createTuple ( Any type,
Any term1,
Any term2 
)

The procedure creates the tuple (i.e. conjunction introduction) proof term from given two product terms and type of the result.

The procedure checks shallowly if the arguments are correctly formed and creates tuple term proof (i.e. conjunction introduction term) which is subsequently wrapped in an Any structure. Note that we do not check the logical structure here.

Parameters
typethe type of the result
term1the term that becomes the first coordinate of the tuple
term2the term that becomes the second coordinate of the tuple
Returns
Any structure that contains the resulting tuple term or NULL on error
Name createWord ( YYSTYPE res)

The procedure creates a string to be used as identifier.

It allocates fresh memory for the new Name and copies there the content of the lexing global variable #yytext.

Parameters
resthe YYSTYPE union to store the pointer to the identifier string to
Returns
the newly allocated copy of the string obtained from lexing or NULL in case of allocation error
void freeQChain ( Type start)

The procedure frees memory of a quantifier chain allocated in composeQuantifier.

Parameters
startpointer to chain of quantifiers
Name getFreshName ( envmap env)

The procedure creates a name that does not occur in the given environment.

Parameters
envthe environment to guarantee freshness against
Returns
the name of the fresh variable
Any* typeToTerm ( Any mtype)

The procedure translates given Type to Term if this is possible.

The procedure checks if the argument is properly formed and wraps the result in Any structure. The actual work is done in typeToTermRaw(). The procedure works for a type variable applied to its arguments. Some parsing within the TPTP parser is common for both types and terms and we have to translate one to the other when the initial assumption that the construct is a type turns out to be wrong.

Parameters
mtypethe Type to convert to Term
Returns
the resulting Term wrapped in Any structure or NULL on error
Term* typeToTermRaw ( Type mtype)

The procedure translates given Type to Term if this is possible.

Some parsing within the TPTP parser is common for both types and terms and we have to translate one to the other when the initial assumption that the construct is a type turns out to be wrong.

Parameters
mtypethe Type to convert to Term
Returns
the resulting Term wrapped in Any structure or NULL on error
int yyparse ( void  )

The procedure parses the content of the file opened for parsing.

The code of the function is automatically generated by yacc and flex from syntaxAnalyser.y and lexicalAnalyzer.l files.

Returns
the parsing status