 kyleperik 1 year ago
parent
commit
82f68f7eea
6 changed files with 150 additions and 1 deletions
1. 4 0
example.judo
2. 22 0
judo/judo
3. 0 0
judo/lexer.py
4. 1 1
parse.py
5. 111 0
6. 12 0
setup.py

+ 4 - 0 example.judo View File

 @@ -0,0 +1,4 @@ 1 +a^2 + b^2 = c^2 2 +a = 3 3 +b = 4 4 +c | out

+ 22 - 0 judo/judo View File

 @@ -0,0 +1,22 @@ 1 +#!/usr/bin/env python 2 + 3 +import sys 4 +from judo.lexer import tokenize 5 +from judo.parse import make_trees, evaluate, eval_var 6 + 7 +if __name__ == '__main__': 8 + 9 + token_lines = tokenize(open(sys.argv).read().splitlines()) 10 + trees = make_trees(token_lines, start=True) 11 + pipes = [t for t in trees if t.symbol == '|'] 12 + equalities = [t for t in trees if t.symbol == '='] 13 + outs = [ 14 + evaluate(eval_var( 15 + t.nodes.symbol, 16 + equalities 17 + )) 18 + for t in pipes 19 + if t.nodes.symbol == 'out' 20 + ] 21 + for o in outs: 22 + print(o)

+ 1 - 1 parse.py View File

 @@ -1,4 +1,4 @@ 1 -from lexer import tokenize 1 +from judo.lexer import tokenize 2 2 from collections import namedtuple 3 3 4 4 # Here we make a tree 🎄

+ 111 - 0 readme.md View File

 @@ -0,0 +1,111 @@ 1 +# Judo - simple logical programming language 2 + 3 +**example.judo** 4 + 5 +``` 6 +a^2 + b^2 = c^2 7 +a = 3 8 +b = 4 9 +c | out 10 +``` 11 + 12 +**install** 13 + 14 +*First clone and cd into this repo* 15 + 16 +``` 17 +\$ pip install -e ./ 18 +``` 19 + 20 +**try it** 21 + 22 + 23 +``` 24 +\$ judo example.judo 25 +5.0 26 +``` 27 + 28 +## Capabilies 29 + 30 +Currently it's closer to a solver. 31 + 32 +### Syntax 33 + 34 +Addition/Subtraction (+-), Multiplication (*/) and powers (^) are supported mathematical operators 35 + 36 +Parenthesis are used to group math 37 + 38 +Running `var | out` will spit out `var` as output 39 + 40 +Anything with more than one instance of a dependent variable in one expression is not currently suppored 41 + 42 +## Roadmap 43 + 44 +### Inner scopes 45 + 46 +Groups of expressions can be grouped together in a "scope" 47 + 48 +These groups can be assigned to a variable, in which it acts like an object. Properties in that object can be accessed with a dot 49 + 50 +``` 51 +pythagorian = #( 52 + a^2 + b^2 = c^2 53 +) 54 +``` 55 + 56 +These inner scopes can be combined with each other by putting them together 57 + 58 +``` 59 +pythagorian#( 60 + a = 3 61 + b = 4 62 +) 63 +``` 64 + 65 +This won't be very useful if a scope can not use information from the outer scope, so an operator may be developed to force left-hand assignment, with access to outer variables (so, like a dictionary): 66 + 67 +``` 68 +a = 3 69 +b = 4 70 +pythagorian:( 71 + a = a 72 + b = b 73 +) 74 +``` 75 + 76 +When these scopes combine, a new object is created that represents the scope's combined information. From this example, it will know enough to compute c, if asked for: 77 + 78 +``` 79 +a = 3 80 +b = 4 81 +c = pythagorian:( 82 + a = a, 83 + b = b 84 +).c 85 +c | out 86 +``` 87 + 88 +If this were any other modern lanugage, this would seem clunky for a function call, so this leads to the next idea 89 + 90 +### Functions 91 + 92 +Inner scopes bring a lot to the table already, but they are very specific. Other times there are situations where you would not want to compute something backwards. So functions are necessary for simple, one way operations 93 + 94 +``` 95 +f = (a, b) => pythagorian:(a=a, b=b).c 96 +c = f(a, b) 97 +``` 98 + 99 +## Lists 100 + 101 +You've already been exposed to lists. Parenthesis are groupings, but they can be groupings of anything. Without using a character before it, it will be simply a list 102 + 103 +``` 104 +l = (1, 2, 3) 105 +``` 106 + 107 +## Purpose 108 + 109 +The main difference bettween this and other logical programming lanuguages is the syntax. There will be minimal use of special characters. Essentially this will be a logical python. 110 + 111 +Though this language is logical, I would like this to be thought as more as functional, with logical capabilities. I don't want this to revolve around solving puzzles or riddles. This is meant to add valuable capabilities to a useful programming language.

+ 12 - 0 setup.py View File

 @@ -0,0 +1,12 @@ 1 +from setuptools import setup 2 + 3 +setup( 4 + name='judo', 5 + version='0.01', 6 + long_description=__doc__, 7 + packages=['judo'], 8 + scripts=['judo/judo'], 9 + include_package_data=True, 10 + zip_safe=False, 11 + install_requires=[] 12 +)