⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idl.ll

📁 编译工具
💻 LL
📖 第 1 页 / 共 2 页
字号:
}{STR} {  yytext[yyleng-1] = '\0';  yylval.string_val = escapedStringToString(yytext + 1);  return STRING_LITERAL;}L{STR} {  yytext[yyleng-1] = '\0';  yylval.wstring_val = escapedStringToWString(yytext + 2);  return WIDE_STRING_LITERAL;}{DECDIGIT}+"."{DECDIGIT}*[dD] {  yylval.fixed_val = new IDL_Fixed(yytext, currentFile, yylineno);  return FIXED_PT_LITERAL;}{DECDIGIT}*"."{DECDIGIT}+[dD] {  yylval.fixed_val = new IDL_Fixed(yytext, currentFile, yylineno);  return FIXED_PT_LITERAL;}{DECDIGIT}+[dD] {  yylval.fixed_val = new IDL_Fixed(yytext, currentFile, yylineno);  return FIXED_PT_LITERAL;}"//".*\n { Comment::add(yytext, currentFile, yylineno-1); }"/*" {  Comment::add(yytext, currentFile, yylineno);  BEGIN(comment);}<comment>[^*\n]*      { Comment::append(yytext); }<comment>"*"+[^*/\n]* { Comment::append(yytext); }<comment>\n           { Comment::append(yytext); }<comment>"*"+"/"      { Comment::append(yytext); BEGIN(INITIAL); }"__omni_pragma"{WS}+ {  BEGIN(omni_pragma);  return OMNI_PRAGMA;}<omni_pragma>{WS}+"__omni_endpragma" {  BEGIN(INITIAL);  return END_PRAGMA;}<omni_pragma>[^ \t\v\n\f\r]+ {  yylval.string_val = idl_strdup(yytext);  return UNKNOWN_PRAGMA_BODY;}<omni_pragma>{WS}+ {  yylval.string_val = idl_strdup(yytext);  return UNKNOWN_PRAGMA_BODY;}^{SPACE}*#{SPACE}*pragma{SPACE}*prefix{SPACE}* {  BEGIN(known_pragma);  return PRAGMA_PREFIX;}^{SPACE}*#{SPACE}*pragma{SPACE}*ID{SPACE}* {  BEGIN(known_pragma);  return PRAGMA_ID;}^{SPACE}*#{SPACE}*pragma{SPACE}*version{SPACE}* {  BEGIN(known_pragma);  return PRAGMA_VERSION;}<known_pragma>{SPACE}+ { /* Eat spaces and tabs */ }^{SPACE}*#{SPACE}*pragma{SPACE}* {  BEGIN(unknown_pragma);  return PRAGMA;}<unknown_pragma>([^\\\n\r]|(\\[^\n\r]))+ {  yylval.string_val = idl_strdup(yytext);  return UNKNOWN_PRAGMA_BODY;}<INITIAL,known_pragma,unknown_pragma>\\(\n|(\r\n)) {  /* Continue line if it ends with \ */}<known_pragma,unknown_pragma>\n|(\r\n) {  BEGIN(INITIAL);  return END_PRAGMA;}^{SPACE}*#{SPACE}*{DECDIGIT}+{SPACE}+{STR}{SPACE}+{DECDIGIT}*{SPACE}*\n {  parseLineDirective(yytext);}^{SPACE}*#{SPACE}*{DECDIGIT}+{SPACE}+{STR}{SPACE}*\n {  parseLineDirective(yytext);}^{SPACE}*#{SPACE}*{DECDIGIT}{SPACE}*\n {  parseLineDirective(yytext);}<INITIAL>{WS} { /* Eat white space */ }. {  return yytext[0];}%%char octalToChar(char* s) {  unsigned long ret = strtoul(s+1, 0, 8);  if (ret > 255) {    IdlError(currentFile, yylineno, "Octal character value '%s' too big", s);  }  return ret;}char hexToChar(char* s)  {  unsigned long ret = strtoul(s+2, 0, 16);  return ret;}char escapeToChar(char* s) {  switch (s[1]) {  case 'n':  return '\n';  case 't':  return '\t';  case 'v':  return '\v';  case 'b':  return '\b';  case 'r':  return '\r';  case 'f':  return '\f';  case 'a':  return '\a';  case '\\': return '\\';  case '?':  return '?';  case '\'': return '\'';  case '\"': return '\"';  }  IdlWarning(currentFile, yylineno,	     "Behaviour for escape sequence '%s' is undefined by IDL; "	     "using '%c'", s, s[1]);  return s[1];}IDL_UShort octalToWChar(char* s) {  unsigned long ret = strtoul(s+1, 0, 8);  if (ret > 255) { // This really is meant to be 255    IdlError(currentFile, yylineno, "Octal character value '%s' too big", s);  }  return ret;}IDL_UShort hexToWChar(char* s) {  unsigned long ret = strtoul(s+2, 0, 16);  return ret;}IDL_UShort escapeToWChar(char* s) {  switch (s[1]) {  case 'n':  return '\n';  case 't':  return '\t';  case 'v':  return '\v';  case 'b':  return '\b';  case 'r':  return '\r';  case 'f':  return '\f';  case 'a':  return '\a';  case '\\': return '\\';  case '?':  return '?';  case '\'': return '\'';  case '\"': return '\"';  }  IdlWarning(currentFile, yylineno,	     "Behaviour for escape sequence '%s' is undefined by IDL; "	     "using '%c'.", s, s[1]);  return s[1];}char* escapedStringToString(char* s) {  int   len = strlen(s);  char* ret = new char[len+1];  char  tmp[8];  int from, to, i;  for (from=0, to=0; from < len; from++, to++) {    if (s[from] == '\\') {      tmp[0] = s[from++];      if ('0' <= s[from] && s[from] <= '7') {	// Octal	for (i=1;	     i < 4 && from < len && '0' <= s[from] && s[from] <= '7';	     from++, i++) tmp[i] = s[from];	tmp[i]  = '\0';	ret[to] = octalToChar(tmp);	from--;      }      else if (s[from] == 'x') {	// Hex	tmp[1] = s[from++];	for (i=2; i < 4 && from < len && isxdigit(s[from]); from++, i++)	  tmp[i] = s[from];	tmp[i]  = '\0';	ret[to] = hexToChar(tmp);	from--;      }      else if (s[from] == 'u') {	// Wide hex not allowed	IdlError(currentFile, yylineno,		 "\\u may only be used in wide characters and strings");	ret[to] = '!';      }      else {	tmp[1]  = s[from];	tmp[2]  = '\0';	ret[to] = escapeToChar(tmp);      }      if (ret[to] == '\0') {	IdlError(currentFile, yylineno, "String cannot contain \\0");	ret[to] = '!';      }    }    else ret[to] = s[from];  }  ret[to] = '\0';  return ret;}IDL_UShort* escapedStringToWString(char* s) {  int         len = strlen(s);  IDL_UShort* ret = new IDL_UShort[len+1];  char        tmp[8];  int from, to, i;  for (from=0, to=0; from < len; from++, to++) {    if (s[from] == '\\') {      tmp[0] = s[from++];      if ('0' <= s[from] && s[from] <= '7') {	// Octal	for (i=1;	     i < 4 && from < len && '0' <= s[from] && s[from] <= '7';	     from++, i++) tmp[i] = s[from];	tmp[i]  = '\0';	ret[to] = octalToWChar(tmp);	from--;      }      else if (s[from] == 'x') {	// Hex	tmp[1] = s[from++];	for (i=2; i < 4 && from < len && isxdigit(s[from]); from++, i++)	  tmp[i] = s[from];	tmp[i]  = '\0';	ret[to] = hexToWChar(tmp);	from--;      }      else if (s[from] == 'u') {	// Wide hex	tmp[1] = s[from++];	for (i=2; i < 6 && from < len && isxdigit(s[from]); from++, i++)	  tmp[i] = s[from];	tmp[i]  = '\0';	ret[to] = hexToWChar(tmp);	from--;      }      else {	tmp[1]  = s[from];	tmp[2]  = '\0';	ret[to] = escapeToWChar(tmp);      }      if (ret[to] == 0) {	IdlError(currentFile, yylineno,		 "Wide string cannot contain wide character zero");	ret[to] = '!';      }    }    else      ret[to] = s[from];  }  ret[to] = 0;  return ret;}void parseLineDirective(char* s) {  char* file    = new char[strlen(s) + 1];  long int line = 0, mode = 0;  int cnt       = sscanf(s, "# %ld \"%[^\"]\" %ld", &line, file, &mode);  assert(cnt >= 1);  if (cnt > 1) {    if (cnt == 3) {      if (mode == 1) {	// New #included file	++nestDepth;	mainFile = 0;	Prefix::newFile();      }      else if (mode == 2) {	// Return from #include	if (--nestDepth == 0) mainFile = 1;	Prefix::endFile();      }    }    delete [] currentFile;    // cccp escapes \ characters, so use the normal string parser    currentFile = escapedStringToString(file);    delete [] file;    if (mainFile)      AST::tree()->setFile(currentFile);  }  yylineno = line;}

⌨️ 快捷键说明

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