[Solved] SOLVED:CSE340 Project 1

$25

File Name: SOLVED:CSE340_Project_1.zip
File Size: 216.66 KB

SKU: [Solved] SOLVED:CSE340 Project 1 Category: Tag:
5/5 - (1 vote)

CSE340 Project 1AbstractThe goal of this project is to explore strings, pointers, and memory allocationin C and familiarize you with the platform and tools that will be used in allprogramming assignments in this course. You will use a lexical analyzer thatwe developed to learn about strings, linked lists and memory management inC. You need to master these topics in order to have a much easier time insubsequent projects.1 IntroductionYou are provided with a small lexer (lexical analyzer) that reads tokens from stan-dard input. Your job is to write a program that reads all tokens from the inputby calling the lexer function getToken() and store some tokens in a linked list andthen print out the contents of the linked list in a speci c order.The following section describes the provided code in detail. You should read itcarefully to learn how to use it in your code.2 Lexer APIThe lexer is composed of several functions most of which are only meant to be calledby the lexer itself and only two of the functions are intended to be used in other code.In other words, these two functions provide the application programming interface(API) of our lexer. These functions are declared in lexer.h:? getToken(): reads the next token from standard input and returns its typeas an int. In some cases the actual token is stored in a global variable namedtoken which is a null-terminated character array. The cases for which theactual token is stored in token are: ID, NUM, IF, WHILE, DO, THEN and PRINT.The possible values for token type returned by getToken() are de ned asmacros in lexer.h. The special value ERROR signi es that getToken() hasencountered an unrecognized character in the input (a lexical error) and EOFsigni es the end of input stream.1? ungetToken(): causes the next call to getToken() to return the last tokenread by the previous call to getToken(). It simply sets a ag so that next callto getToken() would not read another token from the input but rather returnthe last token. Note that it is an error to call ungetToken() before any callto getToken().There are 4 global variables declared in lexer.h:1? ttype: when getToken() is called, the token type is stored as an integer inthe variable ttype.? token: when getToken() is called, the token value is stored in the array token.If the token is one of ID, NUM, IF, WHILE, DO, THEN or PRINT, the variable tokencontains the token string. For other token types, the variable token containsthe empty string.? tokenLength: the length of the string stored in token? line: the current line number of the input3 RequirementsYour program should use the provided lexer and read all tokens from the input byrepeatedly calling the getToken() function. Some of the token strings should bestored in a linked list. Speci cally, if? The token is of type NUM, or? The token is of type ID and the actual token is equal to one of the followingvalues: cse340, programming, or languagethe token string and some other information need to be stored in a node of a linkedlist. The information that needs to be stored about each of these tokens in the linkedlist is the following:? Token type (copied from ttype)? Token value (copied from token)? Line number in the input where token was read (copied from line)After reading all tokens from the input and storing information about tokensthat match the above criteria, your program should go over the linked list and printthe information in reverse order with the following format for each node of thelinked list printed in a separate line:1These variables are declared as extern variables which enables code in other les that #includelexer.h to see these variables. The actual variables are declared in lexer.c.2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:CSE340 Project 1
$25