简体   繁体   English

宏包含一个循环

[英]Macro contains a cycle

So I'm trying to make a lexical analyzer for scheme and when I run JFlex to convert the lever.flex file I get an error similar to this one for example:所以我正在尝试为 scheme 制作一个词法分析器,当我运行 JFlex 来转换 lever.flex 文件时,我得到一个类似于这个的错误,例如:

Reading "lexer.flex"

Macro definition contains a cycle.
1 error, 0 warnings.

the macro it's referring to is this one:它所指的宏是这个:

definition = {variable_definition} 
            | {syntax_definition} 
            | \(begin {definition}*\) 
            | \(let-syntax \({syntax_binding}*\){definition}*\) 
            | \(letrec-syntax \({syntax_binding}*\){definition}*\)

all of the macros defined here have been implemented but fro some reason I can't get rid of this error and I don't know why its happening.此处定义的所有宏都已实现,但出于某种原因,我无法摆脱此错误,也不知道为什么会发生这种错误。

A lex/flex/JFlex style "definition" is a macro expansion, as that error message indicates.一个 lex/flex/JFlex 风格的“定义”是一个宏扩展,正如该错误消息所指示的那样。 Recursive macro expansions are impossible, since macro expansion is not conditional;递归宏展开是不可能的,因为宏展开不是有条件的; trying to expand试图扩大

definition = ... \(begin {definition}*\) ...

will result in an infinitely long regular expression.将导致无限长的正则表达式。

Do not mistake a lexical analyser for a general-purpose parser.不要将词法分析器误认为是通用解析器。 A lexical analyser does no more than split an input into individual tokens (or "lexemes"), using regular expressions to identify each token.词法分析器只不过是将输入拆分为单独的标记(或“词素”),使用正则表达式来识别每个标记。 Tokens do not have structure (at least for the purposes of parsing);令牌没有结构(至少出于解析的目的); once a token is identified, it is a single indivisible object.一旦标记被识别,它就是一个不可分割的对象。 If you find yourself writing lexical descriptions which match structured text, you have almost certainly pushed the lexical analysis beyond its limits.如果您发现自己正在编写与结构化文本匹配的词法描述,那么您几乎肯定已经将词法分析推到了极限之外。

Parsers use an algorithm which does allow recursive descriptions (but which has very limited forward lookahead) and which can create a recursive description of the input (such as a parse tree).解析器使用的算法允许递归描述(但前瞻非常有限)并且可以创建输入的递归描述(例如解析树)。

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

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