正在加载图片...
Lex Overview Usage Paradigm of Lex Lex is a tool for creating lexical analyzers. Lex source Lex program lex.yy.c Lexical analyzers fokenize input streams. Tokens are the terminals of a language. lex.yy.c C compiler a.out Regular expressions define tokens. input a.out tokens To Use Lex and Yacc Together Lex Internals Mechanism Lex source Yacc source (Lexical Rules)(Grammar Rules) Converts regular expressions into DFAs. DFAs are implemented as table driven state machines. lex.yy.c v.tab.c call Input yylex() yyparse() ◆Parsed Input return token lex.yy.c:What it produces Running Lex dofine YYTYPE unsignod char struct yyvork YYTYPE verify,advance;yycrank.{ To run lex on a source file,use the 88 0.0, 0,0, 6888 0,0, command: g事 lex source.I yycrankct-1. 0。 yycrank+-3, 8p3: This produces the file lex.yy.c which is the yycrank+0, veet1. yyvetop+5. C source for the lexical analyzer. unaigned char yymateh{ ·To compile this,use: 898182880t ,01,01,01 8:8: cc -o prog-0 lex.yy.c-lI 4++ 11 Lex Overview • Lex is a tool for creating lexical analyzers. • Lexical analyzers tokenize input streams. • Tokens are the terminals of a language. • Regular expressions define tokens . Usage Paradigm of Lex To Use Lex and Yacc Together Lex Yacc yylex() yyparse() Lex source (Lexical Rules) Yacc source (Grammar Rules) Input Parsed Input lex.yy.c y.tab.c call return token Lex Internals Mechanism • Converts regular expressions into DFAs. • DFAs are implemented as table driven state machines. lex.yy.c : What it produces Running Lex • To run lex on a source file, use the command: lex source.l • This produces the file lex.yy.c which is the C source for the lexical analyzer. • To compile this, use: cc -o prog -O lex.yy.c -ll
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有