depager 0.2.3 → 0.3.0.b20250423
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.rubocop.yml +44 -0
 - data/.simplecov +5 -0
 - data/Gemfile +12 -0
 - data/LICENSE.gpl +339 -0
 - data/Manifest.txt +73 -0
 - data/README.en +7 -21
 - data/README.ja +19 -99
 - data/Rakefile +31 -0
 - data/bin/depager +7 -45
 - data/examples/action_pl0d/pl0d.action.dr +421 -0
 - data/examples/action_pl0d/test.pl0ds +48 -0
 - data/examples/c89/c89.dr +493 -496
 - data/examples/c89/test.c89 +10 -10
 - data/examples/extension/astdf.rb +9 -0
 - data/examples/extension/atree.dr +55 -0
 - data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
 - data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
 - data/examples/extension/paction.dr +16 -15
 - data/examples/extension/pactiontest.dr +14 -14
 - data/examples/extension/simple_action.rb +46 -0
 - data/examples/pl0d/pl0ds.dr +337 -334
 - data/examples/pl0d/test.pl0ds +33 -33
 - data/examples/rie_calc/calc.rie.dr +57 -0
 - data/examples/rie_calc/test.calc +4 -0
 - data/examples/rie_dcuse/dcuse.rie.dr +71 -0
 - data/examples/rie_dcuse/test.dcuse +1 -0
 - data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
 - data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
 - data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
 - data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
 - data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
 - data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
 - data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
 - data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
 - data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
 - data/examples/rie_pl0/pl0.rie.dr +450 -0
 - data/examples/rie_pl0/test.pl0 +10 -0
 - data/examples/slex_test/divreg.slex.dr +29 -29
 - data/examples/slex_test/ljoin.slex.dr +36 -36
 - data/examples/slex_test/test.divreg +1 -1
 - data/examples/slex_test/test.ljoin +3 -3
 - data/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
 - data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
 - data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
 - data/examples/tiny_calc/calc.cst.dr +50 -0
 - data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
 - data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
 - data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
 - data/lib/depager/cli.rb +44 -0
 - data/lib/depager/grammar.rb +253 -291
 - data/lib/depager/lr.rb +589 -579
 - data/lib/depager/parser.rb +269 -277
 - data/lib/depager/plugins/_rie_debug.rb +63 -0
 - data/lib/depager/plugins/action.rb +47 -0
 - data/lib/depager/plugins/ast.dr +367 -0
 - data/lib/depager/plugins/ast.rb +1329 -0
 - data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
 - data/lib/depager/plugins/cst.rb +591 -0
 - data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
 - data/lib/depager/plugins/lex.rb +313 -0
 - data/lib/depager/plugins/rie.dr +725 -0
 - data/lib/depager/plugins/rie.rb +1614 -0
 - data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
 - data/lib/depager/plugins/slex.rb +769 -0
 - data/lib/depager/plugins/srp.rb +46 -0
 - data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
 - data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
 - data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
 - data/lib/depager/utils.rb +158 -318
 - data/lib/depager/version.rb +3 -3
 - data/lib/depager.rb +572 -670
 - metadata +77 -80
 - data/ChangeLog +0 -16
 - data/data/depager/pre-setup.rb +0 -3
 - data/examples/c89/c89.tab.rb +0 -7127
 - data/examples/pl0d/pl0ds.tab.rb +0 -2698
 - data/examples/sample_calc/calc.action.tab.rb +0 -457
 - data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
 - data/examples/sample_calc/calc.ast.tab.rb +0 -665
 - data/examples/sample_calc/calc.astdf.dr +0 -54
 - data/examples/sample_calc/calc.astdf.tab.rb +0 -672
 - data/examples/sample_calc/calc.atree.tab.rb +0 -451
 - data/examples/sample_calc/calc.cst.dr +0 -45
 - data/examples/sample_calc/calc.cst.tab.rb +0 -644
 - data/examples/sample_calc/calc.lex.tab.rb +0 -374
 - data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
 - data/examples/sample_calc/calc.tab.rb +0 -365
 - data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
 - data/examples/slex_test/divreg.slex.tab.rb +0 -303
 - data/examples/slex_test/ljoin.slex.tab.rb +0 -370
 - data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
 - data/lib/depager/ruby/plugins/action.rb +0 -43
 - data/lib/depager/ruby/plugins/ast.dr +0 -269
 - data/lib/depager/ruby/plugins/ast.rb +0 -1308
 - data/lib/depager/ruby/plugins/astdf.rb +0 -6
 - data/lib/depager/ruby/plugins/atree.dr +0 -55
 - data/lib/depager/ruby/plugins/atree.rb +0 -347
 - data/lib/depager/ruby/plugins/cst.rb +0 -626
 - data/lib/depager/ruby/plugins/lex.rb +0 -336
 - data/lib/depager/ruby/plugins/nvaction.rb +0 -19
 - data/lib/depager/ruby/plugins/slex.rb +0 -817
 - data/lib/depager/ruby/plugins/srp.rb +0 -51
 - data/lib/depager/ruby/templates/simple.erb +0 -23
 - data/setup.rb +0 -1585
 - /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
 
    
        data/examples/pl0d/test.pl0ds
    CHANGED
    
    | 
         @@ -1,34 +1,34 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            const m = 7, n = 85;
         
     | 
