lex - Lex -- a Lexical Analyzer Generator (by M.E. Lesk and...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lex -- a Lexical Analyzer Generator (by M.E. Lesk and Eric. Schmidt) Automatically generate a routine (yylex) that recognize the tokens (and perform corresponding actions). Lex source program {definition} %% {rules} %% {user subroutines} Rules: <regular expression> <action> Each regular expression specifies a token. Default action for anything that is not matched: copy to the output Action: C/C++ source fragments specifying what to do when a token is recognized. lex program examples: ex1.l and ex2.l lex ex1.l produces the lex.yy.c file. The int yylex() routine is the scanner that finds all the regular expressions specified. yylex() returns a non-zero value (usually token id) normally. yylex() returns 0 when end of file is reached. Need a drive to test the routine. You need to have a yywrap() function in the lex file (return 1). Something to do with compiling multiple files. Lex regular expression: contains text characters and operators. Letters of alphabet and digits are always text characters....
View Full Document

Page1 / 12

lex - Lex -- a Lexical Analyzer Generator (by M.E. Lesk and...

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

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