QuestionQuestion

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.l 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 gec 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 can 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.

2. 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.

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: [{now},(;},{is}]. However, "now'is" 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"
[{So}, {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.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <readline/readline.h>

using namespace std;

//structure of node for the linked list
struct Node {
char* data;
struct Node* next;
};

//class for the linked list
class LinkedList {
private:
Node* head;
public:
// constructor
LinkedList();
// method for checking if list is empty
bool isempty();
// method for appending a string to list
void append(const char* newEl);
// method for printing the list
void print();...

By purchasing this solution you'll be able to access the following files:
Solution.cpp.

$50.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats