i’m making a language, and every time a person wants to access a variable, it is with a $ sign. But, on every function I have to have an if, seeing if it’s first letter is a $, and every time a parameter is passed, for every parameter I have to do this. It becomes chaotic. I would like to not nest if’s, but have it so I can easily apply a function to it, and access this. It is kind of hard to explain, but Ill use some code to explain.
def varcmd(cmd, variables):
if cmd.__len__() < 4:
print "Too little arguments! str <var> = <string>"
else:
if cmd[2] == "=":
if cmd[3][:1] == "$":
variables[cmd[1]] = variables[cmd[3][1:]]
else:
variables[cmd[1]] = cmd[3]
else:
print "Incorrect syntax! str <var> = <string>"
As I keep adding to this function, the if’s will exponentially increase, and practically every function can take variables, so every function will have tons of if’s. Basically, I want something like this:
def varcmd(cmd, variables):
if cmd.__len__() < 4:
print "Too little arguments! str <var> = <string>"
else:
if cmd[2] == "=":
variables[cmd[1]] = auto_convert_if_var.cmd[3][1:]
else:
print "Incorrect syntax! str <var> = <string>"
It looks as though your needs have gotten complex enough to require building a parser.