如何识别Lex文件中的字符串 [英] How to recognize string in Lex file
问题描述
什么样的方法适合识别lex中的字符串.
Hi what would be appropriate to recognize string in a lex.
我已经尝试过
enter code here
import java_cup.runtime.*;
%%
%cup
%line
NUM = [0-9]
ID = [a-zA-Z]
Pun= [:=;#@$^~]
WhiteSpace = [ \t\r\n\f]
SDQuo = [\"]
%%
({SDQuo}+) ({ID}|{NUM})* ({SDQuo}+) { return new Symbol(sym.STR, new String(yytext()));}
,但是宏无法识别. 我一直收到的错误消息是: 处理第一部分-用户代码. 处理第二部分-JLex声明. 处理第三部分-词汇规则. 创建NFA机器表示. 错误:第39行的解析错误. 说明:词法操作开始时缺少大括号. 解析错误.
but the macro fail to be recognized. The error message that I kept getting is: Processing first section -- user code. Processing second section -- JLex declarations. Processing third section -- lexical rules. Creating NFA machine representation. Error: Parse error at line 39. Description: Missing brace at start of lexical action. Parse error.
推荐答案
在NUM
等的定义中松开=
符号,不要将它们放在%%
之间.而是将最后一个规则放在%%
之间.
Loose the =
signs in the definitions of NUM
etc. and don't place them between %%
. Instead place the last rule between %%
.
这篇关于如何识别Lex文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!