Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Assignment Description

This assignment asks you to implement a basic parser for our dj2dism compiler. You will use bison to generate the parser.

First, download this CFG-less dj.y - in the attachment- Modify that dj.y by declaring appropriate precedence directives in the first section and a correct CFG for DJ in the second section. For this assignment, leave the actions in your CFG empty, except for the {return 0;} action for the CFG's starting symbol (Assignment IV will ask you to fill in the CFG actions to build an AST).

For full credit, your parser must have no conflicts (shift/reduce or reduce/reduce). To make it easier for you to complete Assignment IV in the future, you may want (but are not required) to declare your DJ grammar rules to be left recursive.

Hints

When you find that your parser has conflicts (like I did on my first attempt at this assignment), please examine your bison output file to find the cause of the conflict and then think calmly and carefully about how to modify the CFG to remove the conflict. Please do not just try to "hack" through the problem! Hacked-up grammars are normally complicated and hard to understand. Part of your grade on this assignment will be determined by the simplicity/elegance of your grammar.

My DJ CFG uses 12 nonterminals (e.g., pgm for a program, cdl for a class-declaration list, vdl for a variable-declaration list, t for a typename, id for an identifier, el for an expression list, expr for an expression, and ael for an argument-expression list).

Precedence and Associativity of Operators

A key challenge of this assignment is to declare precedence directives correctly and only in ways that immediately make sense to outside readers of your code.

Consider the following DJ expression (from file good11.dj):

n = n>6+3 && !2+3 && n = !c.n*!3 && 1+3==4

A correct and complete DJ parser (as yours should be after you complete Assignment IV) would produce the following AST for the good11.dj expression above:

1072_Precedence and Associativity of Operators.png

A correct declaration of precedence directives (%left, %nonassoc, %right) in this assignment will help produce these groupings. Notice, for instance that the DOT operator has the highest precedence, while the (right-associative) ASSIGN operator has the lowest precedence. The (left-associative) PLUS and MINUS operators should have equal precedences. The (nonassociative) EQUALITY and GREATER operators should also have equal precedences, though their precedences differ from those of PLUS and MINUS. Although the NOT operator is unary (i.e., only has one operand), you can declare it to be right associative for the sake of ordering its precedence.

Attachment:- dj.txt

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91596981
  • Price:- $110

Guranteed 48 Hours Delivery, In Price:- $110

Have any Question?


Related Questions in Computer Engineering

Search the internet for 5 open source reporting software

Search the internet for 5 open source reporting software packages of your choice? Explain why you think these software packages are the best for BI/DSS Reporting? Choose one of them and do associated with the reporting s ...

Decision support systems dss what sorts of dss tools do you

Decision support systems (DSS). What sorts of DSS tools do you use at your work - e.g., what-if analysis, sensitivity analysis, scenario analysis, goal-seeking analysis, optimization analysis, etc.? Even if you don't use ...

Question what is the relation between virtual memory a

Question : What is the relation between virtual memory, a memory map, physical memory and swapping to secondary memory? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow ...

What is the current balance of trade for the united states

What is the current balance of trade for the United States? Has this balance been increasing or decreasing? Based on the current economic conditions, how do you think this balance will move in the near future, and why?

According to a recent article the average number of babies

According to a recent article the average number of babies born with significant hearing loss (deafness) is approximately four per 1,000 babies in a healthy baby nursery. The number climbs to an average of 30 per 1,000 b ...

Youve entered a contract to purchase a new house and the

You've entered a contract to purchase a new house, and the closing is scheduled for next week. It's typical for some last-minute bargaining to occur at the closing table, where sellers often try to tack on extra fees. Yo ...

Assume you have been selected to build a system for

Assume you have been selected to build a system for Oil&Gas company. Do you prefer to build a win-based system or a web-based system? Why?

A financial analyst examined the possible returns from

A financial analyst examined the possible returns from several financial investments. When the performance of these investments was later examined, it turned out that 25% performed much better than the market average, 25 ...

Search the web for two or more sites that discuss the

Search the web for two or more sites that discuss the ongoing responsibilities of security manager. What other components of security management, as outlined by this model, can be adapted for use in the security manageme ...

In simple python form pleasewrite a script that asks the

In Simple Python form please: Write a script that asks the user to input the name of a file, opens the file, reads its contents, prints the contents of the file on the screen, and closes the file. If no such file exists, ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As