| 
       2 
     | 
    
         
            -
            var x,y;
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            function puts10(x)
         
     | 
| 
       5 
     | 
    
         
            -
                var i;
         
     | 
| 
       6 
     | 
    
         
            -
            begin
         
     | 
| 
       7 
     | 
    
         
            -
                i := 0;
         
     | 
| 
       8 
     | 
    
         
            -
                while i < 10 do
         
     | 
| 
       9 
     | 
    
         
            -
                  begin
         
     | 
| 
       10 
     | 
    
         
            -
                    write x; writeln;
         
     | 
| 
       11 
     | 
    
         
            -
                    i := i + 1;
         
     | 
| 
       12 
     | 
    
         
            -
                  end;
         
     | 
| 
       13 
     | 
    
         
            -
                return i
         
     | 
| 
       14 
     | 
    
         
            -
            end;
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            function fact(x)
         
     | 
| 
       17 
     | 
    
         
            -
            begin
         
     | 
| 
       18 
     | 
    
         
            -
                write x; writeln;
         
     | 
| 
       19 
     | 
    
         
            -
                if x =  
     | 
| 
       20 
     | 
    
         
            -
                return x * fact(x - 1);
         
     | 
| 
       21 
     | 
    
         
            -
            end;
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            begin
         
     | 
| 
       24 
     | 
    
         
            -
                x := m; y := n;
         
     | 
| 
       25 
     | 
    
         
            -
                write x; write y; writeln;
         
     | 
| 
       26 
     | 
    
         
            -
                x := 84; y := 36; 
     | 
| 
       27 
     | 
    
         
            -
                write x; write y; writeln;
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                y := puts10(5);
         
     | 
| 
       30 
     | 
    
         
            -
                write y; writeln;
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                y := fact(5);
         
     | 
| 
       33 
     | 
    
         
            -
                write y; writeln;
         
     | 
| 
      
 1 
     | 
    
         
            +
            const m = 7, n = 85;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var x,y;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            function puts10(x)
         
     | 
| 
      
 5 
     | 
    
         
            +
                var i;
         
     | 
| 
      
 6 
     | 
    
         
            +
            begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                i := 0;
         
     | 
| 
      
 8 
     | 
    
         
            +
                while i < 10 do
         
     | 
| 
      
 9 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                    write x; writeln;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    i := i + 1;
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end;
         
     | 
| 
      
 13 
     | 
    
         
            +
                return i
         
     | 
| 
      
 14 
     | 
    
         
            +
            end;
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            function fact(x)
         
     | 
| 
      
 17 
     | 
    
         
            +
            begin
         
     | 
| 
      
 18 
     | 
    
         
            +
                write x; writeln;
         
     | 
| 
      
 19 
     | 
    
         
            +
                if x = 0 then return 1;
         
     | 
