Find Jobs
Hire Freelancers

Parser java project -- 2

$10-30 USD

Closed
Posted over 1 year ago

$10-30 USD

Paid on delivery
You are supposed to add six new source files ([login to view URL], [login to view URL], [login to view URL], [login to view URL], [login to view URL], [login to view URL]) to the existing 3 files I will be providing ([login to view URL], [login to view URL], [login to view URL]). This project builds on an existing project. The parser will take the collection of tokens from the lexer and build them into a tree of AST nodes. To start this process, make an abstract Node class. Add an abstract ToString override. Now create an IntegerNode class that derives from Node. It must hold an integer number in a private member and have a read-only accessor. Create a similar class for floating point numbers called FloatNode.java. Both of these classes should have appropriate constructors and ToString() overrides. Create a new class called MathOpNode that also derives from Node. MathOpNode must have an enum indicating which math operation (add, subtract, multiply, divide) the class represents. The enum must be read-only. The class must have two references (left and right) to the Nodes that will represent the operands. These references must also be read-only and an appropriate constructor and ToString() must be created. Reading all of this, you might think that we can just transform the tokens into these nodes. This would work, to some degree, but the order of operations would be incorrect. Consider 3 * 5 + 2. The tokens would be NUMBER TIMES NUMBER PLUS NUMBER. That would give us MathNode(*,3,MathNode(+,5,2)) which would yield 21, not 17. Create a Parser class (does not derive from anything). It must have a constructor that accepts your collection of Tokens. Create a public parse method (no parameters, returns “Node”). Parse must call expression (it will do more later) and then matchAndRemove() a newLine. You must create some helper methods as matchAndRemove() as described in lecture. The classic grammar for mathematical expressions (to handle order of operations) looks like this: EXPRESSION = TERM { (plus or minus) TERM} TERM = FACTOR { (times or divide) FACTOR} FACTOR = {-} number or lparen EXPRESSION rparen Turn each of these (expression, term, factor) into a method of Parser. Use matchAndRemove to test for the presence of a token. Each of these methods should return a class derived from Node. Factor will return a FloatNode (NUMBER with a decimal point) or an IntegerNode (NUMBER without a decimal point) OR the return value from the EXPRESSION. Note the unary minus in factor – that is important to bind the negative sign more tightly than the minus operation. Also note that the curly braces are “0 or more times”. Think about how 3*4*5 should be processed with these rules. Hint – use recursion and a helper method. Also think carefully about how to process “number”, since we have two different possible nodes (FloatNode or IntegerNode). Depending on how you implemented your lexer, factor may or may not need to deal with negating the number. Finally, we will build (the beginning of) our interpreter. Create a new class called Interpreter. Add a method called “Resolve”. It will take a Node as a parameter and return a float. For now, we will do all math as floating point. The parser handles the order of operations, so this function is very simple. It should check to see what type the Node is: For FloatNode, return the value. For IntNode, return the value, cast as float. For MathOpNode, it should call Resolve() on the left and right sides. That will give you two floats. Then look at the operation (plus, minus, times, divide) and perform the math. Make sure that you test your code. Change your main to instantiate a parser (passing in the tokens from the lexer) and then call parse on the parser. Right now, it will only process a single line. Print your AST by using the “ToString” that you created. Use several different mathematical expressions and be sure that order of operations is respected. Then add a call to Resolve() and check the math.
Project ID: 34584405

About the project

3 proposals
Remote project
Active 2 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
3 freelancers are bidding on average $92 USD for this job
User Avatar
Hi Dear, I'm interested your project very well. I am a full time developer and i can work more than 10 hours in a day. I am mastering Java & OOP and I'm a good Engineer. And also I have many experience and good skill about algorithm development. I have top rank in hackerrank online competitions which is famous world best online coding competitions. I've been fortunate to have gained a lot of working knowledge and developed a deep appreciation and passion for this field. I'm certain I can apply my practical experience and skills to contribute to your firm's purpose and mission goals.
$75 USD in 1 day
5.0 (4 reviews)
3.4
3.4
User Avatar
Hi, I am developer more than 10 years . if you give me a chance, I can help you with your issue as soon as possible.
$150 USD in 2 days
5.0 (8 reviews)
3.6
3.6
User Avatar
Hi I have read your description carefully. I have rich experiences in JAVA. I will carry out this subject with the high quality in time. Please discuss via chat. Please kindly message me. Thank you.
$50 USD in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of UNITED STATES
Albany, United States
5.0
1
Payment method verified
Member since Sep 7, 2022

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.