michaeldrm / prop-logic-parser

Parser implementation that evaluates propositional logic formulas using lexical analysis (tokenization) and parsing techniques. It supports the recognition of atomic propositions, logical connectives (negation, conjunction, disjunction, implication, equivalence), and parentheses for grouping.
0 stars 0 forks source link

Propositional Logic Parser

This Python script parses and evaluates propositional logic formulas using lexical analysis (tokenization) and parsing techniques. It supports the recognition of atomic propositions, logical connectives (negation, conjunction, disjunction, implication, equivalence), and parentheses for grouping.

Installation

Ensure you have Python installed on your system. Additionally, install the required PLY it's a zero-dependency Python implementation of the traditional parsing tools lex and yacc.

Usage

  1. Run the script using Python: python propositional_logic_parser.py

  2. Enter the propositional logic formula when prompted.

  3. The script will tokenize the formula, parse it, and then evaluate whether the formula is satisfiable.

Structure

Supported Tokens

ATOM: A sequence of alphabetical characters representing atomic propositions.

NEGATION: '~' symbol for negation.

AND: '&' symbol for conjunction.

OR: '|' symbol for disjunction.

IMPLIES: '->' symbol for implication.

EQUIVALENT: '<->' symbol for equivalence.

LPAREN: '(' symbol for left parenthesis.

RPAREN: ')' symbol for right parenthesis.

Example

Suppose you want to analyze the formula (A & B) | (~A & B). Upon running the script, you'll input this formula, and the script will determine whether it's satisfiable or not.

Credits

This script utilizes the ply library for lexical analysis and parsing. PLY Documentation

Author

Michael DIOP ROGANDJI