联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2022-11-28 11:11

LAB 1

Design and implementation of a lexical analyser

Your name and ID

一、Purpose

Design and implement a Lexical analyser using regular grammar.

Create rules which can be used in one language subset.

Symbol needed be designed in your LA. Reserve words includes like:

int, float, double, if, else, for, do, while, etc……

二、Design instructions

1. Please supplement reserve words using in the language.

2. The language is not sensitive to uppercase and lowercase.

3. The identifiers defined are not longer than 32bytes.

4. The characters are “a-z” “A-Z”, numbers are 0-9.

5. The rules showed below as examples can be extended and modified.

6. /*……*/ and // are the comments of the program.

7. The platforms we can use could be c, Java, Lex, yacc, LLVM, GCC.

8. Print the output of Tokens and report the errors.

三、Design requirements

1. Output <number, type> for each kind of token. <number> is the type

you defined and <type> is the class of the token.

2. LA is designed as one pass, the output is a middle file consists of twotuple sequence.

3. Two test cases are needed to test the program function: one reportsthe

errors found in the program.

四、Functions

Through regular grammar analyzing, the LA program completes the

recognition of the symbols in the input file, including reserved words,

identifiers and some other functional symbols, also the comments. The LA

program is needed to find errorsin the source program and report the line

and type of the errors.

The following rules are some examples of describing C language subset

using Regular Grammar. Supplement symbols is not included in these rules.

The students are asked to rewrite the rules according to their designs.

+=, -=, *=, /=, && (and), ||(or).

<identifier> → character ︱<identifier>character ︱<identifier>number

<unsigned> → number ︱<unsigned>number

<single delimiter> → * ︱;︱, ︱( ︱) ︱{ ︱}

<double delimiter> → <greater than>= ︱<less than>= ︱<not equal>= ︱<equal>= ︱

<plus>+ ︱<minus>- ︱ <slash>/

<less than> → <

<equal> → =

<greater than> → >

<slash> → /

<plus> → +

<minus> → -

<logic not> → !

[some example categories are shown below]

#define ERROR 0

#define INTT 1

……

#define IF 3

#define ELSE 4

……

#define ID 5

#define LT 6 //<

……

#define SR 132 //>>

#define EQUU 133 // ==

……


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp