summaryrefslogtreecommitdiffstats
path: root/mcopidl/scanner.ll
blob: bc8f6ae0307599f681d9ce545a57a93080908651 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    /*

    Copyright (C) 1999 Stefan Westerfeld
                       stefan@space.twc.de

    Copyright (C) 1999 Torben Weis <weis@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    */

%{

/*
    This is the lex file for mcopidl. It is based on the dcopidl (kidl)
    lex file, which was written by Torben Weis.
*/

#define YY_NO_UNPUT
#define YY_NEVER_INTERACTIVE 1

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "common.h"

using namespace std;
using namespace Arts;

#ifndef KDE_USE_FINAL
#include "yacc.cc.h"
#endif

extern int idl_line_no;
int comment_mode;

static long ascii_to_longlong( long base, const char *s )
{
  long ll = 0;
  while( *s != '\0' ) {
    char c = *s++;
    if( c >= 'a' )
      c -= 'a' - 'A';
    c -= '0';
    if( c > 9 )
      c -= 'A' - '0' - 10;
    ll = ll * base + c;
  }
  return ll;
}

extern void startInclude(const char *line);
extern void endInclude();

%}

%option noyywrap

/*--------------------------------------------------------------------------*/

Digits                  [0-9]+
Oct_Digit               [0-7]
Hex_Digit               [a-fA-F0-9]
Int_Literal		[1-9][0-9]*
Oct_Literal		0{Oct_Digit}*
Hex_Literal		(0x|0X){Hex_Digit}*
Esc_Sequence1           "\\"[ntvbrfa\\\?\'\"]
Esc_Sequence2           "\\"{Oct_Digit}{1,3}
Esc_Sequence3           "\\"(x|X){Hex_Digit}{1,2}
Esc_Sequence            ({Esc_Sequence1}|{Esc_Sequence2}|{Esc_Sequence3})
Char                    ([^\n\t\"\'\\]|{Esc_Sequence})
Char_Literal            "'"({Char}|\")"'"
String_Literal		\"({Char}|"'")*\"
Float_Literal1		{Digits}"."{Digits}(e|E)("+"|"-")?{Digits}
Float_Literal2		{Digits}(e|E)("+"|"-")?{Digits}
Float_Literal3          {Digits}"."{Digits}
Float_Literal4		"."{Digits}
Float_Literal5		"."{Digits}(e|E)("+"|"-")?{Digits}

/*--------------------------------------------------------------------------*/

Kidl_Identifier	[_a-zA-Z][a-zA-Z0-9_]*

Qualified_Identifier	("::")?[_a-zA-Z](("::")?[a-zA-Z0-9_])*

/*--------------------------------------------------------------------------*/

%%

[ \t]			;
[\n]			{ idl_line_no++; }

"/\*"			{ comment_mode = 1; }
"\*/"			{ if (!comment_mode) { REJECT; } else { comment_mode = 0; } }
[^\n*]*			{ if (!comment_mode) { REJECT; } }
"*"				{ if (!comment_mode) { REJECT; } }

"//"[^\n]*		;

"#startinclude"[^\n]*    { startInclude(yytext); }
"#endinclude"[^\n]* { endInclude(); }


"{"			return T_LEFT_CURLY_BRACKET;
"}"			return T_RIGHT_CURLY_BRACKET;
"("			return T_LEFT_PARANTHESIS;
")"			return T_RIGHT_PARANTHESIS;
"<"			return T_LESS;
">"			return T_GREATER;
","			return T_COMMA;
";"			return T_SEMICOLON;
":"			return T_COLON;
"="			return T_EQUAL;

void		return T_VOID;
byte		return T_BYTE;
long		return T_LONG;
boolean		return T_BOOLEAN;
string		return T_STRING;
object		return T_OBJECT;
struct		return T_STRUCT;
interface	return T_INTERFACE;
module		return T_MODULE;
"enum"		return T_ENUM;
attribute	return T_ATTRIBUTE;
sequence	return T_SEQUENCE;
readonly	return T_READONLY;
in			return T_IN;
out			return T_OUT;
audio		return T_AUDIO;
float		return T_FLOAT;
stream		return T_STREAM;
multi		return T_MULTI;
async		return T_ASYNC;
oneway		return T_ONEWAY;
default		return T_DEFAULT;

{Kidl_Identifier}	{
			  yylval._str = strdup(yytext);		// TAKE CARE: free that thing
			  return T_IDENTIFIER;
			}

{Qualified_Identifier} {
			  yylval._str = strdup(yytext);		// TAKE CARE: free that thing
			  return T_QUALIFIED_IDENTIFIER;
			}

{Int_Literal}		{
			  yylval._int = ascii_to_longlong( 10, yytext );
			  return T_INTEGER_LITERAL;
			}
{Oct_Literal}		{
			  yylval._int = ascii_to_longlong( 8, yytext );
			  return T_INTEGER_LITERAL;
			}
{Hex_Literal}		{
			  yylval._int = ascii_to_longlong( 16, yytext + 2 );
			  return T_INTEGER_LITERAL;
			}

.                       {
                          return T_UNKNOWN;
                        }

%%

void mcopidlInitFlex( const char *_code )
{
   comment_mode = 0;
   yy_switch_to_buffer( yy_scan_string( _code ) );
}