MyNixOS website logo
Description

Logic interpreter.

WeberLogic

Logic interpreter and parsing library

Install

cabal update
cabal install WeberLogic

Interpreter

$ ./WeberLogic
Enter Command
> truthTable: a&b+c->~a&b
'a'   'b'   'c'   | (((a&b)+c)->(~a&b))
True  True  True  | False
True  True  False | False
True  False True  | False
True  False False | True 
False True  True  | True 
False True  False | True 
False False True  | False
False False False | True 

Enter Command
> toNand: a&b->c 
(((((a|b)|(a|b))|((a|b)|(a|b)))|(((a|b)|(a|b))|((a|b)|(a|b))))|(c|c))

Enter Command
> toNor: a&b->c
(((((a/a)/(b/b))/((a/a)/(b/b)))/c)/((((a/a)/(b/b))/((a/a)/(b/b)))/c))

Library

The library contains two modules.

  1. WeberLogic.Parser
  2. WeberLogic.Actions

WeberLogic.Parser

The WeberLogic.Parser provides functions which read stings and return an abstract syntax tree (AST). The AST in implement with a data type called LogicExp and Letter.

  • Data Types

    • LogicExp - A recursively defined data type which implements as abstract syntax tree. It provides the following type constructors which function as nodes in the AST: Not, And, Or, Implies, Iff, Nand, and Nor. The Predicate type constructor functions as the AST leaves.
    > import WeberLogic.Parser
    > Predicate 'A' [(Variable 'x', Name 'a')]
    > Not (Predicate 'A' [(Variable 'x', Name 'a')])
    > And (Predicate 'A' [(Variable 'x', Name 'a')]) (Predicate 'B' [])
    
    • Letter - This Data Constructor provies two Type constructors Variable and Name. They are used in the construction of Predicate which requires a list of type Letter
    > import WeberLogic.Parser
    > Predicate 'A' [(Variable 'x', Name 'a')]
    
  • Functions

    • parseExp
    > import WeberLogic.Parser
    > a = parseExp "Axa"
    > b = parseExp "~Axa"
    > c = parseExp "Axa&B"
    
    • parseArg
    > import WeberLogic.Parser
    > a = parseExp "|- Axa"
    > b = parseExp "~Axa, B |- Cax"
    > c = parseExp "Axa&B, B, C |- Ax->By"
    

WeberLogic.Actions

The WeberLogic.Actions modules provides functions which manipulate the LogicExp AST.

> import WeberLogic.Parser
> import WeberLogic.Actions

> mapM_ putStrLn $ truthTableStr $ readExp "A&B"
'a'   'b'   | (a&~b)
True  True  | False
True  False | True 
False True  | False
False False | False

> toNand $ readExp "A&~B" 
((a|(b|b))|(a|(b|b)))

> toNor $ readExp "A&~B" 
((a/a)/((b/b)/(b/b)))
Metadata

Version

0.1.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows