Answered step by step
Verified Expert Solution
Question
1 Approved Answer
See below image for assignment. You must do in C++. Please make sure you follow the OOP of C++ and please comment your code. Operating
See below image for assignment. You must do in C++. Please make sure you follow the OOP of C++ and please comment your code.
Operating systems communicate with users via a shell program that reads input (e.g voice, keyboard, mouse) and follow user directives to launch or otherwise control programs. In this assignment, you will write a small program that processes keyboard input and would be the first step in a shell program. To make things simpler, you will use the GNU readline library which reads a line of input from a user and allows editing of the line. To use readline, you must include stdio.h prior to including readline/readline.h. When you compile the program, you must use the link library (1) flag after the file(s) that you are compiling. In this assignment, all code should go in file tokenizer.c (C) tokenizer.cpp (C+) You should compile to program tokenizer. Example # Note: no space between -1 and the library name 1 after the targets to compile g++ -o tokenizer -g tokenizer.cpp -lreadline You may wish to use gcc if you are writing in C. You will need to create a Makefile to do this automatically (see below). Your tokenizer program is responsible for doing the following Print a command prompt "> " and read a line of data using function readline (char * readline (char *prompt)). In general, more detail about library functions car be had by typing "man functionname" at a UNIX prompt. Take the string that is returned and from it create a linked list of tokens. Each token should be in a structure that has a character pointer to the token value and a next pointer that is either NULL or points to the next token. Your program will then print the contents of the linked list in square] brackets. The token values will be surrounded by curly braces and separated by a comma. See below for examples. The rules for tokens are as follows and are loosely based on rules used by many UNIX shells 1. Whitespace (space, tab, etc) ends a token and is skipped unless it is in quotes (see below). You will find the function int isspace (char) useful for detecting whitespace characters Several characters are considered special tokens: |;& When one of these characters is encountered, the token being built is completed and a new token consisting of the character is created 2. 3. The special character is an escape character. The next character will be part (or the start) of a token. For example, normally the string "now;is" would be three tokens: [Inow},1;J,is]. However, "nowis" results in a single token: now;is] 4. Items between single or double quotes are treated as parts of the current token > me gusta UNIX [{me},{gusta),(UNIX}] vs. > me" gusta UNIX" [{me gusta UNIX] Quoted text can only be terminated by the same type of quote The escape character only works inside double quotes So long "and thanks's for the fishes" LSo, long, [and thanks's for the fishes] For simplicity, quotes are automatically terminated when a line is processed if the user did not do so. Most shells will usually allow multiline entry across quotes or the escape character, but we will not do this. DO NOT GET AMBITIOUS AND IMPLEMENT THIS, you will lose points. 5. Characters that do not meet the above rules are added on to the current token being built Examples: lt do some "crazy \"air quotes\"" 1let's,doj,1some,crazy "air quotes"] sort >sorted_files.txt L11s, El3, Esort, i>}, [sorted files.txt] > cat -n /etc/fstab L(cat, -n, /etc/fstab] > climate -reverse-"50 years"& climate], s-reverse 50 years], f&1] Operating systems communicate with users via a shell program that reads input (e.g voice, keyboard, mouse) and follow user directives to launch or otherwise control programs. In this assignment, you will write a small program that processes keyboard input and would be the first step in a shell program. To make things simpler, you will use the GNU readline library which reads a line of input from a user and allows editing of the line. To use readline, you must include stdio.h prior to including readline/readline.h. When you compile the program, you must use the link library (1) flag after the file(s) that you are compiling. In this assignment, all code should go in file tokenizer.c (C) tokenizer.cpp (C+) You should compile to program tokenizer. Example # Note: no space between -1 and the library name 1 after the targets to compile g++ -o tokenizer -g tokenizer.cpp -lreadline You may wish to use gcc if you are writing in C. You will need to create a Makefile to do this automatically (see below). Your tokenizer program is responsible for doing the following Print a command prompt "> " and read a line of data using function readline (char * readline (char *prompt)). In general, more detail about library functions car be had by typing "man functionname" at a UNIX prompt. Take the string that is returned and from it create a linked list of tokens. Each token should be in a structure that has a character pointer to the token value and a next pointer that is either NULL or points to the next token. Your program will then print the contents of the linked list in square] brackets. The token values will be surrounded by curly braces and separated by a comma. See below for examples. The rules for tokens are as follows and are loosely based on rules used by many UNIX shells 1. Whitespace (space, tab, etc) ends a token and is skipped unless it is in quotes (see below). You will find the function int isspace (char) useful for detecting whitespace characters Several characters are considered special tokens: |;& When one of these characters is encountered, the token being built is completed and a new token consisting of the character is created 2. 3. The special character is an escape character. The next character will be part (or the start) of a token. For example, normally the string "now;is" would be three tokens: [Inow},1;J,is]. However, "nowis" results in a single token: now;is] 4. Items between single or double quotes are treated as parts of the current token > me gusta UNIX [{me},{gusta),(UNIX}] vs. > me" gusta UNIX" [{me gusta UNIX] Quoted text can only be terminated by the same type of quote The escape character only works inside double quotes So long "and thanks's for the fishes" LSo, long, [and thanks's for the fishes] For simplicity, quotes are automatically terminated when a line is processed if the user did not do so. Most shells will usually allow multiline entry across quotes or the escape character, but we will not do this. DO NOT GET AMBITIOUS AND IMPLEMENT THIS, you will lose points. 5. Characters that do not meet the above rules are added on to the current token being built Examples: lt do some "crazy \"air quotes\"" 1let's,doj,1some,crazy "air quotes"] sort >sorted_files.txt L11s, El3, Esort, i>}, [sorted files.txt] > cat -n /etc/fstab L(cat, -n, /etc/fstab] > climate -reverse-"50 years"& climate], s-reverse 50 years], f&1]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started