Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Assignment2的问题 #43

Open
Henryexcellentw opened this issue Sep 23, 2024 · 1 comment
Open

关于Assignment2的问题 #43

Henryexcellentw opened this issue Sep 23, 2024 · 1 comment

Comments

@Henryexcellentw
Copy link

Henryexcellentw commented Sep 23, 2024

1:Step1里的token具体指什么?文档里把identifier和number当做token我没有太理解。
2:lex里的yylval.token、yytext,yyleeng这些东西在哪里定义的?
3:yacc规则里的这个例子我还是没有理解,大括号最上方要出现的东西,如果EXPR:NUMBER表示文法EXPR->NUMBER,那其他复杂一些的文法怎么表示呢?

@idlebo
Copy link
Collaborator

idlebo commented Sep 23, 2024

1:token本来就是比较抽象的概念,可以理解为连接lex和yacc的桥梁(接口)。把identifier和number当做token是为了代码更加简洁,可以考虑如果不将其当作token应该如何编写yacc(这样应该就可以体会到把identifier和number当做token的好处)。
2:上述三个东西并不是自己定义的,而是lex和yacc内置的。
image
关于yylval.token的含义其实在我们的文档中也有说明:
image
所以yylval.token指的就是yylval结构体中的token
3:其实文档中给出的例子还是比较复杂的,文档中完整的例子是:
expr -> number | identifier | (expr + expr) | (expr * expr)
image
(你提出的问题很详细,表述很清楚,但如果能尝试自己在文档中找答案或者上网搜索答案,你会有更多的收获,能力会更上一层楼)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants