Brief Introduction to LEX and YACC compilers



Compilers scan the entire program and translate it as a whole into a machine code whereas an Interpreter translates one statement at a time. This results compiling being a faster process.


The translation process constitutes of Analysis and Synthesis, while the Interpretation process constitutes of Analysis and Execution .


About LEX and YACC 


Lex


Lex is a computer program that generates lexical analysers ("scanners" or "lexers"). Lex is used with the common parser generator, Yacc. These are two tools that help you write programs that process input.


Both these tools work by the user providing a specification file that the program uses to generate C or C++ source code. Flex and Bison are more widely used than Lex and Yacc, as they produce more faster codes in comparison.


Lex is designed for the lexical processing of the character by character input streams. The program accepts strings in high-level language, and generates a general purpose program. Regular expressions can be recognized by this program.


The regex are already specified to Lex and the code recognizes them, whether they are present in any input stream. This further makes partitions of the input in the matching strings.


The Lex file connects the regexes and fragments of the program. The corresponding fragment comes into execution as the expression comes into the input of lex program. 


Lex code can be written in many host languages, i.e. the language used to output the code of LEX. This makes compatibility of lex to more environments and users.


YACC-Yet Another Compiler Compiler
Computer program input generally has some structure, defining an input language which it accepts. Input language may be complex or simple
Yacc offers a tool that is used to describe input to any program. Portable C is used to write YACC.


Structures of the input and the code that is to be invoked and a low level routine is specified by the user. This specification is converted in subroutine used to handle inputs, which return next input item.


This specification can be made as input characters or high level constructs like names, numbers. LALR(1) grammars with disambiguating rules are also such example.


A function is generated to control inputs. Parser calls lexical analyzer to pick tokens and organize them as per the rules of grammar. User code is supplied, then action is invoked, which can return the values and use them for another actions.

Editor: Aastha Gupta Added on: 2020-05-25 17:54:18 Total View:360







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---