DEV Community

Cover image for Lexical Analysis
Martin Corona
Martin Corona

Posted on • Edited on

1

Lexical Analysis

The first phase of a compiler design is called Lexical Analysis or scanner. The Lexical Analysis read the Stream of characters that make up the source of file and group the significative sequences, known as a lexeme.

                          <token class, attribute value>
Enter fullscreen mode Exit fullscreen mode

For example
int doc=8;

Alt Text

Alt Text

In the next table will be the lexemes classes used in the development of the practice.
Alt Text
Alt Text

In the next Figure 1, it shows the first Automata called A1 which recognize identifiers:

Alt Text

The next Figure 2, it shows the Automata A2 which recognize Octal numbers, Hexadecimal number and Real number:

Alt Text

The next Figure 3, it shows the Automata A3 which recognize Delimitation characters, Arithmetic operators, Punctuation marks and Assignment Operator:

Alt Text

The next Figure 4, it shows the Automata A4 comments:

Alt Text

In this automata the number 10 represents New Line in ASCII code.

Conclusions:

As a conclusion, it was difficult to understand and solve the EOF, Blacks and comments. Because when I was using fgetc() function whit a char variable, the char variable was changing it for another number and never reach to EOF. So that was freaking me out but finally I solve it. Sometimes when the lexical analysis read a black it was doing a loop infinite but it was solved. Also, I consider that this practice was a huge challenge, but I made it.

The code: https://github.com/martincorona007/Lexical_analysis

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay