1 /*===-- FileLexer.l - Scanner for TableGen Files ----------------*- C++ -*-===//
4 //===------------------------------------------------------------------------=*/
9 %option never-interactive
14 %option outfile="Lexer.cpp"
23 typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
24 #include "FileParser.h"
26 // ParseInt - This has to handle the special case of binary numbers 0b0101
27 static int ParseInt(const char *Str) {
28 if (Str[0] == '0' && Str[1] == 'b')
29 return strtol(Str+2, 0, 2);
30 return strtol(Str, 0, 0);
33 static int CommentDepth = 0;
39 Identifier [a-zA-Z_][0-9a-zA-Z_]*
40 Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+
45 {Comment} { /* Ignore comments */ }
50 string { return STRING; }
53 class { return CLASS; }
55 field { return FIELD; }
59 {Identifier} { Filelval.StrVal = new std::string(yytext, yytext+yyleng);
62 {StringVal} { Filelval.StrVal = new std::string(yytext+1, yytext+yyleng-1);
65 {Integer} { Filelval.IntVal = ParseInt(Filetext); return INTVAL; }
67 [ \t\n]+ { /* Ignore whitespace */ }
68 . { return Filetext[0]; }
71 "/*" { BEGIN(comment); CommentDepth++; }
72 <comment>[^*/]* /* eat anything that's not a '*' or '/' */
73 <comment>"*"+[^*/]* /* eat up '*'s not followed by '/'s */
74 <comment>"/*" { ++CommentDepth; }
75 <comment>"/"+[^*]* /* eat up /'s not followed by *'s */
76 <comment>"*"+"/" { if (!--CommentDepth) { BEGIN(INITIAL); } }
77 <comment><<EOF>> { fprintf(stderr, "Unterminated comment!\n"); abort(); }