Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write using LEX AND YACC write using LEX AND YACC Design and implement a lexical analyzer that recognizes the following tokens: num :;s 011213141516171819 letter>

write using LEX AND YACC image text in transcribed
write using LEX AND YACC
Design and implement a lexical analyzer that recognizes the following tokens: num :;s 011213141516171819 letter> ( I )* cdigit+(. digit+?(E(+1-Jdigit+)? V : := array : : estmt stmtb stmtb estmt stmt stmt> stmtb estmt stmt { | end :if (cexpr>) ::#while ( : do while (expr>) :case : : = switch ( ) : : break ; I continue ; ::retum cexpr cfor_stmt> cfor stmt> cassignstmt ccondition> expr :for(assign_stmt>; :cassign stmt>) cterm> 1 / term> cliteral> : : = | ( [digit>]. The input for the lexical analyzer is a text file SOURCE.TXT consisting of several lines of text (a "program containing sequences of lexemes corresponding to the above definitions, whitespaces and comments. The input program can be incorrect so your lexical analyzer should generate error messages indicating the line(s) of these errors The output of your lexical analyzer consists of 2 text files ST.TXT and TOKENS.TXT 1 ST.TXT is the symbol table created by the lexical analyzer. Each line consists of three parts: line number -the lexeme (string) -type (string),being one of the following: keyword, identifier, num 2. TOKENS.TXT is the list of tokens produced by the lexical analyzer with the following structure: -one line of input (in the order of appearance in SOURCE.TXT) -corresponding pairs "token, attribute", each in separate line in the order as they occur in the line -blank line The attribute of keyword, identifier or a number is the line number in the symbol table. The attribute of any other token is lexeme itself. The longest prefix of the input that can match any regular expression pi is taken as the next token. Design and implement a lexical analyzer that recognizes the following tokens: num :;s 011213141516171819 letter> ( I )* cdigit+(. digit+?(E(+1-Jdigit+)? V : := array : : estmt stmtb stmtb estmt stmt stmt> stmtb estmt stmt { | end :if (cexpr>) ::#while ( : do while (expr>) :case : : = switch ( ) : : break ; I continue ; ::retum cexpr cfor_stmt> cfor stmt> cassignstmt ccondition> expr :for(assign_stmt>; :cassign stmt>) cterm> 1 / term> cliteral> : : = | ( [digit>]. The input for the lexical analyzer is a text file SOURCE.TXT consisting of several lines of text (a "program containing sequences of lexemes corresponding to the above definitions, whitespaces and comments. The input program can be incorrect so your lexical analyzer should generate error messages indicating the line(s) of these errors The output of your lexical analyzer consists of 2 text files ST.TXT and TOKENS.TXT 1 ST.TXT is the symbol table created by the lexical analyzer. Each line consists of three parts: line number -the lexeme (string) -type (string),being one of the following: keyword, identifier, num 2. TOKENS.TXT is the list of tokens produced by the lexical analyzer with the following structure: -one line of input (in the order of appearance in SOURCE.TXT) -corresponding pairs "token, attribute", each in separate line in the order as they occur in the line -blank line The attribute of keyword, identifier or a number is the line number in the symbol table. The attribute of any other token is lexeme itself. The longest prefix of the input that can match any regular expression pi is taken as the next token

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

what is python code for addtion

Answered: 1 week ago

Question

6. How will you provide encouragement and support?

Answered: 1 week ago