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

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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.