Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started