logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

For this phase, you will use Lex tool for writing the scanner and Yacc tool for writing the parser for a programming language called AA.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

CSC340:Programming Languages and Compilers

1     AA Language

For this phase, you will use Lex tool for writing the scanner and Yacc tool for writing the parser for a programming language called AA.

1.    The Scanner and the Lexemes:

  • Keywords: int, double, if, read, print, while,START,END.

•       Operators:

  • Arithmetic: + , - , * , /

–   Logic:    &&,||,!

–   Relational:    ==, <>, <, <=, >,>=

  • Assignment: =
  • Punctuation elements: (),,,{}

Precedence and associativity

The table below shows all AA operators from highest to lowest precedence, along with their associativity.

 

Table 1: precedence and associativity table

Operator

Description

Associativity

!

Unary Logical NOT

right to left

∗/

Multiplication/Division

left to right

+−

Addition/ Subtraction

left to right

<, <=, >,>=

Relational

left to right

=<>

Equality

left to right

&&

Logical AND

left to right

||

Logical OR

left to right

=

Assignment

right to left

 

 

 

Identifiers: should start with capital letter and can include small, capital letters, underscores, or digits.

  • Comment: is sequence of any characters between double hash ##..... ##

Literals: INT LITERAL e.g. 12345, STRING LITERAL e.g. "Hello"and DBL LITERAL e.g. 3.14.

2.    The Parser and the Grammar:

When YACC finds input that doesn’t match the grammar, it automatically termi- nates with the message ’Syntax error’. You will need to implement an error routine (yyerror) that also prints out the line number before this termination, and a main method that read AA code from a file. Print an appropriate message in case of no syntax error. Build your parser using the grammar below:

2    Deliverable and rules

 Write the Lex and Yacc file for AA language as described above. Once you built your parser, you should be able to parse AA programs. If you want to test your code, consider the following program.

This program should be compiled and have no errors. Note that this program does not cover all functionalities that could be tested based on the given specification. Test your code thoroughly. If the input program is in different syntax than the given grammar, your parser should report an error.

You must deliver one zip including:

  • A soft copy of a lex file ”phase1.l”
  • A soft copy of a YACC file ”phase1.y”

Deadline is: Saturday March 14th, 2020 (11:59 pm).

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

696 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

684 Answers

Hire Me
expert
Husnain SaeedComputer science

883 Answers

Hire Me
expert
Atharva PatilComputer science

883 Answers

Hire Me