Lex analyzer Programming

profilevt3q58
lexical_analyzer_project.doc

Theory of Programming Languages (CSCI3339)

Programming project — Lexical Analyzer

Objectives of the project

1. To develop your understanding of lexical analyzer in compilers of program languages.

2. To improve you knowledge of Java programming.

Topic of assignment: Lexical analyzer

Write Java programs for a lexical analyzer which can identify the following tokens:

1 INT_LIT: consists of digits

2 ID_CODE: starts with a letter followed by letters and digits, and has a limited length of 10

3 ASSIGN_CODE: =

4 PLUS_CODE: +

5 MINUS_CODE: -

6 DIVISON_CODE: /

7 MULTIP_CODE: *

Programs

You will design two classes:

TestLexAnalyzer: contains main method which performs input/output operations.

LexAnalyzer: contains all the methods related to lexical analysis. Refer to the C programs in the text book for algorithm design.

Input: a string of assignment statement

Output: tokens of each lexeme.

A running example:

Input string:

sum = sum + num;

Output:

Lexeme Token

sum ID_CODE

= ASSIGN_CODE

sum ID_CODE

+ PLUS_CODE

num ID_CODE

Leaning Outcomes

With the completion of the assignment, you would have a better understanding of the concept of lexical analysis of computer programming languages. You would also be able to write Java source code to implement algorithms of medium complexity.