SlideShare a Scribd company logo
1 of 99
Download to read offline
Solving Difficult LR Parsing Conflicts by
           Postponing Them

 Luis Garcia-Forte and Casiano Rodriguez-Leon
           Universidad de La Laguna



      CoRTA2010 September 09-10, 2010
Outline



   Introduction


   Context Dependent Parsing


   Nested Parsing


   Conclusions
Outline



   Introduction


   Context Dependent Parsing


   Nested Parsing


   Conclusions
Yacc Limitations




       Yacc-like LR parser generators provide ways to solve
        shift-reduce mechanisms based on token precedence.
Yacc Limitations




       Yacc-like LR parser generators provide ways to solve
        shift-reduce mechanisms based on token precedence.
       No mechanisms are provided for the resolution of
        reduce-reduce conflicts or difficult shift-reduce conflicts.
Yacc Limitations




       Yacc-like LR parser generators provide ways to solve
        shift-reduce mechanisms based on token precedence.
       No mechanisms are provided for the resolution of
        reduce-reduce conflicts or difficult shift-reduce conflicts.
       To solve such kind of conflicts the language designer has
        to modify the grammar.
Postponed Conflict Resolution Approach
Postponed Conflict Resolution Approach




       The strategy presented here extends yacc conflict
        resolution mechanisms with new ones, supplying ways to
        resolve conflicts that can not be solved using static
        precedences.
Postponed Conflict Resolution Approach




       The strategy presented here extends yacc conflict
        resolution mechanisms with new ones, supplying ways to
        resolve conflicts that can not be solved using static
        precedences.
       The algorithm for the generation of the LR tables remains
        unchanged, but the programmer can modify the parsing
        tables during run time.
PPCR Approach: Identify the Conflict
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
             A → α↑
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
             A → α↑
              and
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
             A → α↑
              and
             B → β↑
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
             A → α↑
              and
             B → β↑
              when the lookahead token is
PPCR Approach: Identify the Conflict


       Identify the conflict: What LR(0)-items/productions and
        tokens are involved?.
       Tools must support that stage, as for example via the
        .output file generated by eyapp.
       Suppose we identify that the participants are the two
        LR(0)-items
             A → α↑
              and
             B → β↑
              when the lookahead token is
              @.
PPCR Approach: Identify the Conflict
PPCR Approach: Identify the Conflict



       The software must allow the use of symbolic labels to refer
        by name to the productions involved in the conflict.
PPCR Approach: Identify the Conflict



       The software must allow the use of symbolic labels to refer
        by name to the productions involved in the conflict.
       In Eyapp names and labels can be explicitly given using
        the directive %name, using a syntax similar to this one:


                          %name :rA A → α
                          %name :rB B → β
PPCR Approach: Identify the Conflict
PPCR Approach: Identify the Conflict



       Give a symbolic name to the conflict. In this case we
        choose isAorB as name of the conflict.
PPCR Approach: Identify the Conflict



       Give a symbolic name to the conflict. In this case we
        choose isAorB as name of the conflict.
       Inside the body section of the grammar, mark the points of
        conflict using the new reserved word %PREC followed by
        the conflict name:


                %name :rA A → α          %PREC IsAorB
                %name :rA B → β          %PREC IsAorB
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
            A → α↑
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
            A → α↑
             and
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
            A → α↑
             and
            B→β↑γ
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
            A → α↑
             and
            B → β ↑ γ for some token ’@’.
Conflict Identification: Shift-Reduce Conflicts

   The procedure is similar for shift-reduce conflicts.
      Let us assume we have identified a shift-reduce conflict
       between LR-(0) items
             A → α↑
              and
             B → β ↑ γ for some token ’@’.
       Again, we must give a symbolic name to A → α and mark
        with the new %PREC directive the places where the conflict
        occurs:


                %name :rA A → α          %PREC IsAorB
                              B →β       %PREC IsAorB    γ
PPCR Approach: The Conflict Handler
PPCR Approach: The Conflict Handler



       Introduce a %conflict directive inside the head section
        of the translation scheme to specify the way the conflict will
        be solved.
PPCR Approach: The Conflict Handler



       Introduce a %conflict directive inside the head section
        of the translation scheme to specify the way the conflict will
        be solved.
       The directive is followed by some code - known as the
        conflict handler - whose mission is to modify the parsing
        tables.
PPCR Approach: The Conflict Handler



       Introduce a %conflict directive inside the head section
        of the translation scheme to specify the way the conflict will
        be solved.
       The directive is followed by some code - known as the
        conflict handler - whose mission is to modify the parsing
        tables.
       This code will be executed each time the associated
        conflict state is reached.
PPCR Approach: The Conflict Handler
PPCR Approach: The Conflict Handler

       This is the usual layout of the conflict handler for a
        reduce-reduce conflict:
        %conflict IsAorB {
          if (is_A) {
            $self-YYSetReduce(’@’, ’:rA’ );
          }
          else {
            $self-YYSetReduce(’@’, ’:rB’ );
          }
        }
PPCR Approach: The Conflict Handler

       This is the usual layout of the conflict handler for a
        reduce-reduce conflict:
        %conflict IsAorB {
          if (is_A) {
            $self-YYSetReduce(’@’, ’:rA’ );
          }
          else {
            $self-YYSetReduce(’@’, ’:rB’ );
          }
        }
        Inside a conflict code handler the Perl default variable $_
        refers to the input and $self refers to the parser object.
PPCR Approach: The Conflict Handler


       This is the usual layout of the conflict handler for a
        shift-reduce conflict:
        %conflict IsAorB {
          if (is_A) {
            $self-YYSetReduce(’@’, ’:rA’ );
          }
          else {
            $self-YYSetShift(’@’);
          }
        }
PPCR Approach: The Conflict Handler
PPCR Approach: The Conflict Handler
       The method YYSetReduce receives a list of tokens and a
        production label, like :rA. The call

               $self-YYSetReduce(’@’, ’:rA’ )

        sets the parsing action for the state associated with the
        conflict IsAorB to reduce by the production :rA when the
        current lookahead is @.
PPCR Approach: The Conflict Handler
       The method YYSetReduce receives a list of tokens and a
        production label, like :rA. The call

               $self-YYSetReduce(’@’, ’:rA’ )

        sets the parsing action for the state associated with the
        conflict IsAorB to reduce by the production :rA when the
        current lookahead is @.
       The method YYSetShift receives a token (or a reference
        to a list of tokens). The call

               $self-YYSetShift(’@’)

        sets the parsing action for the state associated with the
        conflict IsAorB to shift when the current lookahead is @.
PPCR Approach: The Conflict Handler


       %conflict IsAorB {
          if (is_A) { $self-YYSetReduce(’@’, ’:rA’ );
          }
          else { $self-YYSetReduce(’@’, ’:rB’ ); }
        }
       The call to is_A represents the context-dependent
        dynamic knowledge that allows us to take the right
        decision.
PPCR Approach: The Conflict Handler


       %conflict IsAorB {
          if (is_A) { $self-YYSetReduce(’@’, ’:rA’ );
          }
          else { $self-YYSetReduce(’@’, ’:rB’ ); }
        }
       The call to is_A represents the context-dependent
        dynamic knowledge that allows us to take the right
        decision.
       It is usually a call to a nested parser to check that A → α
        applies but it can also be any other contextual information
        we have to determine which one is the right production.
Outline



   Introduction


   Context Dependent Parsing


   Nested Parsing


   Conclusions
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1

        RIGHT
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1

        RIGHT

        2-1-1 # right: 2 = 2-(1-1)
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1

        RIGHT

        2-1-1 # right: 2 = 2-(1-1)

        LEFT
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1

        RIGHT

        2-1-1 # right: 2 = 2-(1-1)

        LEFT

        3-1-1 # left:   1 = (3-1)-1
A Simple Example: Context Dependant Associativity


        $ cat input_for_dynamicgrammar.txt
        2-1-1 # left: 0 = (2-1)-1

        RIGHT

        2-1-1 # right: 2 = 2-(1-1)

        LEFT

        3-1-1 # left:   1 = (3-1)-1

        RIGHT
        3-1-1 # right: 3 = 3-(1-1)
A Simple Example: Body
  p:    c *   {}
  ;
A Simple Example: Body
  p:    c *    {}
  ;
  c:     $expr { print $exprn }
       | RIGHT { $reduce = 0}
       | LEFT { $reduce = 1}
  ;
A Simple Example: Body
  p:    c *    {}
  ;
  c:     $expr { print $exprn }
       | RIGHT { $reduce = 0}
       | LEFT { $reduce = 1}
  ;
  expr: ’(’ $expr ’)’   { $expr }
      | NUM
A Simple Example: Body
  p:    c *    {}
  ;
  c:     $expr { print $exprn }
       | RIGHT { $reduce = 0}
       | LEFT { $reduce = 1}
  ;
  expr: ’(’ $expr ’)’   { $expr }
      | NUM

       | %name :M
         expr.left      %PREC leftORright
         ’-’ expr.right %PREC leftORright
               { $left - $right }
A Simple Example: Body
  p:    c *    {}
  ;
  c:     $expr { print $exprn }
       | RIGHT { $reduce = 0}
       | LEFT { $reduce = 1}
  ;
  expr: ’(’ $expr ’)’   { $expr }
      | NUM

       | %name :M
         expr.left      %PREC leftORright
         ’-’ expr.right %PREC leftORright
               { $left - $right }
  ;
  %%
A Simple Example: Head Section
  $ cat dynamicgrammar.eyp
A Simple Example: Head Section
  $ cat dynamicgrammar.eyp

  %{
  my $reduce = 1;
  %}
A Simple Example: Head Section
  $ cat dynamicgrammar.eyp

  %{
  my $reduce = 1;
  %}
                                  Automatically
  %whites /(s*(?:#.*)?s*)/       Generated
  %token NUM = /(d+)/           Lexical Analyzer
A Simple Example: Head Section
  $ cat dynamicgrammar.eyp

  %{
  my $reduce = 1;
  %}

  %whites /(s*(?:#.*)?s*)/
  %token NUM = /(d+)/

  %conflict leftORright {
    if ($reduce) { $self-YYSetReduce(’-’, ’:M’) }
    else { $self-YYSetShift(’-’) }
  }
A Simple Example: Head Section
  $ cat dynamicgrammar.eyp

  %{
  my $reduce = 1;
  %}

  %whites /(s*(?:#.*)?s*)/
  %token NUM = /(d+)/

  %conflict leftORright {
    if ($reduce) { $self-YYSetReduce(’-’, ’:M’) }
    else { $self-YYSetShift(’-’) }
  }

  %expect 1

  %%
Outline



   Introduction


   Context Dependent Parsing


   Nested Parsing


   Conclusions
Enumerated and Subrange Types in Pascal

       The problem is taken from the Bison manual.
        type subrange = lo .. hi;
        type enum = (a, b, c);
Enumerated and Subrange Types in Pascal

       The problem is taken from the Bison manual.
        type subrange = lo .. hi;
        type enum = (a, b, c);
       The Pascal standard allows only numeric literals and
        constant identifiers for the subrange bounds (lo and hi),
        but Extended Pascal and many other implementations
        allow arbitrary expressions there.
Enumerated and Subrange Types in Pascal

       The problem is taken from the Bison manual.
        type subrange = lo .. hi;
        type enum = (a, b, c);
       The Pascal standard allows only numeric literals and
        constant identifiers for the subrange bounds (lo and hi),
        but Extended Pascal and many other implementations
        allow arbitrary expressions there.
        type subrange = (a) .. b;
        type enum = (a);
Enumerated and Subrange Types in Pascal

       The problem is taken from the Bison manual.
        type subrange = lo .. hi;
        type enum = (a, b, c);
       The Pascal standard allows only numeric literals and
        constant identifiers for the subrange bounds (lo and hi),
        but Extended Pascal and many other implementations
        allow arbitrary expressions there.
                                                   Can't decide up to
        type subrange = (a) .. b;
                                                          here
        type enum = (a);
       To aggravate the conflict we have added the C comma
        operator to the language
        type subrange = (a, b, c) .. (d, e);
        type enum = (a, b, c);
Enumerated vs Range: Full Grammar
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
Enumerated vs Range: Full Grammar
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left   ’,’
  %left   ’-’ ’+’
  %left   ’*’ ’/’
Enumerated vs Range: Full Grammar
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left   ’,’
  %left   ’-’ ’+’
  %left   ’*’ ’/’
  %%
  type_decl : ’TYPE’ ID ’=’ type ’;’ ;
Enumerated vs Range: Full Grammar
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left   ’,’
  %left   ’-’ ’+’
  %left   ’*’ ’/’
  %%
  type_decl : ’TYPE’ ID ’=’ type ’;’ ;
  type : ’(’ id_list ’)’ | expr ’..’ expr ;
Enumerated vs Range: Full Grammar
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left     ’,’                        These are the
  %left     ’-’ ’+’                     productions
  %left     ’*’ ’/’                   involved in the
  %%                                      conflict
  type_decl : ’TYPE’ ID ’=’ type ’;’ ;
  type : ’(’ id_list ’)’ | expr ’..’ expr ;
  id_list   : ID            | id_list ’,’ ID ;
  expr :    ID
       |    NUM             | ’(’ expr ’)’
       |    expr ’,’ expr      /* new */
       |    expr ’+’ expr   | expr ’-’ expr
       |    expr ’*’ expr   | expr ’/’ expr
  ;
Identifying the Conflict
   $ eyapp -v pascalenumeratedvsrange.eyp
   2 reduce/reduce conflicts
Identifying the Conflict
   $ eyapp -v pascalenumeratedvsrange.eyp
   2 reduce/reduce conflicts

   State 11:
       id_list - ID . (Rule 4)
       expr - ID .    (Rule 12)

       ’)’   [reduce using rule 12 (expr)]
       ’)’   reduce using rule 4 (id_list)
       ’,’   [reduce using rule 12 (expr)]
       ’,’   reduce using rule 4 (id_list)


       ’*’   reduce   using   rule   12   (expr)
       ’+’   reduce   using   rule   12   (expr)
       ’-’   reduce   using   rule   12   (expr)
       ’/’   reduce   using   rule   12   (expr)
Enumerated vs Range: Body


  type_decl : ’type’ ID ’=’ type ’;’ ;
Enumerated vs Range: Body


  type_decl : ’type’ ID ’=’ type ’;’ ;

  type :
        %name ENUM
        Lookahead ’(’ id_list ’)’
      | %name RANGE
        Lookahead expr ’..’ expr
  ;
Enumerated vs Range: Body


  type_decl : ’type’ ID ’=’ type ’;’ ;

  type :
        %name ENUM
        Lookahead ’(’ id_list ’)’
      | %name RANGE
        Lookahead expr ’..’ expr
  ;
  Lookahead: /* empty */
    { $is_range = $_[0]-YYPreParse(’Range’); }
  ;
Nested Parsing: Future Work




  $ cat Range2.eyp


  %from pascalnestedeyapp2 import expr
  %%
  range: expr ’..’ expr ’;’
  ;
  %%
Nested Parsing: Current State
   $ cat Range.eyp
   %token ID = /([A-Za-z]w*)/
   %token NUM = /(d+)/

   %left   ’,’
   %left   ’-’ ’+’
   %left   ’*’ ’/’

   %%
   range: expr ’..’ expr ’;’
   ;

   expr : ’(’   expr ’)’
       | expr   ’+’ expr | expr ’-’ expr
       | expr   ’*’ expr | expr ’/’ expr
       | expr   ’,’ expr | ID | NUM
   ;
   %%
Enumerated vs Range: Body
Enumerated vs Range: Body
  id_list :
        %name ID:ENUM
        ID                  %PREC rangeORenum
      | id_list ’,’ ID
  ;
Enumerated vs Range: Body
  id_list :
        %name ID:ENUM
        ID                         %PREC rangeORenum
      | id_list ’,’ ID
  ;
  expr : ’(’ expr ’)’    { $_[2] } /* bypass */
      | %name ID:RANGE
        ID                         %PREC rangeORenum
      | %name PLUS       expr   ’+’ expr
      | %name MINUS      expr   ’-’ expr
      | %name TIMES      expr   ’*’ expr
      | %name DIV        expr   ’/’ expr
      | %name COMMA      expr   ’,’ expr
      | %name NUM        NUM
  ;

  %%
Enumerated vs Range: Header
Enumerated vs Range: Header
  %{
       my $is_range = 0;
  %}
  %conflict rangeORenum {
    if ($is_range)
     { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); }
    else
     { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); }
  }
Enumerated vs Range: Header
  %{
       my $is_range = 0;
  %}
  %conflict rangeORenum {
    if ($is_range)
     { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); }
    else
     { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); }
  }
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
Enumerated vs Range: Header
  %{
       my $is_range = 0;
  %}
  %conflict rangeORenum {
    if ($is_range)
     { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); }
    else
     { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); }
  }
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left     ’,’
  %left     ’-’ ’+’
  %left     ’*’ ’/’
Enumerated vs Range: Header
  %{
       my $is_range = 0;
  %}
  %conflict rangeORenum {
    if ($is_range)
     { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); }
    else
     { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); }
  }
  %token ID = /([A-Za-z]w*)/
  %token NUM = /(d+)/
  %left     ’,’
  %left     ’-’ ’+’
  %left     ’*’ ’/’
  %expect-rr 2
  %%
Enumerated vs Range: Execution

  $ eyapp -P Range.eyp
Enumerated vs Range: Execution

  $ eyapp -P Range.eyp

  $ eyapp -TC pascalnestedeyapp2.eyp
Enumerated vs Range: Execution

  $ eyapp -P Range.eyp

  $ eyapp -TC pascalnestedeyapp2.eyp

  $ ./pascalnestedeyapp2.pm -t -i -m 1 
                 -c ’type e = (x, y, z);’
Enumerated vs Range: Execution

  $ eyapp -P Range.eyp

  $ eyapp -TC pascalnestedeyapp2.eyp

  $ ./pascalnestedeyapp2.pm -t -i -m 1 
                 -c ’type e = (x, y, z);’

  typeDecl_is_type_ID_type(
    TERMINAL[e],
    ENUM(
      idList_is_idList_ID(
        idList_is_idList_ID(ID(TERMINAL[x]),
                            TERMINAL[y]),
        TERMINAL[z]
      )))
Outline



   Introduction


   Context Dependent Parsing


   Nested Parsing


   Conclusions
Conclusions
Conclusions

       The new conflict resolution mechanisms provide ways to
        resolve conflicts that can not be solved using static
        precedences.
Conclusions

       The new conflict resolution mechanisms provide ways to
        resolve conflicts that can not be solved using static
        precedences.
       They also provides finer control over the conflict resolution
        process than existing alternatives, like GLR and
        backtracking LR.
Conclusions

       The new conflict resolution mechanisms provide ways to
        resolve conflicts that can not be solved using static
        precedences.
       They also provides finer control over the conflict resolution
        process than existing alternatives, like GLR and
        backtracking LR.
       There are no limitations to PPCR parsing, since the conflict
        handler is implemented in a universal language and it then
        can resort to any kind of nested parsing algorithm.
Conclusions

       The new conflict resolution mechanisms provide ways to
        resolve conflicts that can not be solved using static
        precedences.
       They also provides finer control over the conflict resolution
        process than existing alternatives, like GLR and
        backtracking LR.
       There are no limitations to PPCR parsing, since the conflict
        handler is implemented in a universal language and it then
        can resort to any kind of nested parsing algorithm.
       The conflict resolution mechanisms presented here can be
        introduced in any LR parsing tools.
Conclusions

       The new conflict resolution mechanisms provide ways to
        resolve conflicts that can not be solved using static
        precedences.
       They also provides finer control over the conflict resolution
        process than existing alternatives, like GLR and
        backtracking LR.
       There are no limitations to PPCR parsing, since the conflict
        handler is implemented in a universal language and it then
        can resort to any kind of nested parsing algorithm.
       The conflict resolution mechanisms presented here can be
        introduced in any LR parsing tools.
       It certainly involves more programmer work than branching
        methods like GLR or backtracking LR.
http://parse-eyapp.googlecode.com/svn/branches/PPCR
http://parse-eyapp.googlecode.com/svn/branches/PPCR



                   Thanks!

More Related Content

Similar to Ppcrslidesannotated

Introducing Riak
Introducing RiakIntroducing Riak
Introducing RiakKevin Smith
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing RiakKevin Smith
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingsaykopatt
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio) rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Microprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionMicroprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionArkhom Jodtang
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001Ralph Weber
 
Introduction to javascript.ppt
Introduction to javascript.pptIntroduction to javascript.ppt
Introduction to javascript.pptBArulmozhi
 
Computational Techniques for the Statistical Analysis of Big Data in R
Computational Techniques for the Statistical Analysis of Big Data in RComputational Techniques for the Statistical Analysis of Big Data in R
Computational Techniques for the Statistical Analysis of Big Data in Rherbps10
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsGeo Marian
 
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...Spark Summit
 
Monte Carlo Simulations in Ad Lift Measurement using Spark
Monte Carlo Simulations in Ad Lift Measurement using SparkMonte Carlo Simulations in Ad Lift Measurement using Spark
Monte Carlo Simulations in Ad Lift Measurement using SparkPrasad Chalasani
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2Nihar Ranjan Paital
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 

Similar to Ppcrslidesannotated (20)

Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Microprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionMicroprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch Instruction
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Presentation 2
Presentation 2Presentation 2
Presentation 2
 
Introduction to javascript.ppt
Introduction to javascript.pptIntroduction to javascript.ppt
Introduction to javascript.ppt
 
Operators & Casts
Operators & CastsOperators & Casts
Operators & Casts
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Computational Techniques for the Statistical Analysis of Big Data in R
Computational Techniques for the Statistical Analysis of Big Data in RComputational Techniques for the Statistical Analysis of Big Data in R
Computational Techniques for the Statistical Analysis of Big Data in R
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statements
 
Java Programming
Java Programming Java Programming
Java Programming
 
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...
Monte Carlo Simulations in Ad-Lift Measurement Using Spark by Prasad Chalasan...
 
