You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! Following your guide at https://norasandler.com/2017/11/29/Write-a-Compiler.html, I can't help but get stuck on the first task (creating a simple lex() function); because it talks about creating a lexer using RegEx's, two things which I understand just fine, however it's not made clear the recommended way to go about this. I have done this in the past by looping through each character, appending it to a temporary string until a space, new-line or certain other characters are hit, and checking the string at each step, and I imagine there is a better way to do this using RegEx, but I'm just not seeing it. I have only ever used RegEx's to test if a given string matches the full expression.
A good format to use would be to give the task, then provide an expandable area containing the (or a, or multiple) solution(s) (preferably with code), and instructing the reader to try the task on their own first, and providing a little more insight into how the task should be accomplished.
The text was updated successfully, but these errors were encountered:
Mrs. Sandler provides this tutorial for free and puts her time and effort into providing this great educational ressource. So I think it's just a bit too much work to give this functionality. Aditionally you can always just take a look at her code. That should be the same as seeing the solution.
Anyway: I did it by just defining an Array of RegEx for the different Tokens and then loop over this array to check if any Token is matched at the beginning. If this is the case I remove the text from the beginning of the code and append a token to my token list. In some cases (identifier or intLiteral for example) you might have to do some additional stuff. Feel free to look at my code at https://github.com/Clemens-Dautermann/lcc/blob/master/Compiler/Lexer/Lexer.cs.
Hey! Following your guide at https://norasandler.com/2017/11/29/Write-a-Compiler.html, I can't help but get stuck on the first task (creating a simple lex() function); because it talks about creating a lexer using RegEx's, two things which I understand just fine, however it's not made clear the recommended way to go about this. I have done this in the past by looping through each character, appending it to a temporary string until a space, new-line or certain other characters are hit, and checking the string at each step, and I imagine there is a better way to do this using RegEx, but I'm just not seeing it. I have only ever used RegEx's to test if a given string matches the full expression.
A good format to use would be to give the task, then provide an expandable area containing the (or a, or multiple) solution(s) (preferably with code), and instructing the reader to try the task on their own first, and providing a little more insight into how the task should be accomplished.
The text was updated successfully, but these errors were encountered: