ChubakPDP11+TakeWithGrainOfSalt

  • 19 Posts
  • 12 Comments
Joined 5 months ago
cake
Cake day: February 10th, 2024

help-circle













  • True, but see, all these build up on the theoretical regex. The theoretical regex indeed has only 3 operators: dot for concatenation, pipe for alteration and the ‘kleene star’ [re: Sipser’s]. These 3 operators can express a finite state automata. You don’t really need all that other operators. Read this: https://swtch.com/~rsc/regexp/regexp1.html Algorithms like Thompson construction can translate a regex to a non-deterministic automata quite quickly, and then from there you can make a DFA or just simulate the NFA.

    I would not call PCRE ‘regular expression’ really. If you read the article I gave you it explains why they are mostly a practical utility than a theoretical groundwork. The regex in use today is far from the regex one learns about in books.

    I think regex is abused. People use it to parse context-free grammars. Extremely intricate and feature-rich patterns cause people to make mistakes, and end up with security holes!

    That being said, I really enjoy NeoVim’s regex. I also like Perl’s. But I would not rely on them for parsing, or even lexing.




















  • I really recommend creating a compiler or an interpreter from scratch, don’t even use an IR like LLVM or MIR. Just hack and slash your way though a C compiler, it’s the simplest language most people know. Don’t care about ‘optimization’ at first, fuck optimization. Just grab Yacc/Lex or a PEG parser generator that works with the language you like most and have ot generate assembly code for simple expressions. Like, make a bc(1) native compiler! Interprets are fun too. You can use VMGEN to generate a superfast VM in C, and then bind it to another language using SWIG.
    Also never imagine usability. Noobdy is going to use your C compiler for any serious work. It’s just for education. Post it online to receive feedback.

    You cna start by writing DSLs. For example, I am implementing the ASDL language from this old paper.

    Also if you are going to do it as an example in your resume, just stop. Nobody cares, because it’s a trivial task to write a compiler, even if you write backend, forntned, and the LP yourself! Do something money-loving people loike, like making some bullshit mobile app that tracks your gym sweat volume.