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

  Create system in java using agile approach

You are a software manager in company which designs critical control software for aircraft. Create system in Java using agile approach with a user involved in the development team.

  Requests 2 numbers from the user and then passes

Write a program in java that requests 2 numbers from the user and then passes these 2 numbers to a method findMax that displays the largest number. Make sure your method is called fron main(). Test the method by passing various data to it

  Using notepad that implements a basic text analyzer

Write a Java application using Notepad that implements a basic Text Analyzer.

  Program that computes and prints the value of 6!/5! using

Write a Java program that computes and prints the  value of 6!/5! using Scanner.

  Tese 14 questions covers java class array link list

these 14 questions covers java class array link list generic class please read carfullynbspnbsp1. suppose we have a

  Produces a simple formatted report

For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below)

  Problem 1 the queue adta queue is a fundamental abstract

problem 1. the queue adta queue is a fundamental abstract data type. it is an ordered collection of items in which the

  Define a class called counter

Define a class called Counter. An object of this class is used to count things, so it records a count that is a non negative whole number. Include methods to set the counter to 0, to increase the count by

  What is an abstract class and how does it differ from the

question 1 what is an abstract class and how does it differ from a regular class? question 2 why are abstract class

  Recommend at least five factors which programmers must

propose at least five factors that programmers should consider when choosing between data types such as those used in c

  Write the code with comment and output resultinterface and

write the code with comment and output resultinterface and polymorphismimplement a class quiz that implements the

  Write a program that displays a frame window w pixels wide

Write a program that displays a frame window W pixels wide and H pixels high. Use the Scanner to enter the values for W and H. The title of the frame is also entered by the user.

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