Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I found a program that works similar with this homework but have slightly different requirements. You can modify it to read the input file given

I found a program that works similar with this homework but have slightly different requirements. You can modify it to read the input file given in my homework.

https://www.codeproject.com/Articles/833206/Lexical-analyzer-an-example

Homework 1

Write a C 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 ::= ::= { , CustomerInfo, ListOfItems ::= { ( ()), Address, ( ()) ::= { ( ()) OPTIONAL, ( ()), (() ("A".."Z")), (()) ::= ( ()) Item ::= { (), ("Black" | "Blue" | "Brown"), (), (), (), ( .. ), END

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

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

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago