Lexical Analysis - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Lexical Analysis

sigma_zksigma_zk Posts: 68Member
I need the pseudocode for an algorithm that matches strings based on a pattern based on DOS wildcards:
? matches any one character.
* matches zero or more characters, as many characters as possible.
any other character matches that character.
The pattern must match the entire string perfectly or it is a failure.

The * is the thing that is giving me the most trouble, by the way.

Comments

  • iapiap Posts: 6Member
    : The * is the thing that is giving me the most trouble, by the way.
    :

    Ok, I can't write it in paseudo code, but I can give you the idea:

    try splitting your query string to sections, when the * is the seperator:

    "A*B*CD" -> ["A","B","CD"]

    the compare each of the sections with the data string, checking in each compiration that the index of the mach (if found) is bigger then the index of the mach of the previous section.

    "AdfsBtfgCD"
    index of "A" is 1.
    index of "B" is 5 - bigger then 1.
    index of "CD" is 9 - bigger then 5.
    string mach.

    I hope I'm clear....

  • sigma_zksigma_zk Posts: 68Member
    I just made it so * grabs the rest of the string and backtracks recursively until it finds a match. Thanks anyways tho' :-).
Sign In or Register to comment.