blob: c7e4346c0feeed8da9a8665536476b681b572f80 [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
19
20%{
21#include "Record.h"
22typedef 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
26static 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
34Comment \/\/.*
35
36Identifier [a-zA-Z_][0-9a-zA-Z_]*
37Integer [-+]?[0-9]+|0x[0-9a-fA-F]+|0b[01]+
38StringVal \"[^"]*\"
39
40%%
41
42{Comment} { /* Ignore comments */ }
43
44int { return INT; }
45bit { return BIT; }
46bits { return BITS; }
47string { return STRING; }
48list { return LIST; }
49
50class { return CLASS; }
51def { return DEF; }
52field { return FIELD; }
53set { return SET; }
54in { 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%%