Skip to content

Commit 4782e8f

Browse files
authored
Merge pull request #1 from 64bit-lab/setup_tool
Setup tool
2 parents 4cc6dc4 + 3245b4f commit 4782e8f

File tree

8 files changed

+97
-17
lines changed

8 files changed

+97
-17
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
dist/
3+
logik.egg-info/

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@ Logik provides 3 main features :
1818

1919
## How to use Logik ?
2020

21-
Logik is designed to be use in a terminal. You can start Logik by executing `evaluator.py` :
21+
Logik is designed to be use in a terminal. You can install it by executing the following command directly inside the main folder. (you need to `git clone https://github.com/64bit-lab/Logik` first)
2222

2323
```
24-
$ python3 evaluator.py
24+
$ python3 setup.py install
25+
```
26+
27+
This will install Logik directly on your machine. You can then start logik by typing :
28+
29+
```
30+
$ logik
31+
```
32+
33+
This will start the interactive command line interface :
34+
35+
```
36+
$ logik
37+
>>> # type any expression here
2538
```
2639

2740
### Syntax

bin/logik

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python3
2+
3+
import logik
4+
5+
logik.main()

logik/__init__.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from . evaluator import *
2+
3+
"""
4+
Module : Logik
5+
6+
Description :
7+
8+
Logik provide a simple way to manipulate propositionnal logic in python !
9+
10+
Author : Arthur Correnson
11+
12+
13+
-------------------------------------------------------------------------------
14+
15+
This software may be freely distributed under the MIT license :
16+
17+
18+
MIT License
19+
20+
Copyright (c) 2019 Arthur Correnson
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy
23+
of this software and associated documentation files (the "Software"), to deal
24+
in the Software without restriction, including without limitation the rights
25+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
copies of the Software, and to permit persons to whom the Software is
27+
furnished to do so, subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
SOFTWARE.
39+
"""
40+
41+
# Main function
42+
def main():
43+
while True:
44+
# input
45+
string = input('>>> ')
46+
# lexing
47+
tokens = lex(string)
48+
# parsing
49+
seq = Seq(list(tokens))
50+
ast = parse(seq)
51+
# display the AST
52+
print('\nSyntax tree :\n')
53+
pprint(ast)
54+
evaluate_all(ast)

evaluator.py renamed to logik/evaluator.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from parser import *
1+
from . parser import *
22
from itertools import product
33

44

@@ -76,17 +76,4 @@ def evaluate_all(ast):
7676
print(evaluate(ast, {}))
7777

7878

79-
if __name__ == '__main__':
80-
# input
81-
string = input('>>> ')
82-
# lexing
83-
tokens = lex(string)
84-
# parsing
85-
seq = Seq(list(tokens))
86-
ast = parse(seq)
87-
# display the AST
88-
print('\nSyntax tree :\n')
89-
pprint(ast)
90-
evaluate_all(ast)
91-
9279

lexer.py renamed to logik/lexer.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import re
22

33
def lex(seq):
4+
"""
5+
An iterator that extract all tokens from an input string.
6+
7+
seq -- the sequence of character to lex (string)
8+
"""
49
l = len(seq)
510

611
while l > 0:
@@ -40,6 +45,7 @@ def lex(seq):
4045

4146

4247
def pprint(token):
48+
"""Pretty print a token"""
4349
print('\033[31m'
4450
+ token[0]
4551
+ "\033[0m"

parser.py renamed to logik/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lexer import *
1+
from . lexer import *
22

33

44
def priority(char):

setup.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from setuptools import setup
2+
3+
setup(name='logik',
4+
version='0.1',
5+
description='A simple way to interact with propositional logic in python',
6+
url='https://github.com/64bit-lab/Logik',
7+
author='Arthur Correnson',
8+
author_email='[email protected]',
9+
license='MIT',
10+
packages=['logik'],
11+
scripts=['bin/logik'],
12+
zip_safe=False)

0 commit comments

Comments
 (0)