1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran.

Slides:



Advertisements
Similar presentations
Compiler construction in4020 – lecture 2 Koen Langendoen Delft University of Technology The Netherlands.
Advertisements

Compiler Baojian Hua Lexical Analysis (II) Compiler Baojian Hua
Lex -- a Lexical Analyzer Generator (by M.E. Lesk and Eric. Schmidt) –Given tokens specified as regular expressions, Lex automatically generates a routine.
 Lex helps to specify lexical analyzers by specifying regular expression  i/p notation for lex tool is lex language and the tool itself is refered to.
Yacc YACC BNF grammar example.y Other modules example.tab.c Executable
Tools for building compilers Clara Benac Earle. Tools to help building a compiler C –Lexical Analyzer generators: Lex, flex, –Syntax Analyzer generator:
Chapter 3 Chang Chi-Chung. The Structure of the Generated Analyzer lexeme Automaton simulator Transition Table Actions Lex compiler Lex Program lexemeBeginforward.
COS 320 Compilers David Walker. Outline Last Week –Introduction to ML Today: –Lexical Analysis –Reading: Chapter 2 of Appel.
Lecture 2: Lexical Analysis CS 540 George Mason University.
ANTLR.
A brief [f]lex tutorial Saumya Debray The University of Arizona Tucson, AZ
LEX and YACC work as a team
1 Flex. 2 Flex A Lexical Analyzer Generator  generates a scanner procedure directly, with regular expressions and user-written procedures Steps to using.
Compilers: lex/3 1 Compiler Structures Objectives – –describe lex – –give many examples of lex's use , Semester 1, Lex.
CSC 338: Compiler design and implementation
1 YACC Parser Generator. 2 YACC YACC (Yet Another Compiler Compiler) Produce a parser for a given grammar.  Compile a LALR(1) grammar Original written.
CS 614: Theory and Construction of Compilers Lecture 10 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
Review: Regular expression: –How do we define it? Given an alphabet, Base case: – is a regular expression that denote { }, the set that contains the empty.
Lecture 2: Lexical Analysis
COMP 3438 – Part II - Lecture 2: Lexical Analysis (I) Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ. 1.
Scanning & FLEX CPSC 388 Ellen Walker Hiram College.
FLEX Fast Lexical Analyzer EECS Introduction Flex is a lexical analysis (scanner) generator. Flex is provided with a user input file or Standard.
Flex: A fast Lexical Analyzer Generator CSE470: Spring 2000 Updated by Prasad.
LEX (04CS1008) A tool widely used to specify lexical analyzers for a variety of languages We refer to the tool as Lex compiler, and to its input specification.
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
THE FUNCTIONS AND PURPOSES OF TRANSLATORS TOPIC 2 CONTENT: 2.1. Types of translators 2.2. Lexical analysis 2.3. Syntax analysis 2.4. Code generation 2.5.
JLex Lecture 4 Mon, Jan 24, JLex JLex is a lexical analyzer generator in Java. It is based on the well-known lex, which is a lexical analyzer generator.
Lexical Analysis – Part I EECS 483 – Lecture 2 University of Michigan Monday, September 11, 2006.
Introduction to Lex Ying-Hung Jiang
Introduction to Yacc Ying-Hung Jiang
1 Using Lex. 2 Introduction When you write a lex specification, you create a set of patterns which lex matches against the input. Each time one of the.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
Introduction to Lex Fan Wu
Introduction to Lexical Analysis and the Flex Tool. © Allan C. Milne Abertay University v
Flex Fast LEX analyzer CMPS 450. Lexical analysis terms + A token is a group of characters having collective meaning. + A lexeme is an actual character.
Practical 1-LEX Implementation
1 Lex & Yacc. 2 Compilation Process Lexical Analyzer Source Code Syntax Analyzer Symbol Table Intermed. Code Gen. Code Generator Machine Code.
Compiler Principle and Technology Prof. Dongming LU Mar. 26th, 2014.
YACC. Introduction What is YACC ? a tool for automatically generating a parser given a grammar written in a yacc specification (.y file) YACC (Yet Another.
Lex & Yacc By Hathal Alwageed & Ahmad Almadhor. References *Tom Niemann. “A Compact Guide to Lex & Yacc ”. Portland, Oregon. 18 April 2010 *Levine, John.
Compiler Construction Sohail Aslam Lecture 9. 2 DFA Minimization  The generated DFA may have a large number of states.  Hopcroft’s algorithm: minimizes.
1 LEX & YACC Tutorial February 28, 2008 Tom St. John.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CS 614: Theory and Construction of Compilers Lecture 7 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Scanner Generation Using SLK and Flex++ Followed by a Demo Copyright © 2015 Curt Hill.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
LECTURE 6 Scanning Part 2. FROM DFA TO SCANNER In the previous lectures, we discussed how one might specify valid tokens in a language using regular expressions.
More yacc. What is yacc – Tool to produce a parser given a grammar – YACC (Yet Another Compiler Compiler) is a program designed to compile a LALR(1) grammar.
LEX SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
1 Syntax Analysis Part III Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
9-December-2002cse Tools © 2002 University of Washington1 Lexical and Parser Tools CSE 413, Autumn 2002 Programming Languages
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
Syntax Analysis Part III
Lexical Analysis.
NFAs, scanners, and flex.
Using SLK and Flex++ Followed by a Demo
Compiler Construction
Regular Languages.
TDDD55- Compilers and Interpreters Lesson 2
JLex Lecture 4 Mon, Jan 26, 2004.
Syntax Analysis Part III
Syntax Analysis Part III
Syntax Analysis Part III
Lecture 5: Lexical Analysis III: The final bits
Syntax Analysis Part III
Compiler Structures 3. Lex Objectives , Semester 2,
More on flex.
Regular Expressions and Lexical Analysis
Systems Programming & Operating Systems Unit – III
Compiler Design 3. Lexical Analyzer, Flex
Presentation transcript:

1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran

2 Outline What is Flex Structure of a Flex File Steps to use Flex Example Summary

3 What is Flex Flex (The Fast Lexical Analyzer) It is a tool for generating programs that perform pattern-matching on text. Flex is a free implementation of the original Unix lex program.

4 What is Flex(Contd.)

5 Structure of a Flex File Format: The definitions section: "name definition" The rules section: "pattern action" The user code section: "yylex() routine" definitions % rules % user code Required Optional

6 Steps to use Flex Create a lex file which has lexical specification rules for the lexer generator. It also has a main method within the file itself which repeatedly invokes the lexer and prints out the token and lexeme pairs. Compile this file by running the following command flex lexicalAnalyzer.l

7 Steps to use Flex(Contd.) A new file called lex.yy.c will be created in the same folder in which the above file was present. Compile this file by running the command: gcc lex.yy.c to generate a.out executable. Test the executable using :./a.out < "lexer_test.pas"

8 Example

9 Example(Contd.)

10 Example(Contd.)

11 Example(Contd.)

12 Summary Tool for generating programs that perform pattern- matching on text Input file is a lex file(.l file) and output file is a c file. Input file is divided into 3 sections: Definitions Rules User Code