freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

lexyacctutorial-文庫(kù)吧資料

2024-10-26 00:55本頁(yè)面
  

【正文】 39。 } | factor { $$ = $1。*39。 } 。 term { $$ = $1 + $3。 PLLab, NTHU,Cs2403 Programming Languages 43 The Position of Rules expr : expr 39。)39。(39。 factor | factor 。 term : term 39。+39。 | ID | NUM。 expr 39。 factor : 39。*39。 term | term。}PLLab, NTHU,Cs2403 Programming Languages 36 Works with Lex Y A C Cy y p a r s e ( )I n p u t p r o g r a m s12 + 26L E Xy y le x ( )How to work ? PLLab, NTHU,Cs2403 Programming Languages 37 Works with Lex Y A C Cy y p a r s e ( )I n p u t p r o g r a m s12 + 26L E Xy y le x ( )call yylex() [09]+ next token is NUM NUM ?+? NUM PLLab, NTHU,Cs2403 Programming Languages 38 YACC File Format %{ C declarations %} yacc declarations %% Grammar rules %% Additional C code – Comments enclosed in /* ... */ may appear in any of the sections. PLLab, NTHU,Cs2403 Programming Languages 39 Definitions Section %{ include include %} %token ID NUM %start expr It is a terminal 由 expr 開始 parse PLLab, NTHU,Cs2403 Programming Languages 40 Start Symbol ? The first nonterminal specified in the grammar specification section. ? To overwrite it with %start declaraction. %start nonterminal PLLab, NTHU,Cs2403 Programming Languages 41 Rules Section ? This section defines grammar ? Example expr : expr 39。}int main(void){ yyparse()。%%int yyerror(char *s){ fprintf(stderr, %s\n, s)。 } | NUMBER { $$ = $1。39。 NUMBER { $$ = $1 + $3。expression: expression 39。 expression | expression { printf(= %d\n, $1)。T lex ? GNU flex ? a Win32 version of flex : or Cygwin : ? Lex on different machines is not created equal. PLLab, NTHU,Cs2403 Programming Languages 31 Yacc Yet Another CompilerCompiler PLLab, NTHU,Cs2403 Programming Languages 32 Introduction ? What is YACC ? – Tool which will produce a parser for a given grammar. – YACC (Yet Another Compiler Compiler) is a program designed to pile a LALR(1) grammar and to produce the source code of the syntactic analyzer of the language produced by this grammar. PLLab, NTHU,Cs2403 Programming Languages 33 How YACC Works File containing desired grammar in yacc format yacc program C source program created by yacc C piler Executable program that will parse grammar given in yacc cc or gcc PLLab, NTHU,Cs2403 Programming Languages 34 yacc How YACC Works (1) Parser generation time YACC source (*.y) C piler/linker (2) Compile time (3) Run time Token stream Abstract Syntax Tree PLLab, NTHU,Cs2403 Programming Languages 35 An YACC File Example %{include %}%token NAME NUMBER%%statement: NAME 39。 printf(“There are total %d words\n”, counter)。 counter++。 %% … void foo() { … } PLLab, NTHU,Cs2403 Programming Languages 28 User Subroutines Section (cont?d) ? The section where main() is placed %{ int counter = 0。} PLLab, NTHU,Cs2403 Programming Languages 25 Lex Library Routines ? yylex() – The default main() contains a call of yylex() ? yymore() – return the next token ? yyless(n) – retain the first n characters in yytext ? yywarp() – is called whenever Lex reaches an endoffile – The default yywarp() always returns 1 PLLab, NTHU,Cs2403 Programming Languages 26 Review of Lex Predefined Variables Name Function char *yytext pointer to matched string int yyleng length of matched string FILE *yyin input stream pointer FILE *yyout output stream pointer int yylex(void) call to invoke lexer, returns token char* yymore(void) return the next token int yyless(int n) retain the first n characters in yytext in
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1