You will be given a lexer that reads tokens from standard input. Your goal is towrite, in C or C++, a program that reads all tokens from standard input by callingthe lexer function getToken() and stores certain tokens in a linked list. After alltokens are read, your program will print out the content of the linked list in aspecific order.ImplementationYour implementation must conform to the CSE 340 projects guideline that thelead TA, Mohsen, has written.Lexer APIThere are two functions that the lexer defines. These two functions compose theapplication programming interface (API) of our lexer. These functions are declaredin lexer.h (and implemented in lexer.c). You will find the files lexer.h and lexer.c onthe submission site for project 2.getToken() reads the next token from standard input and returns its type as atoken_type enum. If the token is of type ID, NUM, IF, WHILE, DO, THEN, or PRINT thenthe actual token value is stored in the global variable current_token as anull-terminated character array and the length of the string is stored in theglobal variable token_length. There are two special token_type values,END_OF_FILE, which is returned when the lexer encounters the end of standardhttp://adamdoupe.com/teaching/classes/cse340-pr1 of 3 09/02/2015 06:04 PMinput and ERROR, which is returned when the lexer encounters anunrecognized character in the input.ungetToken() causes the next call to getToken() to return the last token read bythe previous call to getToken(). Note that this means the next call to getToken()will not read from standard input.There are four global variables declared in lexer.h that are set when getToken() iscalled:t_type the token type is stored here (note that this will be the same valuethat was returned by getToken().current_token the token value is stored in the array current_token. If the token isof type ID, NUM, IF, WHILE, DO, THEN, or PRINT, then current_token contains the tokenstring. For all other token types, current_token contains the empty string.token_length: the length of the string stored in current_token.line: the current line number of the input when the token was read.RequirementsYour program should use the provided lexer and read all tokens from the input byrepeatedly calling the getToken() function. Certain token strings and additionaldata should be stored in a linked list. Specifically, if either of the followingconditions is true:The token is of type NUMThe token is of type ID and the actual token is equal to one of the followingvalues: cse340, programming, or languageThen the token string and other information needs to be stored in a node of alinked list. The information that needs to be stored about each of these tokens inthe linked list is the following:Token type (from t_type)Token value (from current_token)Line number from the input where token was read (from line)After reading all tokens from the input and storing information about tokens thatmatch the criteria, your program should go over the linked list and print theinformation in reverse order from when that token was encountered. Each ofthe tokens in the linked list must be printed to standard output on a separate linewith the following format:http://adamdoupe.com/teaching/classes/cse340-pr2 of 3 09/02/2015 06:04 PMNote that case, the possible values are ID and NUM.EvaluationYour submission will be graded on the automated test cases passing, howeversimply passing all the test cases is not enough for full credit.Your submission will be inspected by the TAs to give you feedback on potentialerrors in your code. You are required to store the information in a linked list thatyou write (either single or double linked list). The nodes in the linked list must beallocated on the heap (using malloc or other similar functions like calloc), and theallocated memory must be freed after printing the output. You are not allowed touse the STL linked list libraries.Note that this means you are not allowed to use the C++ new operator to allocatememory (you must use the C memory allocation functions).ExampleHere is an example input with four lines:cse340 < < + 123 *456 programming cse 340 , LANGUAGE 100. ; WHILE 200 IFHere is your programs expected output:4 NUM 2003 NUM 1003 NUM 3402 ID programming2 NUM 4561 NUM 1231 ID cse340
Programming
[Solved] SOLVED:Principles of Programming Project 2 Solution
$25
File Name: SOLVED:Principles_of_Programming_Project_2_Solution.zip
File Size: 480.42 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.