This program will require you to create a basic parser for an input string that is somewhat like Python. Python has an older parser module and a newer ast module to manage pure Python syntax, but they won't be useful here.
The program will read a data string, identify the control characters, and print out the overall structure of the string. Here's an example
Input String: [{1}]
Output: Number inside a dictionary inside a list
Here are some basic rules for the program:
Input String: {[(abc)}]
Output: Characters inside a tuple inside a ERROR
Python Code:
inpstr = input('Enter the string: ') #get the string from the
user
charList = [] #to store the brackets
shouldappend = True #flag to check closing brackets
ischar = False
i=-1
for char in inpstr: #iterating throught each characters
i+=1
if (ord(char) >= 65 and ord(char) <= 90) or (ord(char) >=
97 and ord(char) <= 122): #check if it is a letter
ischar = True
elif (ord(char) >= 48 and ord(char) <= 57): #check if it is a
number
pass
if (i+1 < len(inpstr)) and shouldappend == True: #checking for
last character
if ((ord(char) >= 48 and ord(char) <= 57) or (ord(char) >=
65 and ord(char) <= 90) or (ord(char) >= 97 and ord(char)
<= 122)) and ((ord(inpstr[i+1]) < 65 or ord(inpstr[i+1]) >
90) and (ord(inpstr[i+1]) < 97 or ord(inpstr[i+1]) > 122) and
(ord(inpstr[i+1]) < 48 or ord(inpstr[i+1]) > 57)): #check if
it is a number
shouldappend = False
if ischar == False:
print('Numbers ', end='')
else:
print('Characters ', end='')
if (char == '(' or char == '{' or char == '[' or char == "'") and
shouldappend == True: #check if it is opening bracket
charList.append(char)
elif char == ')': #check if it is closing bracket
shouldappend = False
stackchar = charList.pop(len(charList)-1) #getting the last element
of the list
if stackchar != '(': #checking if there is proper opening
bracket
print ('inside a ERROR ', end='') #if there isnt printing error
then exiting
break
else:
print ('inside a tuple ', end='') #print the output
elif char == '}': #similarly we check for "}"
shouldappend = False
stackchar = charList.pop(len(charList)-1)
if stackchar != '{':
print ('inside a ERROR ', end='')
break
else:
print ('inside a dictionary ', end='')
elif char == ']': #similarly we check for "]"
shouldappend = False
stackchar = charList.pop(len(charList)-1)
if stackchar != '[':
print ('inside a ERROR ', end='')
break
else:
print ('inside a list ', end='')
elif char == '"': #similarly we check for "
shouldappend = False
stackchar = charList.pop(len(charList)-1)
if stackchar != "'":
print ('inside a ERROR ', end='')
break
else:
print ('inside a string ', end='')
Sample Output:
Enter the string: {[(avc)]}
Characters inside a tuple inside a list inside a dictionary
This program will require you to create a basic parser for an input string that is...
Write a program that determines if a string (passed as a command-line argument) has all unique characters. The program must print the number of times each existing character appears, and then print whether or not they are all unique. Special requirements: You are NOT allowed to modify the input string or create any additional data structures (no arrays, lists, dictionaries, or other strings). You may have only one string (the one received as the command-line argument). You may have one...
For Phton language 3. You are to create a decoder program that takes a tweet as input and turns it into an English sentence. A tweet will contain common acronyms and abbreviations, and your program will need to have a way to decode them (dictionary). For example) “lol” => “laughing out loud”, “brb” => “be right back” Provided is a file with common tweet abbreviations and associated meanings, your program is to use this csv file (tweet_decoder.csv) to create its...
Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....
Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...
please use pythom Write a program that ask the user for a string as input. It should duplicate of all the characters in the string and print it back out to the user. For example: AbC123 would be printed out as AAbbCC112233 Write a program that takes two lists and displays the items that occur in both lists. For example: ["a", "b", "c"] ["c", "a", "d"] would display a and c
Write a C program to “de-vowel” an input string. Assume that the user provides input containing only the characters a through z (i.e., all lowercase letters). Your program should create an output string that deletes all vowels from the input string, pushing the letters together to fill any gaps. For example, given the input “theturtleandthehare” your code should print out “thtrtlndthhr”. Your program should create an output string from the input string, before printing its output. Sample Input: Enter a...
Part I Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be handled...
(1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons (;) or pound signs (#) should be ignored. All empty lines must be ignored Lines containing a string between square brackets are sections. Within each section, lines may contain numbers or strings. For each section, calculate the lowest, highest and modal (most common) number, and print it. In each section, also count all non-whitespace characters, and print that. Example input: ; this is a...
Python Please. a)Let a program store the result of applying the eval function to the first command-line argument. Print out the resulting object and its type. Run the program with different input: an integer, a real number, a list, and a tuple. (On Unix systems you need to surround the tuple expressions in quotes on the command line to avoid error message from the Unix shell.) Try the string "this is a string" as a commandline argument. Why does this...
Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....