Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not running
#1
I'm trying to make my own language with the help of python,
but my code isn't running, why?!

main.py:
script = open('script.jell', 'r').readlines()

def debug(line):
  # support
  def characters(sp, ep):
    save = ''
    for i in range(sp, ep):
      save += line[i]
    return save
  def get_cmd_type():
    c = 0
    save = ''
    not_end = True
    while not_end:
      c += 1
      if line[c] == '(' or line[c] == None:
        not_end = False
      else:
        save += line[c]
    return save
  def get_params():
    c = 0
    saveparams = []
    savevalues = ''
    while not line[c] == '(':
      c += 1
    while not line[c] == ')':
      c += 1
      if line[c] == ',':
        saveparams += savevalues
        savevalues = ''
      else:
        savevalues += line[c]
    saveparams += savevalues
    return saveparams
  # decoding
  
  if get_cmd_type() == 'print':
    params = get_params()
    print(params[0])

for line in script:
  debug(line)
script.jell:
print('hi')
Reply
#2
The debug() function defines 3 inner functions but it does not use them. It does nothing.
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
how do I get "debug" to use them
Reply
#4
Your code is difficult to read because the indent is too small (should be 4 spaces, not 2) and there are no empty lines to help see the start and end of methods and classes. Please adopt the suggested practices in PEP8

https://peps.python.org/pep-0008/

To answer your question, I need to ask a question. What are you trying to do. The code does not make any sense to me.

To use a function you call it. You know how to call functions. Some of the code you've posted to the forum contains function calls.
Reply
#5
@deanhystad the code is reading the lines of the script.jell file and the debug has two parts: support functions and debugging, the support functions help the debugging and the debugging is acting with the input.

I finally managed it to display the code, but now the problem is: whenever I print the parameters, it displays '

the debugging script:
script = open('script.jell', 'r').readlines()

def debug(line):
  # support

  def characters(sp, ep):
    save = ''
    for i in range(sp, ep):
      save += line[i - 1]
    return save

  def get_cmd_type():
    c = 0
    save = ''
    not_end = True
    while not_end:
      c += 1
      if line[c - 1] == '(' or line[c - 1] == None:
        not_end = False
      else:
        save += line[c - 1]
    return save

  def get_params():
    c = 0
    saveparams = []
    savevalues = ''
    while not line[c] == '(':
      c += 1
    while not line[c] == ')':
      c += 1
      if line[c] == ',':
        saveparams += savevalues
        savevalues = None
      else:
        savevalues += line[c]
    saveparams += savevalues
    return saveparams

  # decoding
  
  print(get_cmd_type())
  if get_cmd_type() == 'print':
    params = get_params()
    print(params[0])

for line in script:
  debug(line)
the custom-language script:
print('hi')
subscrib to me

https://youtube.com/@ballinpy
Reply
#6
nevermind I fixed it too
Reply
#7
sorry for wasting your time :(
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020