⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ll1_table2.t.svn-base

📁 这是一个DFA简化和生成LL(1)分析表的程序,自动生成表格及图形
💻 SVN-BASE
字号:
# LL1_table2.t# Test the LL1_table subuse Test::Base;use LL1_table;use t::Util qw/ parse_grammar dump_LL1_table /;plan tests => 1 * blocks();$::LL1_QUIET = 1;run {    my $block = shift;    my $name = $block->name;    my $ast = parse_grammar($block->grammar);    my $Firsts = LL1::Table::first_sets($ast);    my $Follows = LL1::Table::follow_sets($ast, $Firsts);    my $table = LL1::Table::LL1_table($ast, $Firsts, $Follows);    my $got = dump_LL1_table($table);    is $got, $block->LL1_table, $name;};__DATA__=== TEST 1: strings of balanced parentheses--- grammarS: '(' S ')' S | ''--- LL1_tableS  $: S ->  '(': S -> '(' S ')' S  ')': S ->=== TEST 2: if_statements--- grammarstatement: if_stmt | 'other'if_stmt: 'if' '(' exp ')' statement else_partelse_part: 'else' statement |exp: '0' | '1'--- LL1_tableelse_part  $: else_part ->  'else': else_part -> 'else' statementexp  '0': exp -> '0'  '1': exp -> '1'if_stmt  'if': if_stmt -> 'if' '(' exp ')' statement else_partstatement  'if': statement -> if_stmt  'other': statement -> 'other'=== TEST 3: simple integer expression (w/o left recursion)--- grammarexp: term exp_exp_: addop term exp_ | ''addop: '+' | '-'term: factor term_term_: mulop factor term_ | ''mulop: '*'factor: '(' exp ')' | /\d+/--- LL1_tableaddop  '+': addop -> '+'  '-': addop -> '-'exp  '(': exp -> term exp_  /\d+/: exp -> term exp_exp_  $: exp_ ->  ')': exp_ ->  '+': exp_ -> addop term exp_  '-': exp_ -> addop term exp_factor  '(': factor -> '(' exp ')'  /\d+/: factor -> /\d+/mulop  '*': mulop -> '*'term  '(': term -> factor term_  /\d+/: term -> factor term_term_  $: term_ ->  ')': term_ ->  '*': term_ -> mulop factor term_  '+': term_ ->  '-': term_ ->=== TEST 4: statement sequences--- grammarstmt_sequence: stmt stmt_seqstmt_seq: ';' stmt_sequence |stmt: 's'--- LL1_tablestmt  's': stmt -> 's'stmt_seq  $: stmt_seq ->  ';': stmt_seq -> ';' stmt_sequencestmt_sequence  's': stmt_sequence -> stmt stmt_seq

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -