⇦ Ramen Development_

How to create a Syntax analyzer

Cover Image for How to create a Syntax analyzer

Disclaimer: You will need some knowledge of compiler, LR Analyzer, and grammar rules to understand this article.

What is a syntax analyzer and where it is used?

For a crash course, a syntax analyzer is part of the compiler, it is in charge of checking all words and characters in the program and making sure that everything has sense and is in its place. This is done by checking some language rules and making sure it accomplishes every rule that starts.

Where to begin?

You need to know that a syntax analyzer is the second part of the compiler, this means something is before this, and this is called a lexical analyzer, this just makes sure everything in the program is tokenizable and creates a list of tokens for the syntax analyzer to use it.
Also, you will need two other things, a file or two files where the rules of the grammar are written in plain text, one of all the rules, and the other one is an LR table, where its just numbers, 0 meaning null, positive numbers meaning movement, and negative numbers meaning its a rule.

LR Rules 1.- File of LR Rules with their rule number and number of items to pop (Example)

LR Table 2.- File of LR Table (Example)

Algorithm

First of all, we mentioned we need a list(or QUEUE as referred in the algorithm, because you will always pop the first one) of tokens, we will also need a STACK of integers (or whatever you class using if you wanna return a three, this article DO NOT create a three but its implementable) initialized with a 0 inside, the list of rules file read and in a list of rules, the table file in a bidimensional array.
Now, you can follow this algorithm:

Syntax analyzer algorithm 3.- Syntax analyzer algorithm

This way you just will have two kind or returns, if its accepted or an error, and your syntax analyzer will be ready to read all the programs with the LR table grammar you inserted.

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