lexyacctutorial内容摘要:
User Subroutines Section • You can use your Lex routines in the same ways you use routines in other programming languages. %{ void foo()。 %} letter [azAZ] %% {letter}+ foo()。 %% … void foo() { … } PLLab, NTHU,Cs2403 Programming Languages 28 User Subroutines Section (cont‟d) • The section where main() is placed %{ int counter = 0。 %} letter [azAZ] %% {letter}+ {printf(“a word\n”)。 counter++。 } %% main() { yylex()。 printf(“There are total %d words\n”, counter)。 } PLLab, NTHU,Cs2403 Programming Languages 29 Usage • To run Lex on a source file, type lex • It produces a file named which is a C program for the lexical analyzer. • To pile , type cc –ll • To run the lexical analyzer program, type ./ inputfile PLLab, NTHU,Cs2403 Programming Languages 30 Versions of Lex • ATamp。 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。 =39。 expression | expression { printf(= %d\n, $1)。 }。 expression: expression 39。 +39。 NUMBER { $$ = $1 + $3。 } | expression 39。 39。 NUMBER { $$ = $1 $3。 } | NUMBER { $$ = $1。 }。 %%int yyerror(char *s){ fprintf(stderr, %s\n, s)。 return 0。 }int main(void){ yyparse()。 return 0。 }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。 +39。 term | term。 term : term 39。 *39。 factor | factor。 factor : 39。 (39。 expr 39。 )39。 | ID | NUM。 PLLab, NTHU,Cs2403 Programming Languages 42 Rules Section • Normally written like this • Example: expr : expr 39。 +39。 term | term。 term。lexyacctutorial
相关推荐
主要语言搜索。 12 新闻检索可按照不同类型资源限定检索类型 13 地区新闻可以按照国家名称和世界区域查找 14 支持其他语种新闻检索 15 检索大学院校新闻 连接词选择 AND OR AND NOT W/5 W/S W/P 16 搜索结果及文档全文 ,关键词以红色字体显示 17 法律 法律收录美国、英国、加拿大、香港等国家和地区的案例、法规以及评论等,完整覆盖美国联邦和州法院,超过
:使用汇编或特权指令 • 使用 rdtsc指令获取 CPU主频计数器 unsigned long low, high。 asm (rdtsc : =a (low), =d (high))。 printf(rdtsc=%lu,%lu\n, high, low)。 • 使用 IO指令 –在用户空间不能执行 in/out指令,在内核里可以 • “segmentation fault” –尝试在模块里用
启动安装程序 光盘启动 在 BIOS启动搜索顺序里把光盘设为第一位 把安装光盘装进光驱 出现 boot:提示符时按回车键 软盘启动 在 BIOS启动搜索顺序里把软盘设为第一位 把启动软盘装进软驱 出现 boot:提示符时按回车键 无软驱、无光驱的启动方法 如果硬盘上安装了 Win98 从第一张光盘的 iso文件中解出 autoboot目录 启到
is Mr. Liu. What is her/his name? She is Zhang Manyu. She is Ms. Zhang. He is Liu Dehua. He is Mr. Liu. Titles (称呼用语) • He is Mr. Xie. • 他是谢先生。 • She is Mrs. Xie. • 她是谢太太。 • She is Miss Zhao. • 她是赵小姐
♣开关置 1,快速加电流 IM,测量正向 电压 VFf。 ♣ ΔVF=│ VFi VFf│ ΔTi =K ΔVF TJ=TJi+ ΔTi 这里 TJi是测量开始前 LED结温 的初始温度。 mvC/mvC /LED结温测量的电流电压波形 选择至关重要。 除取典型值 ,安外,可取伏安特性的击穿点。 MI热阻测试波形 校准测量数据的冷却曲线 HH FJX VI VK
• 2020 according to statistics Hasee puter products sales of the year nearly 100 million units, ranking second in China39。 s domestic brands。 • 2020 fullyear sales of 1 million units. • 2020 fullyear