Question

In: Computer Science

Implement Lexer(Scanner) that scans the whole source code entered by the user that includes Alphabets(characters), integers(digits),...

Implement Lexer(Scanner) that scans the whole source code entered by the user that includes Alphabets(characters), integers(digits), operators(arithmatic, logical and relational operators), and special symbols. output should be in the form of Symbol table that shows each token with its name, type and number of times entered(lexexmes). dictionary should be implemented in the code by writing RegX for each category. code entered from internet will be discarded. Implementation language will be of your own choice.

I really need the answer of this question, if someone can do that i would really appreciate it.

Solutions

Expert Solution

When an identifier in the source program is detected by the lexical analyzer, the identifier is entered into the symbol table.

A symbol table is a data structure containing a record for each identifier, with fields for the attributes of the identifier. The data structure allows us to find the record for each identifier quickly and to store or retrieve data from that record quickly.

Code:

function lexan : integer;

var lexbuf : array[0...100] of char;

c : char;

begin

loop begin

read a character into c;

if c is a blank or a tab then

do nothing

else if c is a newline then

lineno := Iineno + I

else if c is a digit then begin

set tokenval to the value of this and following digits;

return NUM

end

elseif c is a letter then begin

place c and successive letters and digits into  lexbuf;

p := lookup(lexbuf);

if p=0 then

p := insert(lexbuf,ID);

tokenval := p

return the token field of table entry p ;

end

else begin /* token is a single character */

set tokenval to NONE; /*there is no attribute */

  return integer ending of character c

end

end

end


Related Solutions

Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
1. Design and implement a program that reads a series of integers from the user and...
1. Design and implement a program that reads a series of integers from the user and continually prints their average after every reading. The input stops when the user enters “stop” as the input value. Read each input value as a string, then check if it is “stop” or not. If the string is not “stop”, then, attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException, meaning that the input is not...
Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid integer), display an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces,...
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces, punctuation marks, and there is no length limit). When a button Count is hit , display the number of upper-case letters in the inputted phrase. This must be done in visual studios using C#.
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
Use DevC++ to implement a program that can store and output 5 integers, where the user...
Use DevC++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. 2. Output the content (value) that stored in the array of five elements. 3. Continue to ask the user to store for storing data into another array. c++ ONLY PLEASE NEED IT FAST AS POSSIBLE
Code a program which asks user to enter two strings using Scanner class and returns the...
Code a program which asks user to enter two strings using Scanner class and returns the total number of non-space characters in the Strings. For ex: “Hi there” and “hello” should return 12.
Implement and complement the recursive code to compute the product of two positive integers, x and...
Implement and complement the recursive code to compute the product of two positive integers, x and y, using only addition and/or subtraction. The function will take as its arguments two integers to multiply together ( x x y ) and will return the product. Hint: consider the following: 6 x 1 = 6 6 x 2 = 6 + (6 x 1) 6 x 3 = 6 + (6 x 2) = 6 + [6 + (6 x 1)] =...
Design, code, and test a program that accepts positive integers until the value 204 is entered....
Design, code, and test a program that accepts positive integers until the value 204 is entered. After input terminates, the program should report the total number of even integers (excluding the special number 204) , the average value of the even integers, the total number of odd integers, and the average value of the odd integers. The program should also report "Evens won!", "Odds won!", or "Evens and odds tied!" based on which total was greater. Test your program thoroughly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT