LEX Tool
Computers understand only Low level language or Machine level language. Compiler is a translator that convert the high level language into the low level language. Phases of Compiler: Compilation process contains the sequence of various phases. The structure of compiler consist of two parts: Analysis part Synthesis Part. Lexical Analysis Phase: LEX is tool which generate lexical Analyzer. Lexical analysis is the first phase of a compiler. It takes input as a source code and generate output as token. Token: In a Programming language token is a sequence of characters that can be treated as a unit. Tokens can be classified as keywords , identifier, operator, separator , number etc. Examples: Keywords: if , else , while etc. Identifier: variable name , function name etc. Operator : ‘ + ‘ , ‘ = ‘ , ‘ – ‘ etc. Separator : ‘ , ‘ , ‘ : ‘ etc. Number : 3 , 5 , 77 etc. Lexical Analysis. The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or comments in the source code. If the lexical analyzer finds a token invalid, it generates an error. Lex program divide into three part: Definition section (initialization), Rule section and Code section.
Steps to Run in ubuntu:
Install flex and YACC using command: sudo apt-get install flex byacc
Steps to compile code in ubuntu:
1. lex hello.l
2. gcc lex.yy.c
3. ./a.out
Installing Softwares:
Download Flex 2.5.4a
Download Bison 2.4.1
Download DevC++
Install Flex at “C:GnuWin32“
Install Bison at “C:GnuWin32“
Install DevC++ at “C:Dev-Cpp“
Open Environment Variables.
Add “C:GnuWin32bin;C:Dev-Cppbin;” to path.