简体   繁体   English

如何在 jflex 上创建一个 lambda 符号?

[英]How to create a lambda symbol at jflex?

I'm doing a syntactic Analixer with jflex + javacup.我正在用 jflex + javacup 做一个句法分析器。 At the .cup gramatic I have this part:在 .cup 语法我有这部分:

   SUBPPARAMLIST ::= lambda | "(" EXPLIST ")"

Where lambda mean nothing (SUBPPARAMLIST can be empty) lambda 没有任何意义(SUBPPARAMLIST 可以为空)

Well, I managed to create all my tokens correctly in my .flex, but I dont know how to create the lambda symbol.好吧,我设法在我的 .flex 中正确创建了所有标记,但我不知道如何创建 lambda 符号。 I hope you guys can help me, let me know if you dont understand my problem我希望你们能帮助我,如果你不明白我的问题,请告诉我


WhatDoIWriteHere{return symbol(sym.lambda);}

The empty production (what you call "lambda") doesn't need a symbol, because it is empty.空的产生式(你称之为“lambda”)不需要符号,因为它是空的。 You express this by a production rule:您可以通过产生式规则表达这一点:

SUBPPARAMLIST ::= lambda | "(" EXPLIST ")" ;
lambda ::=  ;

Quote: Each production in the grammar has a left hand side non-terminal followed by the symbol "::=", which is then followed by a series of zero or more actions, terminal, or non-terminal symbols, followed by an optional contextual precedence assignment, and terminated with a semicolon (;).引用:语法中的每个产生式都有一个左侧非终结符,后跟符号“::=”,然后是一系列零个或多个动作、终结符或非终结符,后跟一个可选的上下文优先级分配,并以分号 (;) 终止。 Note the "...zero or more..."注意“...零个或多个...”

Possibly the grammar parser is also capable of handling this:可能语法解析器也能够处理这个:

SUBPPARAMLIST ::= "(" EXPLIST ")" | ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM