Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. I love when that happens!

I love when that happens!

Scheduled Pinned Locked Moved The Lounge
algorithmsregex
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • honey the codewitchH honey the codewitch

    I was making a state removal method that would turn a state machine into a regular expression. In the process I needed to do a subtask, to wit, I needed to set up a quick and dirty finite automaton engine to hold the states. Rather than make a bunch of objects/states that point to other objects/states using dictionaries, I simply stored all the dictionary transitions as a single tuple (int from, int to, string input) in a flat list. The result is smaller, and allows me to do complicated queries on the relationships between the states (now represented as simple integers) very simply. In fact, the result is so good, I may be able to rewrite a more compact and efficient state engine using this technique. And it was originally just intended to be "just enough of a thing" to be scaffolding for my overarching algorithm to work with. I'm elated. Even if the overarching algorithm doesn't work, it means far more compact and efficient code potentially in terms of the finite automata code it works with. :-D

    Real programmers use butterflies

    Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #3

    You're a real innovator!

    The difficult we do right away... ...the impossible takes slightly longer.

    honey the codewitchH 1 Reply Last reply
    0
    • P PIEBALDconsult

      That reminds me of a third-party product a colleague was using. It didn't support proper Order-of-Operations. I said, "it's wrong", and he said, "but it's faaaasssst!"

      honey the codewitchH Offline
      honey the codewitchH Offline
      honey the codewitch
      wrote on last edited by
      #4

      Sometimes it doesn't have to be completely right to work for a situation. Honestly I respect code that does just enough to do the job for a particular application - very efficiently. It's to my mind, one of the higher achievements in code such that if you can pull it off regularly you are way more clever than I. I have to respect it. :)

      Real programmers use butterflies

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        You're a real innovator!

        The difficult we do right away... ...the impossible takes slightly longer.

        honey the codewitchH Offline
        honey the codewitchH Offline
        honey the codewitch
        wrote on last edited by
        #5

        Accidentally, so. I wish it was repeatable, but when I stumble on something, I'll take it. :)

        Real programmers use butterflies

        N 1 Reply Last reply
        0
        • honey the codewitchH honey the codewitch

          Accidentally, so. I wish it was repeatable, but when I stumble on something, I'll take it. :)

          Real programmers use butterflies

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #6

          honey the codewitch wrote:

          Accidentally, so.

          Penicillin was accidental too ;)

          M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

          1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            I was making a state removal method that would turn a state machine into a regular expression. In the process I needed to do a subtask, to wit, I needed to set up a quick and dirty finite automaton engine to hold the states. Rather than make a bunch of objects/states that point to other objects/states using dictionaries, I simply stored all the dictionary transitions as a single tuple (int from, int to, string input) in a flat list. The result is smaller, and allows me to do complicated queries on the relationships between the states (now represented as simple integers) very simply. In fact, the result is so good, I may be able to rewrite a more compact and efficient state engine using this technique. And it was originally just intended to be "just enough of a thing" to be scaffolding for my overarching algorithm to work with. I'm elated. Even if the overarching algorithm doesn't work, it means far more compact and efficient code potentially in terms of the finite automata code it works with. :-D

            Real programmers use butterflies

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #7

            honey the codewitch wrote:

            turn a state machine into a regular expression

            That phrase is a bit odd. The way regular expressions work, depending on the match expression, is to create a state machine (and perhaps even more than one.)

            honey the codewitchH 1 Reply Last reply
            0
            • J jschell

              honey the codewitch wrote:

              turn a state machine into a regular expression

              That phrase is a bit odd. The way regular expressions work, depending on the match expression, is to create a state machine (and perhaps even more than one.)

              honey the codewitchH Offline
              honey the codewitchH Offline
              honey the codewitch
              wrote on last edited by
              #8

              This is doing the reverse of that.

              Real programmers use butterflies

              J 1 Reply Last reply
              0
              • honey the codewitchH honey the codewitch

                I was making a state removal method that would turn a state machine into a regular expression. In the process I needed to do a subtask, to wit, I needed to set up a quick and dirty finite automaton engine to hold the states. Rather than make a bunch of objects/states that point to other objects/states using dictionaries, I simply stored all the dictionary transitions as a single tuple (int from, int to, string input) in a flat list. The result is smaller, and allows me to do complicated queries on the relationships between the states (now represented as simple integers) very simply. In fact, the result is so good, I may be able to rewrite a more compact and efficient state engine using this technique. And it was originally just intended to be "just enough of a thing" to be scaffolding for my overarching algorithm to work with. I'm elated. Even if the overarching algorithm doesn't work, it means far more compact and efficient code potentially in terms of the finite automata code it works with. :-D

                Real programmers use butterflies

                E Offline
                E Offline
                englebart
                wrote on last edited by
                #9

                I like the state machine setup that is basically an abstract/pure virtual super class where each possible input is a method that returns the next state. Each state is a concrete class that must implement all of the input methods. It would likely take up more memory with vtables than your approach, but I like that it makes the introduction of a new input a compile time check on all of the states. Same if you add a new state; you have to define transitions for every input. I prefer compile time checks, but I work on a memory hog of a system where we have that luxury.😊

                honey the codewitchH 1 Reply Last reply
                0
                • E englebart

                  I like the state machine setup that is basically an abstract/pure virtual super class where each possible input is a method that returns the next state. Each state is a concrete class that must implement all of the input methods. It would likely take up more memory with vtables than your approach, but I like that it makes the introduction of a new input a compile time check on all of the states. Same if you add a new state; you have to define transitions for every input. I prefer compile time checks, but I work on a memory hog of a system where we have that luxury.😊

                  honey the codewitchH Offline
                  honey the codewitchH Offline
                  honey the codewitch
                  wrote on last edited by
                  #10

                  If you take a look at Reggie: A Non-Backtracking Streaming Regular Expression Code Generator[^] you'll see that since the state machines end up compiled, the input states are about as checked as they're going to get. In this way you dictate the state machine specs, it then creates an in memory digraph of the states, which it then does some transformations on before compiling into code, at which point *everything* is compiled - in this case into goto tables - one label for each state. Although it can also generate a table/array based matcher Because of how that works, your solution actually doesn't actually fit that particular application (and this is how i most often use them). Because it goes spec->state-machine->code, not spec->coded-state-machine At least if I understand you.

                  Real programmers use butterflies

                  1 Reply Last reply
                  0
                  • honey the codewitchH honey the codewitch

                    This is doing the reverse of that.

                    Real programmers use butterflies

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #11

                    Yes but just want to be clear that although you are using a regular expression it will in fact end up using a state machine to implement that regular expression.

                    honey the codewitchH 1 Reply Last reply
                    0
                    • J jschell

                      Yes but just want to be clear that although you are using a regular expression it will in fact end up using a state machine to implement that regular expression.

                      honey the codewitchH Offline
                      honey the codewitchH Offline
                      honey the codewitch
                      wrote on last edited by
                      #12

                      Yes, but specifically I'm talking about taking that state machine and turning it back into a regular expression.

                      Real programmers use butterflies

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups