Chris Lattner | e62c118 | 2002-12-02 01:23:04 +0000 | [diff] [blame^] | 1 | /*===-- FileLexer.l - Scanner for TableGen Files ----------------*- C++ -*-===// |
| 2 | // |
| 3 | // |
| 4 | //===------------------------------------------------------------------------=*/ |
| 5 | |
| 6 | %option prefix="File" |
| 7 | %option yylineno |
| 8 | %option nostdinit |
| 9 | %option never-interactive |
| 10 | %option batch |
| 11 | %option noyywrap |
| 12 | %option nodefault |
| 13 | %option 8bit |
| 14 | %option outfile="Lexer.cpp" |
| 15 | %option ecs |
| 16 | %option noreject |
| 17 | %option noyymore |
| 18 | |
| 19 | |
| 20 | %{ |
| 21 | #include "Record.h" |
| 22 | typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy; |
| 23 | #include "FileParser.h" |
| 24 | |
| 25 | // ParseInt - This has to handle the special case of binary numbers 0b0101 |
| 26 | static int ParseInt(const char *Str) { |
| 27 | if (Str[0] == '0' && Str[1] == 'b') |
| 28 | return strtol(Str+2, 0, 2); |
| 29 | return strtol(Str, 0, 0); |
| 30 | } |
| 31 | |
| 32 | %} |
| 33 | |
| 34 | Comment \/\/.* |
| 35 | |
| 36 | Identifier [a-zA-Z_][0-9a-zA-Z_]* |
| 37 | Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+ |
| 38 | StringVal \"[^"]*\" |
| 39 | |
| 40 | %% |
| 41 | |
| 42 | {Comment} { /* Ignore comments */ } |
| 43 | |
| 44 | int { return INT; } |
| 45 | bit { return BIT; } |
| 46 | bits { return BITS; } |
| 47 | string { return STRING; } |
| 48 | list { return LIST; } |
| 49 | |
| 50 | class { return CLASS; } |
| 51 | def { return DEF; } |
| 52 | field { return FIELD; } |
| 53 | set { return SET; } |
| 54 | in { return IN; } |
| 55 | |
| 56 | {Identifier} { Filelval.StrVal = new std::string(yytext, yytext+yyleng); |
| 57 | return ID; } |
| 58 | |
| 59 | {StringVal} { Filelval.StrVal = new std::string(yytext+1, yytext+yyleng-1); |
| 60 | return STRVAL; } |
| 61 | |
| 62 | {Integer} { Filelval.IntVal = ParseInt(Filetext); return INTVAL; } |
| 63 | |
| 64 | [ \t\n]+ { /* Ignore whitespace */ } |
| 65 | . { return Filetext[0]; } |
| 66 | %% |