yylex

来自「To help you in writing an LL grammar, we」· 代码 · 共 60 行

TXT
60
字号
// LLAnalyze -- Nathaniel Nystrom, February 2000// For use in Cornell University Computer Science 412/413// Lexical specification for grammar files.package Iota.util.grammar;import java.lang.System;%%%{	public int yyline()	{		return yyline;	}%} %line%char%state COMMENTALPHA=[A-Za-z]DIGIT=[0-9]WHITE_SPACE_CHAR=[\r\n\ \t\b\012]COMMENT_TEXT=([^*]|"*"+[^/])*%% <YYINITIAL> ":" { return (new Yytoken(Yytoken.COLON,yyline,yytext())); }<YYINITIAL> ";" { return (new Yytoken(Yytoken.SEMI,yyline,yytext())); }<YYINITIAL> "(" { return (new Yytoken(Yytoken.LPAREN,yyline,yytext())); }<YYINITIAL> ")" { return (new Yytoken(Yytoken.RPAREN,yyline,yytext())); }<YYINITIAL> "[" { return (new Yytoken(Yytoken.LBRACKET,yyline,yytext())); }<YYINITIAL> "]" { return (new Yytoken(Yytoken.RBRACKET,yyline,yytext())); }<YYINITIAL> "|" { return (new Yytoken(Yytoken.OR,yyline,yytext())); }<YYINITIAL> "*" { return (new Yytoken(Yytoken.STAR,yyline,yytext())); }<YYINITIAL> "+" { return (new Yytoken(Yytoken.PLUS,yyline,yytext())); }<YYINITIAL> "%%" { return (new Yytoken(Yytoken.SEPSEP,yyline,yytext())); }<YYINITIAL> "%token" { return (new Yytoken(Yytoken.SEPTOKEN,yyline,yytext())); }<YYINITIAL> "%start" { return (new Yytoken(Yytoken.SEPSTART,yyline,yytext())); }<YYINITIAL> {WHITE_SPACE_CHAR}+ { }<YYINITIAL> "/*" { yybegin(COMMENT); }<COMMENT> "*/" {     		yybegin(YYINITIAL);}<COMMENT> {COMMENT_TEXT} { }<YYINITIAL> {ALPHA}({ALPHA}|{DIGIT}|_)* {	return (new Yytoken(Yytoken.ID,yyline,yytext()));}	<YYINITIAL,COMMENT> . {	throw new RuntimeException(yyline +	    ": Illegal character: <" + yytext() + ">");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?