The implementation of "*?" (lazy "*") regex pattern in GLR combinators

I have implemented GLR combinatorial analyzers. Among them:

  • char(·)that consumes the specified character or range of characters.
  • many(·)which repeats the specified parser from zero to infinite times.

Example: "char('a').many()"will match a string with any number "a"-s.

But the combinator many(·)is greedy, so, for example, char('{') >> char('{') >> char('a'..'z').many() >> char('}') >> char('}')(where ">>"is a sequential chain of parsers) will successfully consume a whole string "{{foo}}some{{bar}}".

I want to implement a lazy version many(·), which, as used in the previous example, will consume only "{{foo}}". How can i do this?

Edit:

Maybe I'm all confused. In my program, a parser is a function (or “functor” in C ++ terms) that takes a “step” and returns a forest of “steps”. A “step” can be of type “OK” (this means that the parser has successfully used part of the input) and of type FAIL (this means that the analyzer encountered an error). There are several types of steps, but they are auxiliary.

Parser = f(Step) -> Collection of TreeNodes of Steps.

So when I parse the input, I:

  • Compose simple predefined Parser functions to get a complex Parser function representing the desired grammar.

  • Enter the initial step from the entrance.

  • Give the initial step to the comprehensive Parser function.

  • Filter TreeNodes using steps, leaving only OK (or with minimal errors if there were errors in the input).

  • Gather information from the remaining steps.

+3
4

<.*?> <a>bc<d>ef. <a> , ?

<.*?>e . <a>bc<d>e, ?

. , >> . , .

- , , , . , ; , .

0

GLR 15 .

, " GLR", , , . , - ? , , "char (" a "). Many" :

 char = "a" ;
 char = char "a" ;

GLR, , . GLR . "" (.. , ), GLR, , , ( , , , ) .

GLR, . , , , GLR.

GLR, . , , - ; , ( psuedo-parallel, GLR , ) : a) , b) , FOLLOW (x) x - . , , . GLR. (, ). , , , . GLR , EOF. , GLR ; , .

+4

GLR ? - , . , , , . ( , .)

( GLR. , - .)

+1

- , . ( ), "-" ; , " ".

, . , , , , .

0

Source: https://habr.com/ru/post/1778711/


All Articles