3 Replies Latest reply on Nov 21, 2018 6:56 PM by user2885917

    The problem with the lexical analyzer? There is a workaround. But the question is how to find all such names in the code?

    user2885917

      The problem with the lexical analyzer?

      The lexical parsing of the correct variable name is incorrectly performed, therefore, the code cannot be parsed syntactically.

       

      Code:

       

      declare

        c#1_day number;

      begin

        c#1_day := 1;

      end;

       

      Tokens:

       

      [0,7) declare   <IDENTIFIER>

      [11,15) c#1_   <IDENTIFIER>

      [15,16) d   <IDENTIFIER>

      [16,18) ay   <IDENTIFIER>

      [19,25) number   <IDENTIFIER>

      [25,26) ;   <OPERATION>

      [28,33) begin   <IDENTIFIER>

      [37,41) c#1_   <IDENTIFIER>

      [41,42) d   <IDENTIFIER>

      [42,44) ay   <IDENTIFIER>

      [45,46) :   <OPERATION>

      [46,47) =   <OPERATION>

      [48,49) 1   <DIGITS>

      [49,50) ;   <OPERATION>

      [52,55) end   <IDENTIFIER>

      [55,56) ;   <OPERATION>

       

      Parsed tree (incorrect !):

       

      [0,16)

        [0,3)   basic_d  object_d

          declare [0,1)   decl_id  identifier

          [1,3)   constrained_type  object_d_rhs

          c#1_ [1,2)   dotted_name  identifier  link_expanded_n  unconstrained_type_wo_datetime

          d [2,3)   constraint  id_or_qualid  identifier

        [1,4)   basic_d  object_d

          c#1_ [1,2)   decl_id  identifier

        [2,4)   constrained_type  object_d_rhs

          d [2,3)   dotted_name  identifier  link_expanded_n  unconstrained_type_wo_datetime

          ay [3,4)   constraint  id_or_qualid  identifier

        [2,4)   constrained_type

          d [2,3)   dotted_name  identifier  link_expanded_n  unconstrained_type_wo_datetime

          ay [3,4)   constraint  id_or_qualid  identifier

       

       

       

      This is a problem if you have a lot of legacy code that already uses such names.

      But there is a workaround - use quotes for names.

       

      Code:

       

      declare

        "c#1_day" number;

      begin

      "c#1_day" := 1;

      end;

       

      Tokens:

       

      [0,7) declare   <IDENTIFIER>

      [11,20) "c#1_day"   <DQUOTED_STRING>

      [21,27) number   <IDENTIFIER>

      [27,28) ;   <OPERATION>

      [30,35) begin   <IDENTIFIER>

      [39,48) "c#1_day"   <DQUOTED_STRING>

      [49,50) :   <OPERATION>

      [50,51) =   <OPERATION>

      [52,53) 1   <DIGITS>

      [53,54) ;   <OPERATION>

      [56,59) end   <IDENTIFIER>

      [59,60) ;   <OPERATION>

       

      Parsed tree (correct !):

       

      [0,12)   block_stmt  labeled_block_stmt  library_unit  sql_statement  sql_statements

        [0,4)   DECLARE_decls_opt

          declare [0,1)   'DECLARE'

          [1,4)   basic_decl_item  basic_decl_item_list  decl_list

            [1,3)   basic_d  object_d

             "c#1_day" [1,2)   decl_id  identifier

              number [2,3)   'NUMBER'  constrained_type  object_d_rhs  pls_number_datatypes  unconstrained_type_wo_datetime

            ; [3,4)   ';'

        begin [4,5)   'BEGIN'

        [5,10)   assignment_stmt  labeled_nonblock_stmt  seq_of_stmts  sim_stmt  stmt  unlabeled_nonblock_stmt

         "c#1_day" [5,6)   identifier  name  name_wo_function_call

          : [6,7)   ':'

          = [7,8)   '='

          1 [8,9)   and_expr  arith_expr  boolean_primary  digits  factor  numeric_literal  pls_expr  pri  rel  sim_expr  term

          ; [9,10)   ';'

        end [10,11)   'END'

        ; [11,12)   ';'

       

      This can help other community members. But the question is how to find all such names in the code. A pattern is needed (for example, regexp) to search for such names that break the lexical analyzer. Here I expect help from the developers of the lexical analyzer, who sometimes respond here in the forum.