Find Jobs
Hire Freelancers

Parser java project -- 2

$10-30 USD

Cerrado
Publicado hace más de 1 año

$10-30 USD

Pagado a la entrega
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.
ID del proyecto: 34584405

Información sobre el proyecto

3 propuestas
Proyecto remoto
Activo hace 2 años

¿Buscas ganar dinero?

Beneficios de presentar ofertas en Freelancer

Fija tu plazo y presupuesto
Cobra por tu trabajo
Describe tu propuesta
Es gratis registrarse y presentar ofertas en los trabajos
3 freelancers están ofertando un promedio de $92 USD por este trabajo
Avatar del usuario
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 en 1 día
5,0 (4 comentarios)
3,4
3,4
Avatar del usuario
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 en 2 días
5,0 (8 comentarios)
3,6
3,6
Avatar del usuario
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 en 1 día
0,0 (0 comentarios)
0,0
0,0

Sobre este cliente

Bandera de UNITED STATES
Albany, United States
5,0
1
Forma de pago verificada
Miembro desde sept 7, 2022

Verificación del cliente

¡Gracias! Te hemos enviado un enlace para reclamar tu crédito gratuito.
Algo salió mal al enviar tu correo electrónico. Por favor, intenta de nuevo.
Usuarios registrados Total de empleos publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Cargando visualización previa
Permiso concedido para Geolocalización.
Tu sesión de acceso ha expirado y has sido desconectado. Por favor, inica sesión nuevamente.