⇦ Ramen Development_

Lexical analyzer automaton

Cover Image for Lexical analyzer automaton

What is a lexical analyzer and where it is used?

A lexical analyzer is in charge of reading all the characters in a string, verifying and assigning its id, and creating a list of tokens. It would be used in a compiler, but it can be used wherever you need to recognize some characters.

Automaton

From Google, Automaton: “a machine that performs a function according to a predetermined set of coded instructions, especially one capable of a range of programmed responses to different circumstances.” Our task needs to be programmed to respond to different circumstances, or in our case, conditions.

What do we need to do?

Disclaimer: This is an example, the values can be adapted to your code or your goals. Our algorithm will be simple, its just a "conditions machine", being our first condition 0, then will be other conditions to recognize a character or a string and assign its token, and the condition 20 will be accepted, once its accepted, the token will be added to a list of all the tokens (This list may change depending on your code, it can be just values, a class, or an array, but mostly you will have to save the character or string and the token that may be a number) then, it returns to the condition 0 and it reads the next character, this will be a loop until there are no more characters.

Lexical 1.- Automaton algorithm. (Example)

This way, following the algorithm, inside a while that reads all the characters, some if/else, you will have your lexical analyzer and your final list of tokens.

More entries

Cover Image for How I translated my portfolio with JavaScript and JSON

How I translated my portfolio with JavaScript and JSON

I didn't want to get into any extra trouble on my personal portfolio to have it ready a bit faster and try something new. So, I came up with a straightforward solution using only JavaScript. Let's get into it.

Ivan Orozco
Ivan Orozco
Cover Image for Flags to represent languages?

Flags to represent languages?

Should I use the flags of the countries with the most population speaking that language? what’s the best way to design the options for language switching?

Ivan Orozco
Ivan Orozco
Cover Image for Coding with emojis?

Coding with emojis?

Emojis are truly useful in some cases, they can add emotions to our messages so their true meaning doesn't fly over our recipient's head, but should we use them for coding?

Ivan Orozco
Ivan Orozco
Cover Image for Easy Simple Job backstory

Easy Simple Job backstory

The story behind our game isn´t complicated, inspired by a video narrating a story on Reddit that tells about a guy that gets a simple but suspicious job in an office, and certain scary things happen.

Ramen Development Team
Ramen Development Team
Cover Image for Dear LinkedIn recruiters...

Dear LinkedIn recruiters...

It is important for recruiters to take the time to review a candidate's profile before sending a job offer.

Ivan Orozco
Ivan Orozco
Cover Image for Lexical analyzer automaton

Lexical analyzer automaton

In this article you will understand how to code your own lexical analyzer.

Gustavo Padilla
Gustavo Padilla