Git Product home page Git Product logo

predicate_logic_compiler's Introduction

Compiler for first-order predicate calculus

This project is the development of a new compiler that reliably interprets and optimizes first-order predicate calculus. Therefor a new language (PREDLOG1) was created to define the logic terms as code in UTF-8.

Process

The abstract compilation process goes as follows:

  1. Lexical analysis (Scanner)
  2. Syntactical analysis (Parser and syntaxtree)
  3. Semantical analysis
  4. Code optimization
  5. Final code generation

Usage

To compile the code you need:

  • Flex
  • Bison
  • GCC
  • Make

With those prerequisites met you can simply run make for the main.c file and build the compiler program. You can use the compiler to analyze your PREDLOG1-code, when using your desired file as the first input argument executing the compiled program.

Language

The language used is a new creation called "PREDLOG1" short for first-order predicate logic. The following paragraphs describe the syntax used to translate first-order predicate calculus terms to PREDLOG1.

Comments

Comments are declared using /* as in front the start of the comment and */ after the end of the comment. The comments are limited to one line per declaration.

Declarations

Every predicate, function and variable needs to be declared as follows before used:

  • Predicate: DECLARE PREDICATE <id> : <arity>
  • Function: DECLARE FUNCTION <id> : <arity>
  • Variable: DECLARE VARIABLE <id> : int

<id> declares the identifier and <arity> declares the number of arguments.

Operands

Operand PREDLOG1 equivalent
<->
->
|
&
¬ ~
ALL[<var>] or ALL [<var>]
EXIST[<var>] or EXIST [<var>]
0 FALSE
1 TRUE

Priority

The order of priority is structured as follows with decreasing priority top down:

  1. function
  2. predicate
  3. ∀,∃
  4. ¬

Example

/* Example PREDLOG1 */

DECLARE PREDICATE Buys : 2
DECLARE PREDICATE Pumpkin : 1
DECLARE PREDICATE Person : 1
DECLARE FUNCTION Eats : 2
DECLARE FUNCTION Carves : 2
DECLARE FUNCTION John : 0
DECLARE VARIABLE x : int
DECLARE VARIABLE y : int

EXIST[x] (Buys(John,x) & Pumpkin(x)) & ALL[x] ALL[y] (Buys(x,y) & Pumpkin(y) -> Eats(x,y) | Carves(x,y)) 
&
ALL[x] (Person(x) -> ALL[y] (Pumpkin(y) -> ~Eats(x,y))) & ~(Person(John) -> EXIST[x] Carves(John,x)) ;

predicate_logic_compiler's People

Contributors

andrikseeger avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.