| 
      
 20 
     | 
    
         
            +
                return x * fact(x - 1);
         
     | 
| 
      
 21 
     | 
    
         
            +
            end;
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            begin
         
     | 
| 
      
 24 
     | 
    
         
            +
                x := m; y := n;
         
     | 
| 
      
 25 
     | 
    
         
            +
                write x; write y; writeln;
         
     | 
| 
      
 26 
     | 
    
         
            +
                x := 84; y := 36;
         
     | 
| 
      
 27 
     | 
    
         
            +
                write x; write y; writeln;
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                y := puts10(5);
         
     | 
| 
      
 30 
     | 
    
         
            +
                write y; writeln;
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                y := fact(5);
         
     | 
| 
      
 33 
     | 
    
         
            +
                write y; writeln;
         
     | 
| 
       34 
34 
     | 
    
         
             
            end.
         
     | 
| 
         @@ -0,0 +1,57 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            %class TinyCalc::Parser
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Depager::Rie ('depager/plugins/rie.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 5 
     | 
    
         
            +
            %decorate @Rie
         
     | 
| 
      
 6 
     | 
    
         
            +
            %%
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 9 
     | 
    
         
            +
              /\s+/, /\#.*/ { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              /[A-Za-z]\w*/ { yield token(:ID, $&) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              /\d+/         { yield token(:NUMBER, $&.to_i) }
         
     | 
| 
      
 12 
     | 
    
         
            +
              /./           { yield token($&, $&) }
         
     | 
| 
      
 13 
     | 
    
         
            +
            %}
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 16 
     | 
    
         
            +
              program:
         
     | 
| 
      
 17 
     | 
    
         
            +
                  vardecl_list expr
         
     | 
| 
      
 18 
     | 
    
         
            +
                  {
         
     | 
| 
      
 19 
     | 
    
         
            +
                    %thread env
         
     | 
| 
      
 20 
     | 
    
         
            +
                    %except vardecl_list._env = { }
         
     | 
| 
      
 21 
     | 
    
         
            +
                    printf "vars:%s\nresult:%s\n", expr._env.inspect, expr.value
         
     | 
| 
      
 22 
     | 
    
         
            +
                  }
         
     | 
| 
      
 23 
     | 
    
         
            +
              ;
         
     | 
| 
      
 24 
     | 
    
         
            +
              vardecl_list [ _env:eq, env ] :
         
     | 
| 
      
 25 
     | 
    
         
            +
                                       { %thread env }
         
     | 
| 
      
 26 
     | 
    
         
            +
                | vardecl_list vardecl { %thread env }
         
     | 
| 
      
 27 
     | 
    
         
            +
              ;
         
     | 
| 
      
 28 
     | 
    
         
            +
              vardecl [ _env:eq, env] :
         
     | 
| 
      
 29 
     | 
    
         
            +
                  ID '=' expr ';'
         
     | 
| 
      
 30 
     | 
    
         
            +
                  {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    expr._env = $._env
         
     | 
| 
      
 32 
     | 
    
         
            +
                    $.env = $._env.merge({ ID.value => expr.value })
         
     | 
| 
      
 33 
     | 
    
         
            +
                    $._env[ ID.value ] and printf "'%s' redefined.\n", ID.value
         
     | 
| 
      
 34 
     | 
    
         
            +
                  }
         
     | 
| 
      
 35 
     | 
    
         
            +
              ;
         
     | 
| 
      
 36 
     | 
    
         
            +
              expr [ _env:eq, value ] :
         
     | 
| 
      
 37 
     | 
    
         
            +
                  expr '+' term   { %transfer _env ; $.value = expr.value + term.value }
         
     | 
| 
      
 38 
     | 
    
         
            +
                | expr '-' term   { %transfer _env ; $.value = expr.value - term.value }
         
     | 
| 
      
 39 
     | 
    
         
            +
                | term            { %transfer _env, value }
         
     | 
| 
      
 40 
     | 
    
         
            +
              ;
         
     | 
