%{ #include #include "types.h" #include "symtab.h" #include "mtcpars.h" #include "thunk.h" typedef struct _FR { int LineNo; FILE *pfhFile; char *pszFileName; struct _FR *pPreviousFile; } FileRecord; FileRecord *FileList = NULL; static iCommentNesting = 0; %} Alpha ([a-zA-Z_]+) Numeric ([0-9]+) HexValue ([0-9a-fA-F]+) Ident ([a-zA-Z_][a-zA-Z_0-9]*) QString (\"[^"\n]*\") AString (\<[^>\n]*\>) %Start Normal EatComment LookFilename HexNum %% "far16" return(syFar16); "near32" return(syNear32); "*" return(syPtr); "API16" return(syAPI16); "API32" return(syAPI32); "unsigned" return(syUnsigned); "signed" return(sySigned); "long" return(syLong); "short" return(syShort); "int" return(syInt); "typedef" return(syTypeDef); "thunk" return(syMakeThunk); "sizeof" return(sySizeOf); "countof" return(syCountOf); "input" return(syInput); "inout" return(syInOut); "output" return(syOutput); "struct" return(syStruct); "string" return(syString); "passifhinull" return(syPassIfHiNull); "special" return(sySpecial); "maptoretval" return(syMapToRetval); "reverserc" return(syReverseRC); "localheap" return(syLocalHeap); "void" return(syVoid); "char" return(syChar); "nulltype" return(syNullType); "newelem" return(syNewElem); "errnomem" return(syErrNoMem); "errbadparam" return(syErrBadParam); "errunknown" return(syErrUnknown); "true" return(syTrue); "false" return(syFalse); "stack" return(syStack); "inline" return(syInline); "truncation" return(syTruncation); "enablemapdirect1632" return(syEnableMapDirect1632); "user" return(syUser); "gdi" return(syGdi); "kernel" return(syKernel); "syscall" return(sySysCall); "conforming" return(syConforming); "byte" return(syByte); "word" return(syWord); "dword" return(syDWord); "aligned" return(syAligned); "deleted" return(syDeleted); "allow" return(syAllow); "restrict" return(syRestrict); "=>" return(syMapDirect); "=" return(syEqual); "(" return(syLParen); ")" return(syRParen); ";" return(sySemi); "+" return(syPlus); "-" return(syMinus); "/" return(syDiv); "," return(syComma); "{" return(syLBrace); "}" return(syRBrace); "[" return(syLBrack); "]" return(syRBrack); "#include" { BEGIN LookFilename; } {Ident} { yylval.ident = typ_DupString(yytext); return(syIdent); } "0x" { BEGIN HexNum; } {HexValue} { sscanf(yytext,"%lx",&yylval.longval); BEGIN Normal; return(syNumber); } . { return(syError); } {Numeric} { yylval.longval = atoi(yytext); return(syNumber); } [ \t\n] ; "/*" { iCommentNesting++; BEGIN EatComment; } "/*" { iCommentNesting++; } "*/" { if(--iCommentNesting == 0) BEGIN Normal; } [ \t\n] ; . ; {QString} { PushInclude(yytext); BEGIN Normal; } {AString} { } %% void PushInclude( char *yyFile) { FILE *filePtr; FileRecord *pTemp; yyFile[yyleng-1] = '\0'; /* Remove Ending quote */ yyFile++; /* Skip first quote */ if(pTemp = (FileRecord *) malloc(sizeof(FileRecord))) { pTemp->LineNo = yylineno; pTemp->pfhFile = yyin; /* if((pTemp->fhFile=dup(0)) < 0) fatal("PushInclude: Out of file handles"); */ pTemp->pszFileName = yyinname; /* if(close(0)) fatal("PushInclude close 0 failed"); */ pTemp->pPreviousFile = FileList; FileList = pTemp; } else { fatal("PushInclude malloc failure"); } filePtr = fopen(yyFile, "r"); if (filePtr == NULL) { fatal("fopen(%s): Could not open file ",yyFile); } yyin = filePtr; yylineno = 0; yyinname = typ_DupString(yyFile); } void LookNormal( void) { BEGIN Normal; } int yywrap( void) { FileRecord *pTemp; if(!FileList) return 1; /* Close current file */ if( fclose( yyin)) fatal( "yywrap close yyin failed"); /***** if(dup2(FileList->fhFile,0)) fatal( "yywrap dup failure"); if(close(FileList->fhFile)) fatal( "yywrap close %d failure", FileList->fhFile); *****/ yyin = FileList->pfhFile; yylineno = FileList->LineNo; yyinname = FileList->pszFileName; pTemp= FileList; FileList = FileList->pPreviousFile; free( pTemp); return 0; }