How to recognize string in Lex file

大兔子大兔子 提交于 2019-12-13 06:11:24

问题


Hi what would be appropriate to recognize string in a lex.

I have already tried

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()));}

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.


回答1:


Loose the = signs in the definitions of NUM etc. and don't place them between %%. Instead place the last rule between %%.



来源:https://stackoverflow.com/questions/16373742/how-to-recognize-string-in-lex-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!