Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DO IN C Write code for lexical analysis to recognize the following lexical items. 1. The character set is: ASN.1 characters A to Z (LATIN

DO IN C

Write code for lexical analysis to recognize the following lexical items.

1. The character set is:

ASN.1 characters A to Z (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z)

a to z (LATIN SMALL LETTER A to LATIN SMALL LETTER Z)

0 to 9 (DIGIT ZERO to DIGIT 9)

" (QUOTATION MARK)

( (LEFT PARENTHESIS)

) (RIGHT PARENTHESIS)

, (COMMA)

- (HYPHEN-MINUS)

: (COLON)

= (EQUALS SIGN)

{ (LEFT CURLY BRACKET)

| (VERTICAL LINE)

} (RIGHT CURLY BRACKET)

2. Reserved Words: DEFINITIONS, AUTOMATIC, TAGS, BEGIN, SEQUENCE, VisibleString, SIZE, NumericString, OPTIONAL, FROM, INTEGER, BOOLEAN, END,

3. TOKENS: Range_Seperator, ASSIGN, LCURLY, RCURLY, COMMA, LPAREN, RPAREN, BAR, QUOTE, TypeRef, Identifier,Number

A lexical item shall be separated from a following lexical item by one or more instances of white-space.

white-space - numbers represent the ASCII Code:

HORIZONTAL TABULATION (9)

LINE FEED (10)

VERTICAL TABULATION (11)

FORM FEED (12)

CARRIAGE RETURN (13)

SPACE (32)

Type references

Name of lexical item typereference

A "typereference" shall consist of an arbitrary number (one or more) of letters, digits, and hyphens. The initial character shall be an upper-case letter. A hyphen shall not be the last character. A hyphen shall not be immediately followed by another hyphen.

NOTE The rules concerning hyphen are designed to a void ambiguity with (possibly following) comment.

Identifiers

Name of lexical item identifier

An "identifier" shall consist of an arbitrary number (one or more) of letters, digits, and hyphens. The initial character shall be a lower-case letter. A hyphen shall not be the last character. A hyphen shall not be immediately followed by another hyphen.

Numbers

Name of lexical item number

A "number" shall consist of one or more digits. The first digit shall not be zero unless the "number" is a single digit.

Assignment lexical item

Name of lexical item "::="

This lexical item shall consist of the sequence of characters: ::=

Range separator

Name of lexical item ".."

This lexical item shall consist of the sequence of characters: ..

{ - LURLY

} RCURLY

, COMMA

( LPAREN

) RPAREN

| BAR

QUOTE

The input String to test for success is:

-----------------------------------------------------------------

MyShopPurchaseOrders DEFINITIONS AUTOMATIC TAGS ::= BEGIN PurchaseOrder ::= SEQUENCE { dateOfOrder DATE, customer CustomerInfo, items ListOfItems } CustomerInfo ::= SEQUENCE { companyName VisibleString (SIZE (3..50)), billingAddress Address, contactPhone NumericString (SIZE (7..12)) } Address::= SEQUENCE { street VisibleString (SIZE (5 .. 50)) OPTIONAL, city VisibleString (SIZE (2..30)), state VisibleString (SIZE(2) FROM ("A".."Z")), zipCode NumericString (SIZE(5 | 9)) } ListOfItems ::= SEQUENCE (SIZE (1..100)) OF Item Item ::= SEQUENCE { itemCode INTEGER (1..99999), color VisibleString ("Black" | "Blue" | "Brown"), power INTEGER (110 | 220), deliveryTime INTEGER (8..12 | 14..19), quantity INTEGER (1..1000), unitPrice INTEGER (1 .. 9999), isTaxable BOOLEAN } END

-----------------------------------------------------------------------

You also make up some input string that will return some errors. For example insert some characters not part of the alphabet.

You are given description of some languages to recognize tokens.

2. Write a program that would recognize the listed tokens. The sample input is also given to you.

Your program will take the input and list each token in the input string.

DO NOT use the tools like flex. You must write the program in C. You can use the string manipulation library functions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago