Question

In: Computer Science

create a semantic, syntactic and lexical design for a application your a developing? suppose your a...

create a semantic, syntactic and lexical design for a application your a developing?

suppose your a developing a app for both mac and windows that will help both the pc user to use the same command on both interface.you have to create a semantic, syntatic and lexical design for that app?

Solutions

Expert Solution

Answer:-

Lexical analysis is the very first phase in the compiler designing. It takes the modified source code which is written in the form of sentences. In other words, it helps you to converts a sequence of characters into a sequence of tokens. The lexical analysis breaks this syntax into a series of tokens. It removes any extra space or comment written in the source code.

Programs that perform lexical analysis are called lexical analyzers or lexers. A lexer contains tokenizer or scanner. If the lexical analyzer detects that the token is invalid, it generates an error. It reads character streams from the source code, checks for legal tokens, and pass the data to the syntax analyzer when it demands.

Example

How Pleasant Is The Weather?

See this example; Here, we can easily recognize that there are five words How Pleasant, The, Weather, Is. This is very natural for us as we can recognize the separators, blanks, and the punctuation symbol.

 HowPl easantIs Th ewe ather?

Now, check this example, we can also read this. However, it will take some time because separators are put in the Odd Places. It is not something which comes to you immediately.

In this tutorial, you will learn

  • What is Lexical analysis?
  • Basic Terminologies:
  • Lexical Analyzer Architecture: How tokens are recognized
  • Roles of the Lexical analyzer
  • Lexical Errors
  • Error Recovery in Lexical Analyzer
  • Lexical Analyzer vs. Parser
  • Why separate Lexical and Parser?
  • Advantages of Lexical analysis
  • Disadvantage of Lexical analysis

Basic Terminologies

What's a lexeme?

A lexeme is a sequence of characters that are included in the source program according to the matching pattern of a token. It is nothing but an instance of a token.

What's a token?

The token is a sequence of characters which represents a unit of information in the source program.

What is Pattern?

A pattern is a description which is used by the token. In the case of a keyword which uses as a token, the pattern is a sequence of characters.

Lexical Analyzer Architecture: How tokens are recognized

The main task of lexical analysis is to read input characters in the code and produce tokens.

Lexical analyzer scans the entire source code of the program. It identifies each token one by one. Scanners are usually implemented to produce tokens only when requested by a parser. Here is how this works-

  1. "Get next token" is a command which is sent from the parser to the lexical analyzer.
  2. On receiving this command, the lexical analyzer scans the input until it finds the next token.
  3. It returns the token to Parser.

Lexical Analyzer skips whitespaces and comments while creating these tokens. If any error is present, then Lexical analyzer will correlate that error with the source file and line number.

Roles of the Lexical analyzer

Lexical analyzer performs below given tasks:

  • Helps to identify token into the symbol table
  • Removes white spaces and comments from the source program
  • Correlates error messages with the source program
  • Helps you to expands the macros if it is found in the source program
  • Read input characters from the source program

Example of Lexical Analysis, Tokens, Non-Tokens

Consider the following code that is fed to Lexical Analyzer

#include <stdio.h>
    int maximum(int x, int y) {
        // This will compare 2 numbers
        if (x > y)
            return x;
        else {
            return y;
        }
    }

Examples of Tokens created

Lexeme Token
int Keyword
maximum Identifier
( Operator
int Keyword
x Identifier
, Operator
int Keyword
Y Identifier
) Operator
{ Operator
If Keyword

Examples of Nontokens

Type Examples
Comment // This will compare 2 numbers
Pre-processor directive #include <stdio.h>
Pre-processor directive #define NUMS 8,9
Macro NUMS
Whitespace /n /b /t

Related Solutions

You will design and create your own GUI application for the Bank project. This project should...
You will design and create your own GUI application for the Bank project. This project should be designed and written by Java programming. The requirements of the program: 1. The program will be best implemented as a multi-file program for each class. 2. The parameters and return types of each function and class member should be decided in advance. You may need to add more member variables and functions to the classes than those listed below. Also, you can throws...
Create a simple C++ application that will exhibit concurrencyconcepts. Your application should create two threads...
Create a simple C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0. For your created code, provide a detailed analysis of appropriate concepts that could impact your application. Specifically, address:Performance issues with concurrencyVulnerabilities exhibited with use of stringsSecurity of the data types exhibited.
For the following lexical specification: Give NFA and DFA Using your DFA, Implement a lexical analyzer...
For the following lexical specification: Give NFA and DFA Using your DFA, Implement a lexical analyzer using the state table approach shown in class • keywords: if wh pr • Identifiers. An identifier is a sequence of one or more letters • Integer literals. An integer literal is a sequence of one or more decimal digits. • Any of the following one- or two-character symbols: = ( ) { } / * - + < <= == != • Note...
The application of lexical analysis techniques in text editor You should cover: 1) What is the...
The application of lexical analysis techniques in text editor You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++ application:Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.For your created code, provide a written analysis of appropriate concepts that could impact your application.Please Specifically, Address: Performance Issues with Concurrency Vulnerabilities Exhibited with use of Strings and Security of the Data Types used.
Discuss an actual health care operations application or vision of your application of a process design...
Discuss an actual health care operations application or vision of your application of a process design or redesign to improve quality healthcare, include design principles and a lean philosophy.
The application of lexical analysis techniques in information retrieval system You should cover: 1) What is...
The application of lexical analysis techniques in information retrieval system You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
The application of lexical analysis techniques in spam email detection You should cover: 1) What is...
The application of lexical analysis techniques in spam email detection You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT