blob: 7289ca0bbba1bafa42e8fa84787f7a8179fb775a [file] [log] [blame]
Chris Lattnere62c1182002-12-02 01:23:04 +00001/*===-- 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
Chris Lattnerd33b8db2003-07-30 19:39:36 +000019%x comment
Chris Lattnere62c1182002-12-02 01:23:04 +000020
21%{
22#include "Record.h"
23typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
24#include "FileParser.h"
25
26// ParseInt - This has to handle the special case of binary numbers 0b0101
27static 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);
31}
32
Chris Lattnerd33b8db2003-07-30 19:39:36 +000033static int CommentDepth = 0;
34
Chris Lattnere62c1182002-12-02 01:23:04 +000035%}
36
37Comment \/\/.*
38
39Identifier [a-zA-Z_][0-9a-zA-Z_]*
40Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+
41StringVal \"[^"]*\"
42
43%%
44
45{Comment} { /* Ignore comments */ }
46
47int { return INT; }
48bit { return BIT; }
49bits { return BITS; }
50string { return STRING; }
51list { return LIST; }
52
53class { return CLASS; }
54def { return DEF; }
55field { return FIELD; }
56set { return SET; }
57in { return IN; }
58
59{Identifier} { Filelval.StrVal = new std::string(yytext, yytext+yyleng);
60 return ID; }
61
62{StringVal} { Filelval.StrVal = new std::string(yytext+1, yytext+yyleng-1);
63 return STRVAL; }
64
65{Integer} { Filelval.IntVal = ParseInt(Filetext); return INTVAL; }
66
67[ \t\n]+ { /* Ignore whitespace */ }
68. { return Filetext[0]; }
Chris Lattnerd33b8db2003-07-30 19:39:36 +000069
70
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(); }
78
Chris Lattnere62c1182002-12-02 01:23:04 +000079%%