CSC 340 Programming Languages and Compilation Assignment

Assignment Help Theory of Computation
Reference no: EM132471416

CSC 340 - Programming Languages and Compilation - King Saud University

Project Phase1: Scanning and Parsing using Lex and Yacc

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.

Part 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.

Part 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:

Start→ Program START Statements END
Statements → Statements Statement| Statement
Statement→ Dec stmt | Assignment stmt | Print stmt | Read stmt
| Condition stmt | While stmt
Dec stmt→ Type ID |Type ID,IDList IDList → ID | ID,IDList
Type→ int | double
Assignment stmt→ID = Expression
Expression → exp == exp | exp <> exp | exp < exp | exp <= exp| exp >= exp | exp >= exp | exp
exp→ exp + exp | exp - exp| exp * exp | exp /exp | exp || exp | exp && exp | !exp | Factor
Factor→ ( exp )| INT LITERAL | DBL LITERALL | ID Print stmt→ print ( ID ) | print ( STRING LITERAL ) Read stmt→ ID = read ( )
Condition stmt→ if (Expression ) statements While stmt→ while ( Expression ) statements

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.

Start
int X12 double ABC1 DDe =7
while ( QNn >0) ## this a Comment ##
{ RLk 9999 = ACc - 2
CCC = True
if( ACc == 5){ print (" Inside . IF. inside . Loop ") } } print (" Hello ")
End

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.

Attachment:- Programming Languages and Compilers.rar

Reference no: EM132471416

Questions Cloud

What is the optimal output level for kendall square : What is the optimal output level for Kendall Square, Inc in the short run?, What are its profits in the short run?, and what is the long-run cost function?
Describe the nature of the companys business : List the company's primary products or services (use brand names where available). What is the address of the company's corporate headquarters?
What quantity will be produced by each firm using technology : What quantity will be produced by each firm using technology 2? In equilibrium, how many firms using technology 2 will there be in the market?
How does ethics play in business globally : How does ethics play in business globally? Is it important? What strategies do business ours incorporated to keep corruption out?
CSC 340 Programming Languages and Compilation Assignment : CSC 340 Programming Languages and Compilation Assignment Help and Solution, King Saud University - Assessment Writing Service
How does price influence the quantity of an item : How does price influence the quantity of an item you are willing or able to purchase?
What is assumed about consumer income : What is assumed about consumer income when you measure price elasticity of demand?
Price elasticity of demand that is elastic or inelastic : If Walmart is rolling back prices to raise revenues, should it roll back prices on products that have a price elasticity of demand that is elastic or inelastic.
How does the analysis of macroeconomic control : How does the analysis of macroeconomic control need to be modified when considering the open, rather than the closed, economy?

Reviews

Write a Review

Theory of Computation Questions & Answers

  Finite-state machine design

Create a finite-state machine design to turn your FPGA development board into a simple programmable music box.

  Redundant sequence identi cation

Redundant sequence identi cation

  Compute a shortest superstring

Dynamic programming algorithm to compute a shortest superstring.

  Propositional and predicate logic

Write down a structural induction principle for the PlayTree free type

  Design a syntactic analyzer

Design a syntactic analyzer for the language specified by the grammar

  Design unambiguous grammar to parse expressions

Write a program would read two numbers and then print all numbers between the first and the second, inclusive. Design unambiguous grammar to parse expressions

  Consider a logic function with three outputs

Consider a logic function with three outputs,  A ,  B , and  C , and three inputs,  D ,  E , and  F . The function is defined as follows:  A  is true if at least one input is true,  B  is true

  Considering a single programmed operating system

Considering a single programmed operating system, what is the minimal total time required to complete executions of the two processes? You should explain your answer with a diagram.

  How to construct an nfa

Give a construction that assumes you are given a DFA for L and show how to construct an NFA (with or without ε-moves) to recognize sort(L).

  Equivalence classes to construct minimal dfa for language

How many equivalence classes does this relation have and what are they? Use these equivalence classes to construct the minimal DFA for the language.

  Impact of moore-s law on data center costs

Discuss the impact of Moore's law on data center costs on such things as servers and communications equipment. List at least 3 steps or recommendations your data center can take to offset some or all of the effect of Moore's law.

  Problem encountered in statements in predicate logic

How the problem would be encountered in attempting to represent the following statements in Predicate logic. it should be possible to: John only likes to see French movies.

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