Write lex input file that will produce scanner

Assignment Help Basic Computer Science
Reference no: EM132594722

1. Write a Lex input file that will produce a scanner that capitalizes all comments in a C program.

Moreover after replicating its input program in the terminal (or in a file),

the scanner should append the

total number of comments to its output. Your scanner should be able to accept

optional command line

arguments to indicate the input and output filenames. Please consider using

toupper(char c) from

<ctype.h> to convert to uppercase.

2. Write a rule in Lex to print integer numbers that are multiple of five.

The numbers are allowed to have an optional sign (+/-). You are not neither allowed to convert the matched strings into integers, nor to use the modulus operator (%) in your rule.

3. Give only the rule section of a Lex input file for a scanner that prints  only all the letters in its input on screen, and ignores everything else.

4. Answer the following:

a) Write down an unambiguous grammar that generates the set of strings { s; , s;s; , s;s;s; , ... }.

The semicolon should be right associative.

b) Give a leftmost and a rightmost derivation for the string s;s; using your  grammar.

5. Given the grammar

exp → exp + term | exp - term | term

term → term * factor | factor

factor → ( exp ) | number

a) Write down a parse tree and abstract syntax tree for the expressions  3+4*5-6.

b) On the parse tree, number the nodes to represent a rightmost derivation.

6. Consider the following grammar representing simplified LISP-like expressions

lexp → atom | list

atom → number | identifier

list → ( seq )

seq → seq lexp | lexp

a) Draw a parse tree for the LISP expression (a 23 (m x y)). Number the  nodes in the tree to represent a leftmost derivation. There are one number and 4 identifiers in the given expression besides the parentheses.

b) Translate the given grammar into EBNF.

c) Draw syntax diagrams for the EBNF from part (b).

7. Give a grammar that generates the following set of strings

a) { an bn?¹ | n ≥ 0 }.

b) { an?¹cbn | n ≥ 0 }.

8. Given the following grammar

statement → if-stmt | other | ε if-stmt → if ( exp ) statement else-part else-part → else statement | ε exp → 0 | 1

a) Is the grammar ambiguous? Justify your answer (with examples if  applicable)

b) Draw a parse tree for the string if(0) if(1) other else else other

c) What is the purpose of the two else's in the given string?

Reference no: EM132594722

Questions Cloud

Unique strategic challenges : What are some of the unique strategic challenges that Christian universities face? How has the unprecedented Covid-19 pandemic crisis impacted your life?
Why does an acquirer need to use fair value measurement : IFRS 3 Business Combinations states, Critically justify why does an acquirer need to use fair value measurement methods with regard to IFRS 3?
Describe the typical developmental stages of children : Choose a child between the ages of 5 and 12 years old. Identify the age of the child and describe the typical developmental stages of children that age.
Find how does company record the receipt of the note : How does company record the receipt of the note? Do calculations for discount amortizations if applicable along with early journal entries company had to pass
Write lex input file that will produce scanner : Write Lex input file that will produce scanner that capitalizes all comments in C program. Write rule in Lex to print integer numbers that are multiple of five.
How does the company record the receipt of the note : How does the company record the receipt of the note? Do calculations for discount amortizations if applicable along with early journal entries
Identify three users of financial statement : Identify Three (3) users of financial statement and briefly explained information that they would like to know from the financial statements.
Find Towson Company Net Cash Flows from Operating Activities : Common Stock exchanged for outstanding Long Term Notes Payable of $125,000, find Towson Company's Net Cash Flows from Operating Activities
What is the usefulness of a use tax : What is the usefulness of a use tax? Provide some examples of a use tax.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Concept of social engineering attack

Explain the concept of a social engineering attack and the methods you would employ to reduce your organization's exposure to it.

  Find the percent of adults in each province or territory

It makes no sense to find for these data and use it to get a confidence interval for the mean percent μ in all 13 provinces or territories. Why not?

  What is your experience with computer forensics

What is your experience with Computer Forensics? What is Web Browser Forensics and why is it so important? How do top web browsers differ and how are they alike

  Resources for developing applications for ebxm

Provide a well reasoned and support paper to accomplish the above requirements.

  Develop a prototype to display the financial results

Develop a prototype to display the financial results of a public company

  Factors that can make software risk management difficult

This characteristic Is related to which one of the following unique factors that can make software risk management difficult?

  What is the annual increment

A man starts his job with a certain monthly salary and a fixed increment every year. his salary will be Rs 11000 after 2 years and Rs 14000 after 4 years. What is his starting salary and what is the annual increment?

  Relationship between a digital signal

Describe the difference in analog and digital signals, and explain which is used in current computer architectures. Explain the relationship between a digital signal's period and its frequency. Explain the states of a digital signal.

  What is the difference between a virus and a worm

What is the difference between a virus and a worm?

  Relationship between accuracy and overall error rate

What is the difference between the total predicted negative and the total actually negative?

  Develop policy for optimizing bus and local train schedules

describe how these tools could be used to develop policy for optimizing bus and local train schedules to minimize energy use and passenger wait times

  Design and analysis of algorithm

Subject: Design and Analysis of Algorithm 1: Give short and logical explanation of the following questions.

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