Login Register


The Programming Language Challenge filter_list
Author
Message
The Programming Language Challenge #1
So, in this challenge, you must create a programming language (defined in just a moment) using the Python programming language. Whoever has the shortest code "wins" (while their code is still the shortest); but that is not the main point, just have fun and learn!
Your programming language must include:
  • basic math (addition, subtraction, multiplication, division)
  • basic conditions (equal to, not equal to, lower than, greater than)
  • variables (stack allowed)
  • REPL (loop required)
  • integer data type (no other data types required)
There are no other requirements. If you have any questions just ask below.
What I hope you learn is that making a programming language (a simple one) is not all that hard.
Let the games begin!

Shoutout to @Shebang - the programming language making machine Wink

Reply

RE: The Programming Language Challenge #2
Can I do this at a very basic level?

Eg.Your conditions don't say I can't simulate everything in base 2

Reply

RE: The Programming Language Challenge #3
(11-30-2015, 09:27 AM)Rick Wrote: Can I do this at a very basic level?

Eg.Your conditions don't say I can't simulate everything in base 2

Sure, go ahead! I would like to see anything you can come up with! Smile

Reply

RE: The Programming Language Challenge #4
Well, I've had this lying around for awhile, but I was too lazy to post until now. xD
Code:
from __future__ import print_function def tokenize(code): return code.split() def evaluate(code, stack, operators): tokens = tokenize(code) for token in tokens: if token in operators: if token in ["+", "-", "*", "/"]: while len(stack) < 2: stack.append(0) ret = operators[token](stack) if ret != None: stack.append(ret) else: # push stack.append(int(token)) stack = [] operators = { "+": lambda stack: stack.pop() + stack.pop(), "-": lambda stack: stack.pop() - stack.pop(), "*": lambda stack: stack.pop() * stack.pop(), "/": lambda stack: stack.pop() / stack.pop(), "|": lambda stack: print(stack[-1]), "=": lambda stack: int(stack.pop() == stack.pop()), "!": lambda stack: int(stack.pop() != stack.pop()), ">": lambda stack: int(stack.pop() > stack.pop()), "<": lambda stack: int(stack.pop() < stack.pop()) } print("CTRL-D or CTRL-C to close REPL") while True: try: code = raw_input(">>> ") evaluate(code, stack, operators) except KeyboardInterrupt, EOFError: break print("\nthe stack is: " + repr(stack))

Reply







Users browsing this thread: