Question: implement a lexical analyzer for a Pascal-like language using Lex tool. The lexical analyzer should recognize identifiers, integer literals, string literals, keywords, and predefined symbols.

implement a lexical analyzer for a Pascal-like language using Lex tool. The lexical analyzer should recognize identifiers, integer literals, string literals, keywords, and predefined symbols. Their definitions are below:

1- Lexical Classes: (note that '|' and the outermost '(' and ')' are meta-symbols and not part of the alphabet)

ID = letter (letter | digit | _)* INT = digit+ STR = "*" WS = ( | | )+ SYM = ( + |-| * | = | < | <= | > | >= | <> | . | , | : | ; | ..| := | ( | ) | [ | ] ) In the above definitions, can be any printing character capital or small. Of course, WS (white space) only serves as a delimiter and no corresponding token should be returned by the lexical analyzer.

2- Keywords and reserved symbols: the symbols and names that the lexer should recognize are:

and, begin, forward, div, do, else, end, for, function, if, array, mod, not, of, or, procedure, program, record, then, to, type, var, while, +, *, -, =, <, <=, >, >=, <>, ., ,, :, ;, :=, .., (, ), [, ]

The language is case sensitive. Each keyword should be uniquely identified by its own token. You may choose to return the same token (e.g. RELOP) for every relational operator (with different lexemes, of course) or a different token for each relational operator. The same is true for arithmetic operators.

3- Comments In the programming language you are building a compiler for, comments consist of text enclosed in matching curly braces, namely { and }. No token should be produced for comments. The lexer, upon encountering a comment, should produce the first token following the end of the comment.

write code in C++

please note DONT COPY AND PASTE other solutions the answer should be right and clear

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!