Feb13 - CSE302: Compiler Design Instructor: Dr. Liang Cheng...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 13, 2007 Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Outline Recap The lexical-analyzer generator Lex Implementing lexical-analyzer generators Summary and homework Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Overview of Flex Flex is a scanner generator Input is description of patterns and actions Output is a C program which contains a function yylex() which when called matches patterns and performs actions per input Execute the unix command man flex for full information Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Overview of Flex Compile using Flex tool Results in C code Compile using C compiler Link to the flex library (-lfl) Run the executable and recognize tokens Lex compiler Lex source program: lex.l lex.yy.c C compiler lex.yy.c a.out a.out Input stream sequence of tokens Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Flex Source Program Format %{ declarations %} regular definitions %% translation rules %% auxiliary procedures/functions Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Commands flex <prog_name>.l On CSE Department Suns, flex is in /usr/sfw/bin/flex gcc o sample lex.yy.c -lfl sample < input.text flex generates a main routine that is not needed when parsing with Yacc-generated parser Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Some Functions and Variables yylex() The primary function generated input() Returns the next char from the input unput(int c) Returns char c to input yylval // Used to pass values to parser yytext // String with token from input yyleng // Length of string yyin // File handle yyin = fopen(args[0], r) Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Regular Expressions For Tokens ws ( blank | tab | newline )+ Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/13/07 Example Lex Source Programs %{ /* definitions of constants LT , LE , EQ , NE , GT ,...
View Full Document

This note was uploaded on 08/06/2008 for the course CSE 302 taught by Professor Cheng during the Spring '07 term at Lehigh University .

Page1 / 28

Feb13 - CSE302: Compiler Design Instructor: Dr. Liang Cheng...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online