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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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