Write a scanner that translates logical expressions

Assignment Help JAVA Programming
Reference no: EM13552145

Scanning represents a common class of algorithms that is widely used by programmers. In this assignment you will write a scanner. The project will utilize your knowledge of finite state machines and text files.

Scanners process test by translating a stream of input characters into tokens. Each token represents a contiguous group of characters. For example, the scanner in a compiler would input the following line of Java

  while (myInt > 1000)

and discover the following six tokens:

1) the keyword while

2) the left paren

3) the variable name myInt

4) the less than symbol

5) the integer 1000

6) the right paren

Write a scanner that translates logical expressions. There are many different notations for logical expressions. For example, Java uses the constants "true" and "false", while philosophers often abbreviate these as "T" and "F" and Boolean algebraists use "1" and "0". Your scanner is going to produce logical expressions in a compact form that uses one symbol per constant and one symbol per operator. Below is a table of all of the allowable output symbol tokens, and associated logical semantics, for your scanner.

Token

Meaning

T

logical value of TRUE

F

logical value of FALSE

~

NOT operator

^

AND operator

V

inclusive OR operator

x

exclusive or (XOR) operator

IMPLIES operator

=

EQUIVALENCE operator

(

a left paren

)

a right paren

?

this symbol denotes a syntax error

The program needs to be more flexible in the acceptable form of the syntax that is translated. FOr example, unlimited blanks are permitted (but not required) before, after or between tokens. No blanks will result in the output. The permissible input tokens prior to translation are explained below:

TRUE value -- any unsigned integer with an odd value

FALSE value -- any unsigned integer with an even value

NOT -- # 

!

AND -- &

*

OR --  +

XOR -- <>

!=

IMPLIES --     =>

any string of zero or more consecutive dashes (-) followed by a > symbol

EQUIVALENCE --      =

==

left paren -     (

right paren --   )

 

Note that all of the preceding notations are used in some settings for the associated tokens, but these particular tokens were selected in order to work better with FSMs. Anything other than what was described should be considered incorrect syntax and result in a ? symbol for a token.

You will be graded largely on how effectively you utilize a finite state machine and the associated table-driven code to solve this problem. You should view the problem as an FSM that scans one character at a time in order to transition from state to state. Each state transition has one of three associated actions:

1) add another token to the output string

2) read another character

3) add another token to the output string AND read another character.

Since the "add another token" action does not always add the same token, it is helpful to view your FSM as using three, rather than two, tables -- namely, a next state table, an action table and an output token table. Also, when building these tables you can take advantage of the fact that all valid input characters fall in the range from a blank to the greater than character.

Your final submission also needs to follow these guidelines:

1) You are reuired to submit a graphical representation (states with labeled arcs) to describe your FSM.

2) The FSM tables must be read from a text file that is included with your src folder files when you submit the program.

3) The input string to be tokenized must be read from a text file and you must use a JFileChooser object to allow the user to select this input file.

4) The output sequence of tokens must be displayed in a JFrame that pops upt when your program completes the scan.

Reference no: EM13552145

Questions Cloud

What volume of water is flowing in the channel : Water is flowing in an open channel that is 2.00 m wide. The water surface is 3.00 m above the bottom of the channel. What volume of water is flowing in the channel
Introduction our national eating disorder : The Omnivore’s Dilemma by Michael Pollan begins with an introduction, “Our National Eating Disorder,” which establishes the themes, history, and purposes for reading.
How many star images then fit onto the chip : A certain telescope forms an image of part of a cluster of stars on a square silicon charge-coupled detector (CCD) chip 2.00 cm on each side. How many star images then fit onto the chip
Develop a relative frequency distribution : Develop a relative frequency distribution for these data
Write a scanner that translates logical expressions : Write a scanner that translates logical expressions. There are many different notations for logical expressions.
Estimate what was the initial speed of the bullet : A .01 kg bullet is fired into a 5.0 kg wood block that is at rest on a level wood table. The block, with the bullet embedded, slides .05 m across the table. What was the initial speed of the bullet
Find the pressure after the reaction ends : 100 grams of oxygen and 100 grams of hydrogen gas occupy separate, equal sections of 200 liter tank. find the pressure after the reaction ends
Yukl book leadership in organizations : The case Nissan from Yukl's book Leadership in Organizations
Estimate what is his power output : 700 newton Marine in basic traning climbs a 10 meter wall vertical rope at a constant speed in 8 seconds. What is his power output

Reviews

Write a Review

JAVA Programming Questions & Answers

  User enter a series of numbers

Design a java program with a loop that lets the user enter a series of numbers. The user should enter - 99 to signal the end of the series. After all the numbers have been enter been entered, the program should display the largest and smallest number..

  Eplain the main purpose of using javascript on a website

question 1 what is the purpose of using javascript on a website? what is a specific example of a javascript

  Write method called median that accepts an array of integer

Write a method called median that accepts an array of integers as its parameter and returns the median of the numbers in the array.

  Determine the type of moped

Write a driver class called MopedRental. This class should perform the following: asks the user to enter the size of the moped, the day of the week and the number of hours rented, creates the Moped object, based on the size, and displays the input..

  Create a complete java application that meets these

create a complete java application that meets these requirements1. the program has an opening comments section using

  Write a class array that encapsulates an array

Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray[10]. The public members should be a default constructor and methods (signatures shown below) to provide ..

  Implement the application using a singly linked list

Implement the following application using a singly linked list. This application accepts from console and stores a list of 10 names of your friends in the singly linked list

  Part - a1nbsp to compile and run a java source file

part - a1.nbsp to compile and run a java source file hello.java that contains a main method which of the following are

  Write java program that calculates total order for customer

Write a Java program that calculates the total order for a customer. The order should include the details of buying several products. For each product (item), there should be a product code, product price, product description, and product icon.

  Redesign the grading program as an object-oriented design

redesign the grading program as an object-oriented design. We will start with a simple Student class. The student will have a name, an id (as a String) and a set of grades (as doubles)

  Prepare a java simulation program

Given a hash function h, prepare a java simulation program to determine each of the subsequent quantities after 0.8*tablesize random keys have been generated. The keys should be random integers.

  Delete a random element from an arraylist

Elements in an ArrayList and picking one at random to remove. Unfortunately, this slow, since deleting a random element from an ArrayList is slow because of all the shifting. For this question, you should modify the poll()method so that it runs in..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd