使用C编程语言的词法分析器 [英] Lexical analyzer using C programing languages

查看:95
本文介绍了使用C编程语言的词法分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是为以下编程语言编写词法分析器(扫描仪),考虑以下因素:



保留字和特殊符号:





+ =并且有资格获得

- #ARRAY FORWARD RECORD

*<从重复开始

/>按IF REM

:=<> CASE IMPLEMENTATION RETRY

& < = CONST IMPORT RETURN

。 > = SET中的定义

,.. DIV LOOP THEN

; :DO MOD to

()ELSE MODULE TYPE

[] ELSIF NOT UNTIL

{} END OF VAR

^ |除了或者什么时候

~退出包装

出口指示程序

最终



(*)此语言的每个令牌都有一个标识(代表)编号:



1.每个保留字都有一个唯一的ID号。

2.所有用户定义的名称给定相同的ID号。

3.所有整数都有一个id号。

4.所有真实的都有一个id号。

5.每个特殊符号都有一个id号。 ....等等。



(*)程序的输入是一个表示用户源代码的文本文件。



(*)你的程序输出是:

程序中的一个令牌表显示:



索引,令牌,id-number,令牌类型(保留字,名称,整数,保留等等)。



重要说明:



•仅使用C语言。

•一次读取一个字符以获取令牌,即不使用strtok函数。 br />
•使用CodeBlocks编译和运行程序



我尝试过:



你有2天的时间来解决问题

解决方案

让我谷歌那个。 [ ^ ]

is to write a lexical analyzer (scanner) for the following programming language taking in consideration the following:

Reserved Words and special symbols:


+ = AND FOR QUALIFIED
- # ARRAY FORWARD RECORD
* < BEGIN FROM REPEAT
/ > BY IF REM
:= <> CASE IMPLEMENTATION RETRY
& <= CONST IMPORT RETURN
. >= DEFINITION IN SET
, .. DIV LOOP THEN
; : DO MOD TO
( ) ELSE MODULE TYPE
[ ] ELSIF NOT UNTIL
{ } END OF VAR
^ | EXCEPT OR WHILE
~ EXIT PACKEDSET WITH
EXPORT POINTER PROCEDURE
FINALLY

(*) Every token in this language is given an identification (representation) number:

1. Every reserved word is given a unique id number.
2. All user defined names given the same id number.
3. All integers have an id number.
4. All real have an id number.
5. Every special symbol has an id number. .... and so on.

(*) The input to your program is a text file representing the user’s source code.

(*) The output of your program is :
A table of tokens in the program showing:

index , token , id-number , type of token (reserved word , name , integer, reserved, ... etc).

Important Notes:

• Use only C language.
• Read one character at a time to get the token, that is, do not use the strtok function.
• Use CodeBlocks to compile and run your program

What I have tried:

you have 2 days to solve the problem

解决方案

Let me Google that for you.[^]


这篇关于使用C编程语言的词法分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