Difference between revisions of "Lex Tutorial"

From MKWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[File:Compilation phases.png|thumb|Phases of Compilation]]
 
[[File:Compilation phases.png|thumb|Phases of Compilation]]
[[File:Lex.png|thumb| Running Lex Programs]]
 
 
==Lex ==
 
==Lex ==
 
* Lex is a program that generates lexical analyzer. It is used with YACC parser generator.
 
* Lex is a program that generates lexical analyzer. It is used with YACC parser generator.
Line 6: Line 5:
 
* It reads the input stream and produces the source code as output through implementing the lexical analyzer in the C program.
 
* It reads the input stream and produces the source code as output through implementing the lexical analyzer in the C program.
 
===The function of Lex is as follows:===
 
===The function of Lex is as follows:===
 +
[[File:Lex.png|thumb| Running Lex Programs]]
 
* Firstly lexical analyzer creates a program '''lex.1''' in the Lex language. Then Lex compiler runs the '''lex.1''' program and produces a C program '''lex.yy.c.'''
 
* Firstly lexical analyzer creates a program '''lex.1''' in the Lex language. Then Lex compiler runs the '''lex.1''' program and produces a C program '''lex.yy.c.'''
 
* Finally C compiler runs the '''lex.yy.c''' program and produces an object program '''a.out.'''
 
* Finally C compiler runs the '''lex.yy.c''' program and produces an object program '''a.out.'''
 
* '''a.out''' is lexical analyzer that transforms an input stream into a '''sequence of tokens.'''
 
* '''a.out''' is lexical analyzer that transforms an input stream into a '''sequence of tokens.'''

Revision as of 00:43, 10 August 2020

Phases of Compilation

Lex

  • Lex is a program that generates lexical analyzer. It is used with YACC parser generator.
  • The lexical analyzer is a program that transforms an input stream into a sequence of tokens.
  • It reads the input stream and produces the source code as output through implementing the lexical analyzer in the C program.

The function of Lex is as follows:

Running Lex Programs
  • Firstly lexical analyzer creates a program lex.1 in the Lex language. Then Lex compiler runs the lex.1 program and produces a C program lex.yy.c.
  • Finally C compiler runs the lex.yy.c program and produces an object program a.out.
  • a.out is lexical analyzer that transforms an input stream into a sequence of tokens.