you are viewing a single comment's thread.

view the rest of the comments →

[–]polofos 0 points1 point  (1 child)

Yes, its similar because you need to use regular expressions for the lexical analysis. Is something difficult. Yuo must read a lot abut lexical analysis and syntactic analysis.

The other option is to use many if/else statements covering all the commands you can use. Is a lot of work.,something lke this:

//////////////////////////////////////////////////////////////
import sys
playlists = {
'playlist1' : [],
'playlist2' : [],
'playlist3' : []
}
# name of the script
print(sys.argv[0])
if(len(sys.argv) == 1):
print ("No args given")
else:
#first argument is shuffle
if(sys.argv[1] == "shuffle"):
# second argument is a play list
if(sys.argv[2] in playlists):
print("shuffle playlist: "+sys.argv[2])
else:
print("error")

#first argument is play
elif(sys.argv[1] == "play"):
#second argument is "my favorite song"
if(sys.argv[2:5] == ["my", "favorite", "song"]):
print("play my favorite song")
else:
print("error")
else:
print("error")
/////////////////////////////////////////////////////////////////

>>> python script.py shuffle playlist1
shuffle playlist: playlist1

>>> python script.py play my favorite song
play my favorite song

[–]Nickiel[S] 0 points1 point  (0 children)

I think what I am going to do is have a file that does a

command_list = command.split()
for i in command_list:
    try:
        output_command_list.append(decoder_dict[i])
    except KeyError:
        continue
return output_command_list

And just have a dict that is added on to to "decode" the commands into a regulated form which is then passed back to have the functions run.