| 
      
 41 
     | 
    
         
            +
              term [ _env:eq, value ] :
         
     | 
| 
      
 42 
     | 
    
         
            +
                  term '*' fact   { %transfer _env ; $.value = term.value * fact.value }
         
     | 
| 
      
 43 
     | 
    
         
            +
                | term '/' fact   { %transfer _env ; $.value = term.value / fact.value }
         
     | 
| 
      
 44 
     | 
    
         
            +
                | fact            { %transfer _env, value }
         
     | 
| 
      
 45 
     | 
    
         
            +
              ;
         
     | 
| 
      
 46 
     | 
    
         
            +
              fact [ _env:eq, value ] :
         
     | 
| 
      
 47 
     | 
    
         
            +
                  ID
         
     | 
| 
      
 48 
     | 
    
         
            +
                  {
         
     | 
| 
      
 49 
     | 
    
         
            +
                    $.value = $._env[ ID.value ] || 0
         
     | 
| 
      
 50 
     | 
    
         
            +
                    $._env[ ID.value ] or printf "'%s' undefined.\n", ID.value
         
     | 
| 
      
 51 
     | 
    
         
            +
                  }
         
     | 
| 
      
 52 
     | 
    
         
            +
                | NUMBER          { $.value = NUMBER.value }
         
     | 
| 
      
 53 
     | 
    
         
            +
              ;
         
     | 
| 
      
 54 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 55 
     | 
    
         
            +
            %%
         
     | 
| 
      
 56 
     | 
    
         
            +
            parser = TinyCalc.create_decorated_parser
         
     | 
| 
      
 57 
     | 
    
         
            +
            r, = parser.parse(ARGF)
         
     | 
| 
         @@ -0,0 +1,71 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            %class DcUse::Parser
         
     | 
| 
      
 2 
     | 
    
         
            +
            %extend Depager::Lexer ('depager/plugins/lex.rb')
         
     | 
| 
      
 3 
     | 
    
         
            +
            %extend Depager::Rie ('depager/plugins/rie.rb')
         
     | 
| 
      
 4 
     | 
    
         
            +
            #%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
         
     | 
| 
      
 5 
     | 
    
         
            +
            %decorate @Rie
         
     | 
