Skip to content

Commit a57a4e8

Browse files
authored
You've been gnomed
adding files lol
0 parents  commit a57a4e8

File tree

7 files changed

+242
-0
lines changed

7 files changed

+242
-0
lines changed

example1.hawk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'A' in binary is 01000001 so we need to flip the bits at position 1 and position 7
2+
3+
> First clear the pool (optional)
4+
/^ Move the pointer left one bit and flip that bit
5+
//////^ Move the pointer left six more bits and flip the last bit
6+
:> Print out the pool (A) and clear the pool
7+
8+
9+
The following can also be written like this
10+
11+
>/^//////^:>
12+
13+
(That will also print 'A')

example2.hawk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
>/^///^: Prints 'H' (01001000) (Note the beginning zero)
2+
>/^/^///^//^: Prints 'e' (01100101)
3+
>/^/^//^/^:. Prints 'l' and saves it to cache (01101100)
4+
>,:+ Prints 'l' from cache and clears cache
5+
>!^///^:. Prints 'o' and saves it to cache (01101111)
6+
>//^: Prints ' ' (00100000)
7+
>!^////^: Prints 'w' (01110111)
8+
>,:+ Prints 'o' from cache and clears cache
9+
>/^/^/^///^: Prints 'r' (01110010)
10+
>/^/^//^/^: Prints 'l' (01101100)
11+
>/^/^///^: Prints 'd' (01100100)
12+
>//^/////^: BANG (00100001)
13+
>////^//^: Prints a newline (00001010)
14+
15+
16+
The following can also be written like this
17+
>/^///^:>/^/^///^//^:>/^/^//^/^:.>,:+>!^///^:.>//^:>!^////^:>,:+>/^/^/^///^:>/^/^//^/^:>/^/^///^:>//^/////^:>////^//^:

hawklang.exe

10.2 MB
Binary file not shown.

hawkparser.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
class Parser:
2+
def __init__(self, text):
3+
self.pool = ['0'] * 8
4+
self.cache = ['0'] * 8
5+
self.pointer = 0
6+
self.onerror = False
7+
self.code = text.split('\n')
8+
self.buffer = ''
9+
10+
def parse(self):
11+
counter = 0
12+
for line in self.code:
13+
res = []
14+
res[:] = line
15+
#print(res)
16+
for pos, char in enumerate(res):
17+
#print(char, pos)
18+
if char == '>': # Clears the pool
19+
self.pool = ['0'] * 8
20+
self.pointer = 0
21+
22+
elif char == '\\': # Moves the pointer left one bit
23+
if self.pointer == 0:
24+
self.error(1, counter, pos)
25+
break
26+
self.pointer -=1
27+
28+
elif char == '/': # Moves the pointer right one bit
29+
if self.pointer == 7:
30+
self.error(1, counter, pos)
31+
break
32+
self.pointer += 1
33+
34+
elif char == '^': # Inverses bit under pointer
35+
if self.pool[self.pointer] == '0': self.pool[self.pointer] = '1'
36+
else: self.pool[self.pointer] = '0'
37+
38+
elif char == '!': # Inverses all bits in pool
39+
for _, item in enumerate(self.pool):
40+
if item == '0': self.pool[_] = '1'
41+
else: self.pool[_] = '0'
42+
#print(self.pool)
43+
44+
elif char == ':': # Reads the pool as a 8 bit integer and prints the ascii value of it
45+
if chr(int(''.join(self.pool))) == '\n':
46+
self.buffer += '\n'
47+
else:
48+
self.buffer += chr(int(''.join(self.pool), 2))
49+
50+
elif char == '.': # Saves pool to cache
51+
if self.pool == ['0'] * 8:
52+
self.error(3, counter, pos)
53+
break
54+
self.cache = self.pool
55+
56+
elif char == ',': # Saves cache to pool
57+
if self.cache == ['0'] * 8:
58+
self.error(2, counter, pos)
59+
break
60+
self.pool = self.cache
61+
62+
elif char == '+': # Clears cache
63+
if self.cache == ['0'] * 8:
64+
self.error(4, counter, pos)
65+
break
66+
67+
self.cache = ['0'] * 8
68+
69+
70+
71+
72+
if self.onerror:
73+
break
74+
75+
#print()
76+
77+
counter += 1
78+
79+
if not self.onerror: # Print
80+
print(self.buffer)
81+
print()
82+
83+
def error(self, code, line, char):
84+
pos = f'{line+1};{char+1}'
85+
if code == 1: # User attempted to move pointer out of pool range (<0, >7)
86+
print(f'''
87+
ERROR (code 1) in {pos} of code
88+
Pointer moved outside of pool. Remember: the Pool is only 8 bits large!
89+
''')
90+
91+
elif code == 2: # User attempted to dump an empty cache
92+
print(f'''
93+
ERROR (code 2) in {pos} of code
94+
Cannot dump an empty cache!
95+
''')
96+
97+
elif code == 3: # User attempted to save an empty pool to cache
98+
print(f'''
99+
ERROR (code 3) in {pos} of code
100+
Cannot save an empty pool!
101+
''')
102+
103+
elif code == 4: # User attempted to clear an empty cache
104+
print(f'''
105+
ERROR (code 4) in {pos} of code
106+
Cannot clear an empty cache!
107+
''')
108+
self.onerror = True

main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
from hawkparser import Parser
3+
from repl import repl
4+
5+
try:
6+
code = open(sys.argv[1]).read()
7+
Parser(code).parse()
8+
except:
9+
print('Starting Hawklang REPL...')
10+
repl()

readme.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Hawklang
2+
## An esoteric language ~~copied~~ heavily inspired by [Excon](https://esolangs.org/wiki/EXCON)
3+
4+
### How it works
5+
Hawklang starts with a pool of 8 bits, and a cache of 8 bits as well. Both automatically start as `00000000`.
6+
Hawklang also has a pointer, which automatically starts at position 0
7+
```
8+
00000000
9+
^
10+
```
11+
12+
13+
14+
Hawklang has 8 instructions. Listed below are the instructions, and their actions.
15+
```
16+
> | Clears the Pool (to 00000000), and moves the pointer back to position 0
17+
/ | Moves the pointer right one bit.
18+
\ | Moves the pointer left one bit.
19+
^ | Inverses the bit that is under the pointer (1 -> 0, 0 -> 1)
20+
! | Inverses all the bits in the pool
21+
: | Reads the pool as a 8-bit integer and prints out the ascii value of it
22+
. | Saves pool to cache
23+
, | Dumps cache to pool
24+
+ | Clears cache
25+
```
26+
Any other characters that are not >/\^!:., are considered comments.
27+
28+
### Important Note
29+
If you are dealing with, for example, the letter H, which in binary is only 7 bits long (1001000),
30+
make sure you leave an extra zero before the first 1 (01001000), so that the parser doesn't read it as 10010000!
31+
(10010000 as an ascii character is `\x90`, which is definitely not H!)
32+
33+
## Examples
34+
35+
example1.hawk | Prints the letter 'A'
36+
```
37+
'A' in binary is 01000001 so we need to flip the bits at position 1 and position 7
38+
> First clear the pool (optional)
39+
/^ Move the pointer left one bit and flip that bit
40+
//////^ Move the pointer left six more bits and flip the last bit
41+
:> Print out the pool (A) and clear the pool
42+
```
43+
44+
45+
46+
example2.hawk | Prints Hello world!
47+
```
48+
>/^///^: Prints 'H' (01001000) (Note the beginning zero)
49+
>/^/^///^//^: Prints 'e' (01100101)
50+
>/^/^//^/^:. Prints 'l' and saves it to cache (01101100)
51+
>,:+ Prints 'l' from cache and clears cache
52+
>!^///^:. Prints 'o' and saves it to cache (01101111)
53+
>//^: Prints ' ' (00100000)
54+
>!^////^: Prints 'w' (01110111)
55+
>,:+ Prints 'o' from cache and clears cache
56+
>/^/^/^///^: Prints 'r' (01110010)
57+
>/^/^//^/^: Prints 'l' (01101100)
58+
>/^/^///^: Prints 'd' (01100100)
59+
>//^/////^: BANG (00100001)
60+
>////^//^: Prints a newline (00001010)
61+
```
62+
The following can also be written like this:
63+
```
64+
>/^///^:>/^/^///^//^: >/^/^//^/^:.>,:+>!^///^:.>//^:>!^////^:>,:+>/^/^/^///^:>/^/^//^/^:>/^/^///^:>//^/////^:>////^//^:
65+
```
66+
67+
68+
## Usage Instructions
69+
If you want to use the .exe file, simply run `hawklang.exe` to access the Hawklang REPL, or open command prompt,
70+
navigate to the directory hawklang.exe is in, and run `hawklang [insert hawk file here]` to run a hawklang file.
71+
72+
### Screenshots
73+
![image](https://storage.googleapis.com/replit/images/1591915172564_691f4b4690d0176951cba04f829d37ac.png)
74+
75+
76+
![image](https://storage.googleapis.com/replit/images/1591915234890_fc3931ac5ea8f5742d738f7f50ebd49c.png)
77+
78+
> ## Have fun!
79+
> cheers, Warhawk947

repl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from hawkparser import Parser
2+
import os
3+
4+
def clear():
5+
os.system('cls' if os.name == 'nt' else 'clear')
6+
7+
8+
def repl():
9+
print('Hawklang REPL')
10+
print('Type CLS to clear, and EXIT to exit.')
11+
while True:
12+
code = input('>>>')
13+
if code == 'CLS': clear()
14+
elif code == 'EXIT': break
15+
else: Parser(code).parse()

0 commit comments

Comments
 (0)