This document discusses Lex and Yacc, tools used to generate lexical analyzers and parsers. Lex reads regular expression patterns and generates a lexical analyzer in C. Yacc reads a context-free grammar specification and generates a C parser. The document provides examples of Lex and Yacc input structures and grammars. It also describes how a Lex analyzer and Yacc parser can be linked together to recognize programming language structures.
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof Chethan Raj C
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operating System Lab Manual.
1) To make students familiar with Lexical Analysis and Syntax Analysis phases of Compiler Design and implement programs on these phases using LEX & YACC tools and/or C/C++/Java.
2) To enable students to learn different types of CPU scheduling algorithms used in Operating system.
3) To make students able to implement memory management - page replacement and deadlock handling algorithms.
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof Chethan Raj C
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operating System Lab Manual.
1) To make students familiar with Lexical Analysis and Syntax Analysis phases of Compiler Design and implement programs on these phases using LEX & YACC tools and/or C/C++/Java.
2) To enable students to learn different types of CPU scheduling algorithms used in Operating system.
3) To make students able to implement memory management - page replacement and deadlock handling algorithms.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
2. References
*Tom Niemann. “A Compact Guide to Lex & Yacc ”. Portland,
Oregon. 18 April 2010 <http://epaperpress.com>
*Levine, John R., Tony Mason and Doug Brown [1992]. Lex &
Yacc. O’Reilly & Associates, Inc. Sebastopol, California.
2
Hathal & Ahmad
4. Lex
lex is a program (generator) that generates lexical
analyzers, (widely used on Unix).
It is mostly used with Yacc parser generator.
Written by Eric Schmidt and Mike Lesk.
It reads the input stream (specifying the lexical analyzer )
and outputs source code implementing the lexical analyzer
in the C programming language.
Lex will read patterns (regular expressions); then produces
C code for a lexical analyzer that scans for identifiers.
4
Hathal & Ahmad
5. Lex
◦ A simple pattern: letter(letter|digit)*
Regular expressions are translated by lex to a computer program that mimics an
FSA.
This pattern matches a string of characters that begins with a single letter
followed by zero or more letters or digits.
5
Hathal & Ahmad
6. Lex
Some limitations, Lex cannot be used to recognize nested structures such as
parentheses, since it only has states and transitions between states.
So, Lex is good at pattern matching, while Yacc is for more challenging
tasks.
6
Hathal & Ahmad
11. Lex
Whitespace must separate the defining term and the associated expression.
Code in the definitions section is simply copied as-is to the top of the generated C file and must
be bracketed with “%{“ and “%}” markers.
substitutions in the rules section are surrounded by braces ({letter}) to distinguish them from
literals.
11
Hathal & Ahmad
12. Yacc
Theory:
◦ Yacc reads the grammar and generate C code for a parser .
◦ Grammars written in Backus Naur Form (BNF) .
◦ BNF grammar used to express context-free languages .
◦ e.g. to parse an expression , do reverse operation( reducing the
expression)
◦ This known as bottom-up or shift-reduce parsing .
◦ Using stack for storing (LIFO).
12
Hathal & Ahmad
13. Yacc
Input to yacc is divided into three sections.
... definitions ...
%%
... rules ...
%%
... subroutines ...
13
Hathal & Ahmad
14. Yacc
The definitions section consists of:
◦ token declarations .
◦ C code bracketed by “%{“ and “%}”.
◦ the rules section consists of:
BNF grammar .
the subroutines section consists of:
◦ user subroutines .
14
Hathal & Ahmad
15. yacc& lex in Together
The grammar:
program -> program expr | ε
expr -> expr + expr | expr - expr | id
Program and expr are nonterminals.
Id are terminals (tokens returned by lex) .
expression may be :
◦ sum of two expressions .
◦ product of two expressions .
◦ Or an identifiers
15
Hathal & Ahmad