| 
      
 6 
     | 
    
         
            +
            %%
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            %LEX{
         
     | 
| 
      
 9 
     | 
    
         
            +
              /\s+/, /\#.*/  { }
         
     | 
| 
      
 10 
     | 
    
         
            +
              /use/          { yield token(:USE) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              /dcl /         { yield token(:DCL) }
         
     | 
| 
      
 12 
     | 
    
         
            +
              /[A-Za-z_]\w*/ { yield token(:ID, $&) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              /./            { yield token($&, $&) }
         
     | 
| 
      
 14 
     | 
    
         
            +
            %}
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            #begin-rule
         
     | 
| 
      
 17 
     | 
    
         
            +
              program:
         
     | 
| 
      
 18 
     | 
    
         
            +
                  dclist stlist
         
     | 
| 
      
 19 
     | 
    
         
            +
                  { stlist._env = dclist.env }
         
     | 
| 
      
 20 
     | 
    
         
            +
              ;
         
     | 
| 
      
 21 
     | 
    
         
            +
              dclist [ env ] :
         
     | 
| 
      
 22 
     | 
    
         
            +
                    dc
         
     | 
| 
      
 23 
     | 
    
         
            +
                  { $.env = newenv([ dc.name ]) }
         
     | 
| 
      
 24 
     | 
    
         
            +
                | dclist dc
         
     | 
| 
      
 25 
     | 
    
         
            +
                  {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    $.env = dclist.env | [ dc.name ]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    not dclist.env.include? dc.name or
         
     | 
| 
      
 28 
     | 
    
         
            +
                    message "redeclaration '%s'.\n", dc.name
         
     | 
| 
      
 29 
     | 
    
         
            +
                  }
         
     | 
| 
      
 30 
     | 
    
         
            +
                ;
         
     | 
| 
      
 31 
     | 
    
         
            +
              dc [ name ] :
         
     | 
| 
      
 32 
     | 
    
         
            +
                  DCL ID ';'
         
     | 
| 
      
 33 
     | 
    
         
            +
                  { $.name = ID.value }
         
     | 
| 
      
 34 
     | 
    
         
            +
              ;
         
     | 
| 
      
 35 
     | 
    
         
            +
              stlist [ _env ] :
         
     | 
| 
      
 36 
     | 
    
         
            +
                    stlist st
         
     | 
| 
      
 37 
     | 
    
         
            +
                  { %transfer _env }
         
     | 
| 
      
 38 
     | 
    
         
            +
                | st
         
     | 
| 
      
 39 
     | 
    
         
            +
                  { %transfer _env }
         
     | 
| 
      
 40 
     | 
    
         
            +
              ;
         
     | 
| 
      
 41 
     | 
    
         
            +
              st [ _env ] :
         
     | 
| 
      
 42 
     | 
    
         
            +
                  USE ID ';'
         
     | 
| 
      
 43 
     | 
    
         
            +
                  {
         
     | 
| 
      
 44 
     | 
    
         
            +
                    $._env.include? ID.value or
         
     | 
| 
      
 45 
     | 
    
         
            +
                    message "not declared '%s'.\n", ID.value
         
     | 
| 
      
 46 
     | 
    
         
            +
                  }
         
     | 
| 
      
 47 
     | 
    
         
            +
              ;
         
     | 
| 
      
 48 
     | 
    
         
            +
            #end-rule
         
     | 
| 
      
 49 
     | 
    
         
            +
            %%
         
     | 
| 
      
 50 
     | 
    
         
            +
            class DcUseEnv
         
     | 
| 
      
 51 
     | 
    
         
            +
              def initialize ary
         
     | 
| 
      
 52 
     | 
    
         
            +
                @ary = ary
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
              def | ary
         
     | 
| 
      
 55 
     | 
    
         
            +
                DcUseEnv.new(@ary | ary)
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
              def include? i
         
     | 
| 
      
 58 
     | 
    
         
            +
                @ary.include? i
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
              def inspect
         
     | 
| 
      
 61 
     | 
    
         
            +
                "{#{@ary.inspect}}"
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
      
 64 
     | 
    
         
            +
            def newenv *args
         
     | 
| 
      
 65 
     | 
    
         
            +
              DcUseEnv.new(*args)
         
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
| 
      
 67 
     | 
    
         
            +
            def message *args
         
     | 
| 
      
 68 
     | 
    
         
            +
              printf(*args)
         
     | 
| 
      
 69 
     | 
    
         
            +
            end
         
     | 
| 
      
 70 
     | 
    
         
            +
            parser = DcUse.create_decorated_parser
         
     | 
| 
      
 71 
     | 
    
         
            +
            r, = parser.parse(ARGF)
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            dcl a; dcl b; use a; use b;
         
     | 
| 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const   m=7, n=85
         
     | 
| 
      
 2 
     | 
    
         
            +
            var     x,y,z,q,r ;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            procedure multiply ;
         
     | 
| 
      
 5 
     | 
    
         
            +
                    var a,b
         
     | 
| 
      
 6 
     | 
    
         
            +
            begin   a := u ; b := y ; z := 0
         
     | 
| 
      
 7 
     | 
    
         
            +
                    while b > 0 do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 9 
     | 
    
         
            +
                            if odd b do z := z + a ;
         
     | 
| 
      
 10 
     | 
    
         
            +
                            a := 2a ; b := b/2 ;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            procedure divide
         
     | 
| 
      
 15 
     | 
    
         
            +
                    var w ;
         
     | 
| 
      
 16 
     | 
    
         
            +
                    const two = 2, three := 3;
         
     | 
| 
      
 17 
     | 
    
         
            +
            begin r = x ; q := 0 ; w := y ;
         
     | 
| 
      
 18 
     | 
    
         
            +
                    while w <= r do w := two*w ;
         
     | 
| 
      
 19 
     | 
    
         
            +
                    while w >  y
         
     | 
| 
      
 20 
     | 
    
         
            +
                            begin q := ( 2*q ; w := w/2 ) ;
         
     | 
| 
      
 21 
     | 
    
         
            +
                                    if w <= r then
         
     | 
| 
      
 22 
     | 
    
         
            +
                                            begin r:= r-w   q := q + 1
         
     | 
| 
      
 23 
     | 
    
         
            +
                                            end
         
     | 
| 
      
 24 
     | 
    
         
            +
                            end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            procedure gcd ;
         
     | 
| 
      
 28 
     | 
    
         
            +
                    var f,g ;
         
     | 
| 
      
 29 
     | 
    
         
            +
            begin f := x ; g := y 
         
     | 
| 
      
 30 
     | 
    
         
            +
                    while f <> g do
         
     | 
| 
      
 31 
     | 
    
         
            +
                            begin if f < g then g := g-f ;
         
     | 
| 
      
 32 
     | 
    
         
            +
                                  if g < f then f := f-g ;
         
     | 
| 
      
 33 
     | 
    
         
            +
                    z := f 
         
     | 
| 
      
 34 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            begin
         
     | 
| 
      
 37 
     | 
    
         
            +
                    x :=  m ; y :=  n ; call multiply ;
         
     | 
| 
      
 38 
     | 
    
         
            +
                    x := 25 ; y :=  3 ; call divide ;
         
     | 
| 
      
 39 
     | 
    
         
            +
                    x := 84 ; y := 36 ; call gcd ;
         
     | 
| 
      
 40 
     | 
    
         
            +
                    call x ;  x:= gcd ; gcd = x
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const m=7,n=85;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var x,y,z;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 5 
     | 
    
         
            +
                var a,b;
         
     | 
| 
      
 6 
     | 
    
         
            +
                begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                  a:=u; b=y; z:=0;
         
     | 
| 
      
 8 
     | 
    
         
            +
                  while b>0 do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                      if odd b then z:=z+a;
         
     | 
| 
      
 11 
     | 
    
         
            +
                      a:=2*a; b:=b/2;
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end;
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            begin
         
     | 
| 
      
 16 
     | 
    
         
            +
              x:=m; y:=n; call multiply;
         
     | 
| 
      
 17 
     | 
    
         
            +
              call x;
         
     | 
| 
      
 18 
     | 
    
         
            +
              x:=multiply; multiply:=x
         
     | 
| 
      
 19 
     | 
    
         
            +
            end.
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const m=7,n=85,m=7;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var x,y,z,x;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 5 
     | 
    
         
            +
                 var a,b;
         
     | 
| 
      
 6 
     | 
    
         
            +
                begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                  a:=x; b:=y; z:=0;
         
     | 
| 
      
 8 
     | 
    
         
            +
                  while b>0 do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                      if odd b then z:=z+a;
         
     | 
| 
      
 11 
     | 
    
         
            +
                      a:=2048*a; b:=b/2;
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end;
         
     | 
| 
      
 14 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            begin
         
     | 
| 
      
 17 
     | 
    
         
            +
              x:=m; y:=n; call multiply;
         
     | 
| 
      
 18 
     | 
    
         
            +
              call x;
         
     | 
| 
      
 19 
     | 
    
         
            +
              x:=multiply; multiply:=x
         
     | 
| 
      
 20 
     | 
    
         
            +
            end.
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const m=7,n=85;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var x,y,z;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 5 
     | 
    
         
            +
                var a,b;
         
     | 
| 
      
 6 
     | 
    
         
            +
                begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                  a:=x; b:=y; z:=0;
         
     | 
| 
      
 8 
     | 
    
         
            +
                  while b>0 do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                      if odd b then z:=z+a;
         
     | 
| 
      
 11 
     | 
    
         
            +
                      a:=2*a; b:=b/2;
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end;
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            begin
         
     | 
| 
      
 16 
     | 
    
         
            +
              @x := 0 ; x:=m; y:=n; call multiply;
         
     | 
| 
      
 17 
     | 
    
         
            +
              !write(x); writeln(y); writeln(z)
         
     | 
| 
      
 18 
     | 
    
         
            +
            end.
         
     | 
| 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const   m=7, n=85 ;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var     x,y,z,q,r ;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            procedure multiply ;
         
     | 
| 
      
 5 
     | 
    
         
            +
                    var a,b ;
         
     | 
| 
      
 6 
     | 
    
         
            +
            begin   a := x ; b := y ; z := 0 ;
         
     | 
| 
      
 7 
     | 
    
         
            +
                    while b > 0 do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 9 
     | 
    
         
            +
                            if odd b then z := z + a ;
         
     | 
| 
      
 10 
     | 
    
         
            +
                            a := 2*a ; b := b/2 ;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            procedure divide ;
         
     | 
| 
      
 15 
     | 
    
         
            +
                    var w ;
         
     | 
| 
      
 16 
     | 
    
         
            +
            begin r := x ; q := 0 ; w := y ;
         
     | 
| 
      
 17 
     | 
    
         
            +
                    while w <= r do w := 2*w ;
         
     | 
| 
      
 18 
     | 
    
         
            +
                    while w >  y do
         
     | 
| 
      
 19 
     | 
    
         
            +
                            begin q := 2*q ; w := w/2 ;
         
     | 
| 
      
 20 
     | 
    
         
            +
                                    if w <= r then
         
     | 
| 
      
 21 
     | 
    
         
            +
                                            begin r:= r-w ; q := q + 1
         
     | 
| 
      
 22 
     | 
    
         
            +
                                            end
         
     | 
| 
      
 23 
     | 
    
         
            +
                            end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            procedure gcd ;
         
     | 
| 
      
 27 
     | 
    
         
            +
                    var f,g ;
         
     | 
| 
      
 28 
     | 
    
         
            +
            begin f := x ; g := y ;
         
     | 
| 
      
 29 
     | 
    
         
            +
                    while f <> g do
         
     | 
| 
      
 30 
     | 
    
         
            +
                            begin if f < g then g := g-f ;
         
     | 
| 
      
 31 
     | 
    
         
            +
                                  if g < f then f := f-g ;
         
     | 
| 
      
 32 
     | 
    
         
            +
                            end ;
         
     | 
| 
      
 33 
     | 
    
         
            +
                    z := f
         
     | 
| 
      
 34 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            begin
         
     | 
| 
      
 37 
     | 
    
         
            +
                    x :=  m ; y :=  n ; call multiply ;
         
     | 
| 
      
 38 
     | 
    
         
            +
                    x := 25 ; y :=  3 ; call divide ;
         
     | 
| 
      
 39 
     | 
    
         
            +
                    x := 84 ; y := 36 ; call gcd ;
         
     | 
| 
      
 40 
     | 
    
         
            +
            end .
         
     | 
| 
         @@ -0,0 +1,43 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const   m=7, n=85 ;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var     x,y,z,q,r ;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            procedure multiply ;
         
     | 
| 
      
 5 
     | 
    
         
            +
                    var a,b ;
         
     | 
| 
      
 6 
     | 
    
         
            +
            begin   a := x ; b := y ; z := 0 ;
         
     | 
| 
      
 7 
     | 
    
         
            +
                    while b > 0 do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 9 
     | 
    
         
            +
                            if odd b then z := z + a ;
         
     | 
| 
      
 10 
     | 
    
         
            +
                            a := 2*a ; b := b/2 ;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            procedure divide ;
         
     | 
| 
      
 15 
     | 
    
         
            +
                    var w ;
         
     | 
| 
      
 16 
     | 
    
         
            +
            begin r := x ; q := 0 ; w := y ;
         
     | 
| 
      
 17 
     | 
    
         
            +
                    while w <= r do w := 2*w ;
         
     | 
| 
      
 18 
     | 
    
         
            +
                    while w >  y do
         
     | 
| 
      
 19 
     | 
    
         
            +
                            begin q := 2*q ; w := w/2 ;
         
     | 
| 
      
 20 
     | 
    
         
            +
                                    if w <= r then
         
     | 
| 
      
 21 
     | 
    
         
            +
                                            begin r:= r-w ; q := q + 1
         
     | 
| 
      
 22 
     | 
    
         
            +
                                            end
         
     | 
| 
      
 23 
     | 
    
         
            +
                            end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            procedure gcd ;
         
     | 
| 
      
 27 
     | 
    
         
            +
                    var f,g ;
         
     | 
| 
      
 28 
     | 
    
         
            +
            begin f := x ; g := y ;
         
     | 
| 
      
 29 
     | 
    
         
            +
                    while f <> g do
         
     | 
| 
      
 30 
     | 
    
         
            +
                            begin if f < g then g := g-f ;
         
     | 
| 
      
 31 
     | 
    
         
            +
                                  if g < f then f := f-g ;
         
     | 
| 
      
 32 
     | 
    
         
            +
                            end ;
         
     | 
| 
      
 33 
     | 
    
         
            +
                    z := f
         
     | 
| 
      
 34 
     | 
    
         
            +
            end ;
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            begin
         
     | 
| 
      
 37 
     | 
    
         
            +
                    x :=  m ; y :=  n ; call multiply ; 
         
     | 
| 
      
 38 
     | 
    
         
            +
                    write(x) ; write(y) ; write(z) ; writeln ;
         
     | 
| 
      
 39 
     | 
    
         
            +
                    x := 25 ; y :=  3 ; call divide ; 
         
     | 
| 
      
 40 
     | 
    
         
            +
                    write(x) ; write(y) ; write(q) ; write(r) ; writeln ;
         
     | 
| 
      
 41 
     | 
    
         
            +
                    x := 84 ; y := 36 ; call gcd ; 
         
     | 
| 
      
 42 
     | 
    
         
            +
                    write(x) ; write(y) ; write(z) ; writeln 
         
     | 
| 
      
 43 
     | 
    
         
            +
            end .
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            var x,y,z;
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 4 
     | 
    
         
            +
                 var a,b;
         
     | 
| 
      
 5 
     | 
    
         
            +
                begin
         
     | 
| 
      
 6 
     | 
    
         
            +
                  a:=x; b:=y; z:=0;
         
     | 
| 
      
 7 
     | 
    
         
            +
                  while b>0 do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 9 
     | 
    
         
            +
                      if odd b then z:=z+a;
         
     | 
| 
      
 10 
     | 
    
         
            +
                      a:=2*a; b:=b/2;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                end;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            begin
         
     | 
| 
      
 15 
     | 
    
         
            +
              read(x);
         
     | 
| 
      
 16 
     | 
    
         
            +
              while x<>0 do
         
     | 
| 
      
 17 
     | 
    
         
            +
                begin
         
     | 
| 
      
 18 
     | 
    
         
            +
                  read(y); call multiply;
         
     | 
| 
      
 19 
     | 
    
         
            +
                  write( x ); write( y ); writeln( z );
         
     | 
| 
      
 20 
     | 
    
         
            +
                  read(x)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end 
         
     | 
| 
      
 22 
     | 
    
         
            +
            end.
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const m=7,n=85;
         
     | 
| 
      
 2 
     | 
    
         
            +
            var x,y,z;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              procedure multiply;
         
     | 
| 
      
 5 
     | 
    
         
            +
                var a,b;
         
     | 
| 
      
 6 
     | 
    
         
            +
                begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                  a:=x; b:=y; z:=0;
         
     | 
| 
      
 8 
     | 
    
         
            +
                  while b>0 do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                      if odd b then z:=z+a;
         
     | 
| 
      
 11 
     | 
    
         
            +
                      a:=2*a; b:=b/2;
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end;
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            begin
         
     | 
| 
      
 16 
     | 
    
         
            +
              x:=m; y:=n; call multiply;
         
     | 
| 
      
 17 
     | 
    
         
            +
              write(x); writeln(y); writeln(z)
         
     | 
| 
      
 18 
     | 
    
         
            +
            end.
         
     |