编程介的小学生 2017-05-07 09:27 采纳率: 20.5%
浏览 738
已采纳

FORCAL

FORCAL is the programming language well known to programmers who are interested in compiler construction and especially to students attending Dr. C. Ompiler class. The FORCAL syntax is defined as follows:
The only data type is integer.

All identifiers are implicitly declared and are not longer than 32 characters. Identifiers are composed of letters, digits and underscores. At least one character of the identifier is not a digit.

Literals are strings of at most 8 digits.

Comments begin with -- and end at the end of the line in which they start.

Statement types are

Assignment:

identifier := expression

where expressions are constructed from identifiers, literals, operators +, -,

and parentheses as follows:

1) all identifiers and literals are expressions,

2) if a, b are expressions then a + b, a - b, +a, -a, (a) are expressions.

Input/Output:

read(List of identifiers);

write(List of expressions)

(Items in the list are separated by comma)

begin, end, read, and write are reserved words.

Each statement is terminated by a semicolon.

FORCAL is not case-sensitive, for example BegIN is the same keyword as beGin.

FORCAL tokens are defined to be: the identifiers or the literals or the symbols + - ( ) := ; , or the reserved words.

NOTES:

the assign operator is to be considered one FORCAL token,

spaces, tabs, end-of-lines are allowed between the tokens,

no part of any comment is a token,

successive tokens that are either identifiers, literals or reserved words must be separated by a space or tab or end-of-line,

no token is allowed to contain a space or a tab or end-of-line.

Help the students of Dr. C. Ompiler to write a program which reads lines of text an recognizes the FORCAL tokens in them.

Input

The input consists of several blocks of lines. Each block contains lines of text and is terminated by one empty line.

Output

The output consists of blocks corresponding to the blocks in the input. In the lines of each block there are successively stored the FORCAL tokens recognized by the program (just one token on each line). Each token must be written on the output line in exactly the same form as it appears in the input text. If the program encounters a string that is neither a FORCAL token, nor comment, nor space, tab, end-of-line, it is to write the string TOKEN ERROR on a new line and continues by processing the next block in the input. The program writes one empty line after each block of the output.

Sample Input

A1:= A + (-B);

A123_A123 )
01.2 A B
C

:= A beGIn

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Output

A1
:=
A
+

(

B
)
;

A123_A123
)
01
TOKEN ERROR

:=
A
beGIn

TOKEN ERROR

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-23 17:41
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器