tokens.l 829 Bytes
Newer Older
Peter Faber's avatar
Peter Faber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%{
#include <cstdio>
#include <string>

 /* Will later be replaced by parser definitions! */
 int yylval;
 enum token_t
  {
    TINT_T = 258,
    TVOID_T = 259,
    TIDENTIFIER = 260,
    TINTEGER = 261,
    TASSIGN = 262,
    TNE = 263,
    TLT = 264,
    TLE = 265,
    TGT = 266,
    TGE = 267,
    TEQ = 268,
    TLPAREN = 269,
    TRPAREN = 270,
    TLBRACE = 271,
    TRBRACE = 272,
    TSEMICOL = 273,
    TCOMMA = 274,
    TPLUS = 275,
    TMINUS = 276,
    TMUL = 277,
    TDIV = 278,
    TRETURN = 279,
    TEXTERN = 280,
    TIF = 281,
    TELSE = 282,
    UMINUS = 283,
    TNONE = 0
};

%}

%option noyywrap
%option yylineno

%%


%%

int main(){
  int token;
  while(TNONE!=(token=yylex())){
    printf("read '%s' of length %d -- which is of type %d (value is %d)\n",yytext,yyleng,token,yylval);
  }
  return 0;
}