Monte Carlo Simulations in Ad Lift Measurement using Spark
Monte Carlo Simulations in Ad Lift Measurement using SparkMonte Carlo Simulations in Ad Lift Measurement using Spark
Monte Carlo Simulations in Ad Lift Measurement using Spark
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Ppcrslidesannotated

  • 1. Solving Difficult LR Parsing Conflicts by Postponing Them Luis Garcia-Forte and Casiano Rodriguez-Leon Universidad de La Laguna CoRTA2010 September 09-10, 2010
  • 2. Outline Introduction Context Dependent Parsing Nested Parsing Conclusions
  • 3. Outline Introduction Context Dependent Parsing Nested Parsing Conclusions
  • 4. Yacc Limitations Yacc-like LR parser generators provide ways to solve shift-reduce mechanisms based on token precedence.
  • 5. Yacc Limitations Yacc-like LR parser generators provide ways to solve shift-reduce mechanisms based on token precedence. No mechanisms are provided for the resolution of reduce-reduce conflicts or difficult shift-reduce conflicts.
  • 6. Yacc Limitations Yacc-like LR parser generators provide ways to solve shift-reduce mechanisms based on token precedence. No mechanisms are provided for the resolution of reduce-reduce conflicts or difficult shift-reduce conflicts. To solve such kind of conflicts the language designer has to modify the grammar.
  • 8. Postponed Conflict Resolution Approach The strategy presented here extends yacc conflict resolution mechanisms with new ones, supplying ways to resolve conflicts that can not be solved using static precedences.
  • 9. Postponed Conflict Resolution Approach The strategy presented here extends yacc conflict resolution mechanisms with new ones, supplying ways to resolve conflicts that can not be solved using static precedences. The algorithm for the generation of the LR tables remains unchanged, but the programmer can modify the parsing tables during run time.
  • 10. PPCR Approach: Identify the Conflict
  • 11. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?.
  • 12. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp.
  • 13. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items
  • 14. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items A → α↑
  • 15. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items A → α↑ and
  • 16. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items A → α↑ and B → β↑
  • 17. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items A → α↑ and B → β↑ when the lookahead token is
  • 18. PPCR Approach: Identify the Conflict Identify the conflict: What LR(0)-items/productions and tokens are involved?. Tools must support that stage, as for example via the .output file generated by eyapp. Suppose we identify that the participants are the two LR(0)-items A → α↑ and B → β↑ when the lookahead token is @.
  • 19. PPCR Approach: Identify the Conflict
  • 20. PPCR Approach: Identify the Conflict The software must allow the use of symbolic labels to refer by name to the productions involved in the conflict.
  • 21. PPCR Approach: Identify the Conflict The software must allow the use of symbolic labels to refer by name to the productions involved in the conflict. In Eyapp names and labels can be explicitly given using the directive %name, using a syntax similar to this one: %name :rA A → α %name :rB B → β
  • 22. PPCR Approach: Identify the Conflict
  • 23. PPCR Approach: Identify the Conflict Give a symbolic name to the conflict. In this case we choose isAorB as name of the conflict.
  • 24. PPCR Approach: Identify the Conflict Give a symbolic name to the conflict. In this case we choose isAorB as name of the conflict. Inside the body section of the grammar, mark the points of conflict using the new reserved word %PREC followed by the conflict name: %name :rA A → α %PREC IsAorB %name :rA B → β %PREC IsAorB
  • 25. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts.
  • 26. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items
  • 27. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items A → α↑
  • 28. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items A → α↑ and
  • 29. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items A → α↑ and B→β↑γ
  • 30. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items A → α↑ and B → β ↑ γ for some token ’@’.
  • 31. Conflict Identification: Shift-Reduce Conflicts The procedure is similar for shift-reduce conflicts. Let us assume we have identified a shift-reduce conflict between LR-(0) items A → α↑ and B → β ↑ γ for some token ’@’. Again, we must give a symbolic name to A → α and mark with the new %PREC directive the places where the conflict occurs: %name :rA A → α %PREC IsAorB B →β %PREC IsAorB γ
  • 32. PPCR Approach: The Conflict Handler
  • 33. PPCR Approach: The Conflict Handler Introduce a %conflict directive inside the head section of the translation scheme to specify the way the conflict will be solved.
  • 34. PPCR Approach: The Conflict Handler Introduce a %conflict directive inside the head section of the translation scheme to specify the way the conflict will be solved. The directive is followed by some code - known as the conflict handler - whose mission is to modify the parsing tables.
  • 35. PPCR Approach: The Conflict Handler Introduce a %conflict directive inside the head section of the translation scheme to specify the way the conflict will be solved. The directive is followed by some code - known as the conflict handler - whose mission is to modify the parsing tables. This code will be executed each time the associated conflict state is reached.
  • 36. PPCR Approach: The Conflict Handler
  • 37. PPCR Approach: The Conflict Handler This is the usual layout of the conflict handler for a reduce-reduce conflict: %conflict IsAorB { if (is_A) { $self-YYSetReduce(’@’, ’:rA’ ); } else { $self-YYSetReduce(’@’, ’:rB’ ); } }
  • 38. PPCR Approach: The Conflict Handler This is the usual layout of the conflict handler for a reduce-reduce conflict: %conflict IsAorB { if (is_A) { $self-YYSetReduce(’@’, ’:rA’ ); } else { $self-YYSetReduce(’@’, ’:rB’ ); } } Inside a conflict code handler the Perl default variable $_ refers to the input and $self refers to the parser object.
  • 39. PPCR Approach: The Conflict Handler This is the usual layout of the conflict handler for a shift-reduce conflict: %conflict IsAorB { if (is_A) { $self-YYSetReduce(’@’, ’:rA’ ); } else { $self-YYSetShift(’@’); } }
  • 40. PPCR Approach: The Conflict Handler
  • 41. PPCR Approach: The Conflict Handler The method YYSetReduce receives a list of tokens and a production label, like :rA. The call $self-YYSetReduce(’@’, ’:rA’ ) sets the parsing action for the state associated with the conflict IsAorB to reduce by the production :rA when the current lookahead is @.
  • 42. PPCR Approach: The Conflict Handler The method YYSetReduce receives a list of tokens and a production label, like :rA. The call $self-YYSetReduce(’@’, ’:rA’ ) sets the parsing action for the state associated with the conflict IsAorB to reduce by the production :rA when the current lookahead is @. The method YYSetShift receives a token (or a reference to a list of tokens). The call $self-YYSetShift(’@’) sets the parsing action for the state associated with the conflict IsAorB to shift when the current lookahead is @.
  • 43. PPCR Approach: The Conflict Handler %conflict IsAorB { if (is_A) { $self-YYSetReduce(’@’, ’:rA’ ); } else { $self-YYSetReduce(’@’, ’:rB’ ); } } The call to is_A represents the context-dependent dynamic knowledge that allows us to take the right decision.
  • 44. PPCR Approach: The Conflict Handler %conflict IsAorB { if (is_A) { $self-YYSetReduce(’@’, ’:rA’ ); } else { $self-YYSetReduce(’@’, ’:rB’ ); } } The call to is_A represents the context-dependent dynamic knowledge that allows us to take the right decision. It is usually a call to a nested parser to check that A → α applies but it can also be any other contextual information we have to determine which one is the right production.
  • 45. Outline Introduction Context Dependent Parsing Nested Parsing Conclusions
  • 46. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1
  • 47. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1 RIGHT
  • 48. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1 RIGHT 2-1-1 # right: 2 = 2-(1-1)
  • 49. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1 RIGHT 2-1-1 # right: 2 = 2-(1-1) LEFT
  • 50. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1 RIGHT 2-1-1 # right: 2 = 2-(1-1) LEFT 3-1-1 # left: 1 = (3-1)-1
  • 51. A Simple Example: Context Dependant Associativity $ cat input_for_dynamicgrammar.txt 2-1-1 # left: 0 = (2-1)-1 RIGHT 2-1-1 # right: 2 = 2-(1-1) LEFT 3-1-1 # left: 1 = (3-1)-1 RIGHT 3-1-1 # right: 3 = 3-(1-1)
  • 52. A Simple Example: Body p: c * {} ;
  • 53. A Simple Example: Body p: c * {} ; c: $expr { print $exprn } | RIGHT { $reduce = 0} | LEFT { $reduce = 1} ;
  • 54. A Simple Example: Body p: c * {} ; c: $expr { print $exprn } | RIGHT { $reduce = 0} | LEFT { $reduce = 1} ; expr: ’(’ $expr ’)’ { $expr } | NUM
  • 55. A Simple Example: Body p: c * {} ; c: $expr { print $exprn } | RIGHT { $reduce = 0} | LEFT { $reduce = 1} ; expr: ’(’ $expr ’)’ { $expr } | NUM | %name :M expr.left %PREC leftORright ’-’ expr.right %PREC leftORright { $left - $right }
  • 56. A Simple Example: Body p: c * {} ; c: $expr { print $exprn } | RIGHT { $reduce = 0} | LEFT { $reduce = 1} ; expr: ’(’ $expr ’)’ { $expr } | NUM | %name :M expr.left %PREC leftORright ’-’ expr.right %PREC leftORright { $left - $right } ; %%
  • 57. A Simple Example: Head Section $ cat dynamicgrammar.eyp
  • 58. A Simple Example: Head Section $ cat dynamicgrammar.eyp %{ my $reduce = 1; %}
  • 59. A Simple Example: Head Section $ cat dynamicgrammar.eyp %{ my $reduce = 1; %} Automatically %whites /(s*(?:#.*)?s*)/ Generated %token NUM = /(d+)/ Lexical Analyzer
  • 60. A Simple Example: Head Section $ cat dynamicgrammar.eyp %{ my $reduce = 1; %} %whites /(s*(?:#.*)?s*)/ %token NUM = /(d+)/ %conflict leftORright { if ($reduce) { $self-YYSetReduce(’-’, ’:M’) } else { $self-YYSetShift(’-’) } }
  • 61. A Simple Example: Head Section $ cat dynamicgrammar.eyp %{ my $reduce = 1; %} %whites /(s*(?:#.*)?s*)/ %token NUM = /(d+)/ %conflict leftORright { if ($reduce) { $self-YYSetReduce(’-’, ’:M’) } else { $self-YYSetShift(’-’) } } %expect 1 %%
  • 62. Outline Introduction Context Dependent Parsing Nested Parsing Conclusions
  • 63. Enumerated and Subrange Types in Pascal The problem is taken from the Bison manual. type subrange = lo .. hi; type enum = (a, b, c);
  • 64. Enumerated and Subrange Types in Pascal The problem is taken from the Bison manual. type subrange = lo .. hi; type enum = (a, b, c); The Pascal standard allows only numeric literals and constant identifiers for the subrange bounds (lo and hi), but Extended Pascal and many other implementations allow arbitrary expressions there.
  • 65. Enumerated and Subrange Types in Pascal The problem is taken from the Bison manual. type subrange = lo .. hi; type enum = (a, b, c); The Pascal standard allows only numeric literals and constant identifiers for the subrange bounds (lo and hi), but Extended Pascal and many other implementations allow arbitrary expressions there. type subrange = (a) .. b; type enum = (a);
  • 66. Enumerated and Subrange Types in Pascal The problem is taken from the Bison manual. type subrange = lo .. hi; type enum = (a, b, c); The Pascal standard allows only numeric literals and constant identifiers for the subrange bounds (lo and hi), but Extended Pascal and many other implementations allow arbitrary expressions there. Can't decide up to type subrange = (a) .. b; here type enum = (a); To aggravate the conflict we have added the C comma operator to the language type subrange = (a, b, c) .. (d, e); type enum = (a, b, c);
  • 67. Enumerated vs Range: Full Grammar %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/
  • 68. Enumerated vs Range: Full Grammar %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’
  • 69. Enumerated vs Range: Full Grammar %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’ %% type_decl : ’TYPE’ ID ’=’ type ’;’ ;
  • 70. Enumerated vs Range: Full Grammar %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’ %% type_decl : ’TYPE’ ID ’=’ type ’;’ ; type : ’(’ id_list ’)’ | expr ’..’ expr ;
  • 71. Enumerated vs Range: Full Grammar %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ These are the %left ’-’ ’+’ productions %left ’*’ ’/’ involved in the %% conflict type_decl : ’TYPE’ ID ’=’ type ’;’ ; type : ’(’ id_list ’)’ | expr ’..’ expr ; id_list : ID | id_list ’,’ ID ; expr : ID | NUM | ’(’ expr ’)’ | expr ’,’ expr /* new */ | expr ’+’ expr | expr ’-’ expr | expr ’*’ expr | expr ’/’ expr ;
  • 72. Identifying the Conflict $ eyapp -v pascalenumeratedvsrange.eyp 2 reduce/reduce conflicts
  • 73. Identifying the Conflict $ eyapp -v pascalenumeratedvsrange.eyp 2 reduce/reduce conflicts State 11: id_list - ID . (Rule 4) expr - ID . (Rule 12) ’)’ [reduce using rule 12 (expr)] ’)’ reduce using rule 4 (id_list) ’,’ [reduce using rule 12 (expr)] ’,’ reduce using rule 4 (id_list) ’*’ reduce using rule 12 (expr) ’+’ reduce using rule 12 (expr) ’-’ reduce using rule 12 (expr) ’/’ reduce using rule 12 (expr)
  • 74. Enumerated vs Range: Body type_decl : ’type’ ID ’=’ type ’;’ ;
  • 75. Enumerated vs Range: Body type_decl : ’type’ ID ’=’ type ’;’ ; type : %name ENUM Lookahead ’(’ id_list ’)’ | %name RANGE Lookahead expr ’..’ expr ;
  • 76. Enumerated vs Range: Body type_decl : ’type’ ID ’=’ type ’;’ ; type : %name ENUM Lookahead ’(’ id_list ’)’ | %name RANGE Lookahead expr ’..’ expr ; Lookahead: /* empty */ { $is_range = $_[0]-YYPreParse(’Range’); } ;
  • 77. Nested Parsing: Future Work $ cat Range2.eyp %from pascalnestedeyapp2 import expr %% range: expr ’..’ expr ’;’ ; %%
  • 78. Nested Parsing: Current State $ cat Range.eyp %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’ %% range: expr ’..’ expr ’;’ ; expr : ’(’ expr ’)’ | expr ’+’ expr | expr ’-’ expr | expr ’*’ expr | expr ’/’ expr | expr ’,’ expr | ID | NUM ; %%
  • 80. Enumerated vs Range: Body id_list : %name ID:ENUM ID %PREC rangeORenum | id_list ’,’ ID ;
  • 81. Enumerated vs Range: Body id_list : %name ID:ENUM ID %PREC rangeORenum | id_list ’,’ ID ; expr : ’(’ expr ’)’ { $_[2] } /* bypass */ | %name ID:RANGE ID %PREC rangeORenum | %name PLUS expr ’+’ expr | %name MINUS expr ’-’ expr | %name TIMES expr ’*’ expr | %name DIV expr ’/’ expr | %name COMMA expr ’,’ expr | %name NUM NUM ; %%
  • 83. Enumerated vs Range: Header %{ my $is_range = 0; %} %conflict rangeORenum { if ($is_range) { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); } else { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); } }
  • 84. Enumerated vs Range: Header %{ my $is_range = 0; %} %conflict rangeORenum { if ($is_range) { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); } else { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); } } %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/
  • 85. Enumerated vs Range: Header %{ my $is_range = 0; %} %conflict rangeORenum { if ($is_range) { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); } else { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); } } %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’
  • 86. Enumerated vs Range: Header %{ my $is_range = 0; %} %conflict rangeORenum { if ($is_range) { $self-YYSetReduce([’,’, ’)’], ’ID:RANGE’ ); } else { $self-YYSetReduce([’,’, ’)’], ’ID:ENUM’ ); } } %token ID = /([A-Za-z]w*)/ %token NUM = /(d+)/ %left ’,’ %left ’-’ ’+’ %left ’*’ ’/’ %expect-rr 2 %%
  • 87. Enumerated vs Range: Execution $ eyapp -P Range.eyp
  • 88. Enumerated vs Range: Execution $ eyapp -P Range.eyp $ eyapp -TC pascalnestedeyapp2.eyp
  • 89. Enumerated vs Range: Execution $ eyapp -P Range.eyp $ eyapp -TC pascalnestedeyapp2.eyp $ ./pascalnestedeyapp2.pm -t -i -m 1 -c ’type e = (x, y, z);’
  • 90. Enumerated vs Range: Execution $ eyapp -P Range.eyp $ eyapp -TC pascalnestedeyapp2.eyp $ ./pascalnestedeyapp2.pm -t -i -m 1 -c ’type e = (x, y, z);’ typeDecl_is_type_ID_type( TERMINAL[e], ENUM( idList_is_idList_ID( idList_is_idList_ID(ID(TERMINAL[x]), TERMINAL[y]), TERMINAL[z] )))
  • 91. Outline Introduction Context Dependent Parsing Nested Parsing Conclusions
  • 93. Conclusions The new conflict resolution mechanisms provide ways to resolve conflicts that can not be solved using static precedences.
  • 94. Conclusions The new conflict resolution mechanisms provide ways to resolve conflicts that can not be solved using static precedences. They also provides finer control over the conflict resolution process than existing alternatives, like GLR and backtracking LR.
  • 95. Conclusions The new conflict resolution mechanisms provide ways to resolve conflicts that can not be solved using static precedences. They also provides finer control over the conflict resolution process than existing alternatives, like GLR and backtracking LR. There are no limitations to PPCR parsing, since the conflict handler is implemented in a universal language and it then can resort to any kind of nested parsing algorithm.
  • 96. Conclusions The new conflict resolution mechanisms provide ways to resolve conflicts that can not be solved using static precedences. They also provides finer control over the conflict resolution process than existing alternatives, like GLR and backtracking LR. There are no limitations to PPCR parsing, since the conflict handler is implemented in a universal language and it then can resort to any kind of nested parsing algorithm. The conflict resolution mechanisms presented here can be introduced in any LR parsing tools.
  • 97. Conclusions The new conflict resolution mechanisms provide ways to resolve conflicts that can not be solved using static precedences. They also provides finer control over the conflict resolution process than existing alternatives, like GLR and backtracking LR. There are no limitations to PPCR parsing, since the conflict handler is implemented in a universal language and it then can resort to any kind of nested parsing algorithm. The conflict resolution mechanisms presented here can be introduced in any LR parsing tools. It certainly involves more programmer work than branching methods like GLR or backtracking LR.