tgbascan.ll 1.32 KB
Newer Older
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%option noyywrap
%option prefix="tgbayy"
%option outfile="lex.yy.c"

%{
#include <string>
#include "parsedecl.hh"

#define YY_USER_ACTION \
  yylloc->columns(yyleng);

#define YY_USER_INIT                            \
  do {                                          \
    yylloc->begin.filename = current_file;      \
    yylloc->end.filename = current_file;        \
  } while (0)

#define YY_NEVER_INTERACTIVE 1

static std::string current_file;

%}

eol      \n|\r|\n\r|\r\n

%%

%{
  yylloc->step ();
%}

\"[^\"]*\"		{ 
			  yylval->str = new std::string(yytext + 1, 
			                                yyleng - 2);
	                  return STRING;
		        }

[a-zA-Z][a-zA-Z0-9_]*   {
			  yylval->str = new std::string(yytext);
	                  return IDENT;
		        }

			/* discard whitespace */ 
{eol}			yylloc->lines(yyleng); yylloc->step();
[ \t]+			yylloc->step(); 

.			return *yytext;

%{
  /* Dummy use of yyunput to shut up a gcc warning.  */
  (void) &yyunput;
%}

%%

namespace spot
{
  int
  tgbayyopen(const std::string &name)
  {
    if (name == "-")
      {
        yyin = stdin;
        current_file = "standard input";
      }
    else
      {
        yyin = fopen (name.c_str (), "r");
        current_file = name;
        if (!yyin)
	  return 1;
      }
    return 0;
  }

  void
  tgbayyclose()
  {
    fclose(yyin);
  }
}