HY 340 : ΓΛΩΣΣΕΣ ΚΑΙ...

Click here to load reader

  • date post

    22-Jan-2016
  • Category

    Documents

  • view

    62
  • download

    0

Embed Size (px)

description

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ, ΣΧΟΛΗ ΘΕΤΙΚΩΝ ΕΠΙΣΤΗΜΩΝ, ΤΜΗΜΑ ΕΠΙΣΤΗΜΗΣ ΥΠΟΛΟΓΙΣΤΩΝ. HY 340 : ΓΛΩΣΣΕΣ ΚΑΙ ΜΕΤΑΦΡΑΣΤΕΣ. ΔΙΔΑΣΚΩΝ Αντώνιος Σαββίδης. HY 340 : ΓΛΩΣΣΕΣ ΚΑΙ ΜΕΤΑΦΡΑΣΤΕΣ. Φροντιστήριο 1ο Εισαγωγή στο FLEX. Flex. Μια γεννήτρια λεξικογραφικών αναλυτών για τις γλώσσες C/C++ - PowerPoint PPT Presentation

Transcript of HY 340 : ΓΛΩΣΣΕΣ ΚΑΙ...

HCI & AT Lab @ ICS-FORTH

HY340 : , ,

1. HY340 : 1 FLEXSlide 2 / 26HY340, 20132. Flex C/C++ :Regular expressions, Actions, regular expression Slide 3 / 26HY340, 2013. Regular Expressions (1/4)x xabcd - abcd. () - new line[xyz] , x, y z[ab-eg] a, b e g[^ab-e] [ab-e] ( a, b, c, d, e)Slide 4 / 26HY340, 2013. Regular Expressions (2/4)r* - ra* , a, aa, aaa, r+ - ra+ a, aa, aaa, , r? - r ( r)r{i, j} - i j r( i, j > 0 i < j)r{i} i rr{i,} i rSlide 5 / 26HY340, 2013. Regular Expressions (3/4)rs r s (concatenation)(r) r ( )abc+ abc, abcc, abccc, (abc)+ abc, abcabc, r|s r s^r r r$ r \\, \, \(, \), \*, \+, \[, \], \$, \^, \{, \}, ... \, , (, *, (escaped)Slide 6 / 26HY340, 2013. Regular Expressions (4/4) !! foo|bar* (foo)|(ba(r*)) * | foo bar foo|(bar)* foo bar (foo|bar)*

Slide 7 / 26HY340, 2013. flex regular expressions [:X:] : alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit. standard C isX(int c) Slide 8 / 26HY340, 2013. Flex

%%

%%

()Slide 9 / 26HY340, 2013. - {% /*code*/ %} %top{ /*code*/ }Regular expression macros (aliases) name regex .. string \"[^\n"]*\" %option option_name %option option_name=valueUser-defined conditions Slide 10 / 26HY340, 2013. (1/2)%option header-file=./scanner.h header file %option noyywrap yywrap, ( 0 scanning )%option yylineno yylineno, %option case-insensitive case insensitive. ClaSS classSlide 11 / 26HY340, 2013. (2/2)%option reentrant reentrant ( yylex ). yylex%option prefix="PREFIX" yy . yylex, yyin, yylineno, yytext, yywrap, ... PREFIX%option nounistd 'include' header file unistd.h, UNIX Slide 12 / 26HY340, 2013. User defined conditions conditionsInclusive (start) conditions %s condition_name ( condition) Exclusive conditions %x condition_name

Slide 13 / 26HY340, 2013. regular expressionsUser defined conditions

Slide 14 / 26HY340, 2013. - , : Regular expression { action } , Slide 15 / 26HY340, 2013. - ConditionsConditions conditions conditions ( %s %x) . default , inclusive conditions default ( inclusive), INITIAL conditions INITIALSlide 16 / 26HY340, 2013. Regular Expressions & ActionsRegular ExpressionTo regular expression macros , {, }, .. {comment} Action regular expression statement {, } ( block)

Slide 17 / 26HY340, 2013. yytext: pointer char ( char array lex) regular expressionyyleng: yytextBEGIN(condition): conditionECHO: yytext .REJECT: : REJECT input(): (look-ahead)unput(c): c . cSlide 18 / 26HY340, 2013. - condition

conditionSlide 19 / 26HY340, 2013. %% , .c

:Slide 20 / 26HY340, 2013.

scanner.lSlide 21 / 26HY340, 201321. scanner.lMeta compiler (flex/lex)scanner.cC/C++ Compiler:scanner

Slide 22 / 26HY340, 201322. c strings char buffers (1/3) , global FILE* pointer yyin ( main() ) (FILE* pointers) memory buffers flex (NULL terminated char* pointers, buffers)

Slide 23 / 26HY340, 2013. c strings char buffers (2/3) handle YY_BUFFER_STATE yy_scan_string(const char* str) string str yy_scan_bytes(char* buffer, size_t size) buffer size yylex() , handle yy_delete_buffer(YY_BUFFER_STATE buffer)Slide 24 / 26HY340, 2013. c strings char buffers (3/3)

strings buffersSlide 25 / 26HY340, 2013. ReferencesFlex Home Pagehttp://www.gnu.org/software/flexFlex Manualhttp://www.gnu.org/software/flex/manual/Flex for Windowshttp://gnuwin32.sourceforge.net/packages/flex.htmSlide 26 / 26HY340, 2013