jagomart
digital resources
picture1_Compiler Design Lab Manual 189261 | Lm Cd Item Download 2023-02-03 07-57-15


 124x       Filetype PDF       File size 0.53 MB       Source: ggnindia.dronacharya.info


File: Compiler Design Lab Manual 189261 | Lm Cd Item Download 2023-02-03 07-57-15
lab manual of compiler design department of electronics computer engg dronacharya college of engineering khentawas gurgaon 123506 list of experiments s no aim of experiment 1 study of lex and ...

icon picture PDF Filetype PDF | Posted on 03 Feb 2023 | 2 years ago
Partial capture of text on file.
         
         
         
         
         
         
         
         
         
                       LAB MANUAL OF     
                     COMPILER DESIGN 
         
         
         
         
         
         
         
        Department of Electronics & Computer Engg. 
                        
           Dronacharya College Of Engineering 
             Khentawas, Gurgaon – 123506 
         
         
         
         
         
         
                                                                    
                                   LIST OF EXPERIMENTS 
               
               
               S. No.                          AIM OF EXPERIMENT 
                                                                
                  1.                     STUDY OF LEX AND YACC TOOLS. 
                   2             TO CONVERT REGULAR EXPRESSION INTO NFA. 
                   3                          WAP TO FIND FIRST IN CFG. 
                  4.               WAP TO FIND STRING IS KEYWORD OR NOT. 
                  5.               WAP TO FIND STRING IS IDENTIFIER OR NOT. 
                  6.               WAP TO FIND STRING IS CONSTANT OR NOT. 
                  7.         WAP TO COUNT NO. OF WHITESPACES AND NEWLINE. 
                  8.       WAP TO GENERATE TOKENS FOR THE GIVEN GRAMMER. 
                  9.                    AN ALGO TO CONVERT NFA TO DFA. 
                  10.                    AN ALGO FOR MINIMIZING OF DFA. 
                  11.           WAP TO CHECK STRING IS IN GRAMMER OR NOT. 
                  12.     WAP TO CALCULATE LEADING FOR ALL NON TERMINALS 
                                                               . 
                  13.             WAP TO CALCULATE TRAILING FOR ALL NON 
                                                       TERMINALS . 
               
               
               
                      PROGRAM NO:-1                                                
                            
            PRACTICE OF LEX/YACC OF COMPILER WRITING 
        
        
       A compiler or interpreter for a programming language is often decomposed into 
       two parts: 
        1.  Read the source program and discover its structure. 
        2.  Process this structure, e.g. to generate the target program. 
       Lex and Yacc can generate program fragments that solve the first task. 
       The task of discovering the source structure again is decomposed into subtasks: 
        1.  Split the source file into tokens (Lex). 
        2.  Find the hierarchical structure of the program (Yacc). 
       Lex - A Lexical Analyzer Generator 
       Lex is a program generator designed for lexical processing of character input 
       streams. It accepts a high-level, problem oriented specification for character string 
       matching, and produces a program in a general purpose language which recognizes 
       regular expressions. The regular expressions are specified by the user in the source 
       specifications given to Lex. The Lex written code recognizes these expressions in 
       an input stream and partitions the input stream into strings matching the 
       expressions. At the boundaries between strings program sections provided by the 
       user are executed. The Lex source file associates the regular expressions and the 
       program fragments. As each expression appears in the input to the program written 
       by Lex, the corresponding fragment is executed. 
        
       Lex helps write programs whose control flow is directed by instances of regular 
       expressions in the input stream. It is well suited for editor-script type 
       transformations and for segmenting input in preparation for a parsing routine. 
       Lex source is a table of regular expressions and corresponding program fragments. 
       The table is translated to a program which reads an input stream, copying it to an 
       output stream and partitioning the input into strings which match the given 
       expressions. As each such string is recognized the corresponding program 
       fragment is executed. The recognition of the expressions is performed by a 
        
        
        
                     deterministic finite automaton generated by Lex. The program fragments written 
                     by the user are executed in the order in which the corresponding regular 
                     expressions occur in the input stream. 
                     The lexical analysis programs written with Lex accept ambiguous specifications 
                     and choose the longest match possible at each input point. If necessary, substantial 
                     lookahead is performed on the input, but the input stream will be backed up to the 
                     end of the current partition, so that the user has general freedom to manipulate it.                                       
                     Lex can generate analyzers in either C or Ratfor, a language which can be 
                     translated automatically to portable Fortran. It is available on the PDP-11 UNIX, 
                     Honeywell GCOS, and IBM OS systems. This manual, however, will only discuss 
                     generating analyzers in C on the UNIX system, which is the only supported form 
                     of Lex under UNIX Version 7. Lex is designed to simplify interfacing with Yacc, 
                     for those with access to this compiler-compiler system. 
                      
                                         Lex generates programs to be used in simple lexical analysis of text. 
                                         The input files (standard input default) contain regular expressions to 
                                         be searched for and actions written in C to be executed when 
                                         expressions are found. 
                                         A C source program, lex.yy.c is generated. This program, when run, 
                                         copies unrecognized portions of the input to the output, and executes 
                                         the associated C action for each regular expression that is recognized. 
                                         The options have the following meanings. 
                                         –t    Place the result on the standard output instead of in file lex.yy.c. 
                                         –v    Print a one–line summary of statistics of the generated analyzer. 
                                         –n    Opposite of –v; –n is default. 
                                         –9    Adds code to be able to compile through the native C compilers. 
                      
                     EXAMPLE 
                          This program converts upper case to lower, removes blanks at the end of lines, 
                          and replaces multiple blanks by single blanks. 
                          %% 
                          [A–Z]       putchar(yytext[0]+'a'–'A'); 
                          [ ]+$ 
                          [ ]+ putchar(' ') 
                      
                      
                      
The words contained in this file might help you see if this file matches what you are looking for:

...Lab manual of compiler design department electronics computer engg dronacharya college engineering khentawas gurgaon list experiments s no aim experiment study lex and yacc tools to convert regular expression into nfa wap find first in cfg string is keyword or not identifier constant count whitespaces newline generate tokens for the given grammer an algo dfa minimizing check calculate leading all non terminals trailing program practice writing a interpreter programming language often decomposed two parts read source discover its structure process this e g target can fragments that solve task discovering again subtasks split file hierarchical lexical analyzer generator designed processing character input streams it accepts high level problem oriented specification matching produces general purpose which recognizes expressions are specified by user specifications written code these stream partitions strings at boundaries between sections provided executed associates as each appears corre...

no reviews yet
Please Login to review.