?? ccc_1.l
字號:
/* subset of c, lex grammer. */
/* version 0.01 */
/* chenhongyu. 2004-9-16 */
%{
#include "lang.tab.h"
#include <string.h>
#include "memory.h"
#include "error.h"
extern int lineno;
int commentDepth=0;
%}
%x commentsc
%%
<commentsc>{
\n lineno++;
"*/" { commentDepth--; if (commentDepth == 0) BEGIN(INITIAL);}
"/*" commentDepth++;
"//"[^\n]* /* Single line comments take precedence over multilines */;
<<EOF>> yyerror("Unclosed comment.");
[^*/\n]* /* ignore anything thats not a '*' or '/' to increase speed */;
. /* ignore (multiline comments)*/;
}
[ \t]+ /* ignore */;
"/*" { commentDepth++; BEGIN(commentsc);}
\n lineno++;
"//"[^\n]* /* ignore (singleline comment)*/;
bool return tBOOL;
else return tELSE;
for return tFOR;
if return tIF;
int return tINT;
return return tRETURN;
string return tSTRING;
void return tVOID;
while return tWHILE;
"&&" return tAND;
"==" return tEQUALS;
">=" return tGEQUALS;
"<=" return tLEQUALS;
"!=" return tNEQUALS;
"||" return tOR;
"=" return '=';
">" return '>';
"<" return '<';
"!" return '!';
"+" return '+';
"-" return '-';
"*" return '*';
"/" return '/';
"%" return '%';
"{" return '{';
"}" return '}';
";" return ';';
"(" return '(';
")" return ')';
"," return ',';
0|([1-9][0-9]*) { yylval.intconst = atoi(yytext);
return tINTCONST; }
true { yylval.boolconst = 1;
return tBOOLCONST; }
false { yylval.boolconst = 0;
return tBOOLCONST; }
\"[^\"\n]*\" { yytext[strlen(yytext)-1]='\0'; /* remove "'s from yytext */
yylval.stringconst = strdup(yytext+1);
return tSTRINGCONST; }
[A-Za-z_][A-Za-z0-9_]* { yylval.identifier = strdup(yytext);
return tIDENTIFIER; }
. yyerror("Invalid character '%s'.", yytext);
%%
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -