Prolog Compiler
Bases: Compiler
A Compiler that generates Prolog code from a Theory object.
Source code in src/typedlogic/compilers/prolog_compiler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
compile(theory, syntax=None, **kwargs)
Compile a Theory object into Prolog code.
Example:
>>> from typedlogic import *
>>> theory = Theory()
>>> x = Variable("x")
>>> theory.predicate_definitions = [PredicateDefinition("P", {"x": "str"}),
... PredicateDefinition("Q", {"x": "str"})]
>>> s = Implies(Term("P", x), Term("Q", x))
>>> theory.add(sentence=s)
>>> compiler = PrologCompiler()
>>> print(compiler.compile(theory))
%% Predicate Definitions
% P(x: str)
% Q(x: str)
<BLANKLINE>
%% Sentences
<BLANKLINE>
q(X) :- p(X).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theory
|
Theory
|
|
required |
syntax
|
Optional[Union[str, ModelSyntax]]
|
|
None
|
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
str
|
|
Source code in src/typedlogic/compilers/prolog_compiler.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|