急!急!急! 有人肯帮忙我做下列题吗?是国外大学的作业题

xieqq 2007-11-11 09:35:17
A8P3 - 30 marks (LR.java or lr.ss)
Write a Java or Scheme program that reads an LR1 file representing a context-free grammar, an LR(1) machine, and a sequence to be recognized. If the sequence is in the language, output the unindented reversed rightmost derivation, as defined in the cfg-r file format. If the input is not recognized, output "ERROR at k" to standard error, where k is one greater than the number of tokens in the longest correct prefix.
For the sample lr1 file as input, the correct output is:

term id
expr term
term id
expr term
term ( expr )
expr expr - term
term id
expr expr - term
S BOF expr EOF

If you replace the last line of this file by
BOF id - id ) - id EOF
the correct output (to standard error) is
ERROR at 5

You may also test your program with the WL grammar and parse tables, in .lr1 format after adding a sequence to be recognized.
Note that the parsing handout contains LR pseudocode.

A8P4 - 16 marks (WLParse.java or wlparse.ss)
Write a WL parser encapsulated as a Java or Scheme program. The input to your parser is a file representing the sequence of tokens in a WL program, as output by the scanner specified in A6P4.
That is, each token is represented by a line containing the name of the token, followed by a space, followed by the string recognized as the token in the WL source program. Note: Unlike the input of A8P3, the input to your parser in this problem will not have lines containing BOF and EOF at the beginning and end.

If the input represents a syntactically valid WL program, the output from your program should be a .wli file. The format of a .wli represents the derivation and also the recognized token strings.

If the input does not represent a syntactically valid WL program, output "ERROR at k" to System.err where k is one greater the number of tokens in the longest correct prefix of the input (that is, not counting BOF).

The student.cs undergraduate enviroment includes two commands to help you test your parser:

java cs241.WLScan reads a WL program and outputs a token list that may be used as input to your parser;
java cs241.WLICheck displays and verifies the format of a .wli file.
...全文
168 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
malligator 2007-11-29
  • 打赏
  • 举报
回复
:)
daniel_kaka 2007-11-29
  • 打赏
  • 举报
回复
大学编译原理教材上关于LR1语法写得很详细,你可以找找看看,网上这方面的也很多
fu320212253 2007-11-16
  • 打赏
  • 举报
回复
脑壳大

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