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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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