aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYing Wang2016-01-11 20:14:17 -0600
committerYing Wang2016-01-11 20:14:17 -0600
commitc8abc4ec45ae9c5310097a02a406cd663e5457ea (patch)
treee210c2265dc0c2d22ccf313a7e83a6db79136126 /edify/lexer.ll
parent6f8b9b60dbf2d73e0ee6e757d565035f017e1ccd (diff)
downloadplatform-bootable-recovery-c8abc4ec45ae9c5310097a02a406cd663e5457ea.tar.gz
platform-bootable-recovery-c8abc4ec45ae9c5310097a02a406cd663e5457ea.tar.xz
platform-bootable-recovery-c8abc4ec45ae9c5310097a02a406cd663e5457ea.zip
Rename .l/.y to .ll/.yy
Now to generate .cpp you need to use .ll/.yy. Bug: 26492989 Change-Id: Ib078e03b3b0758f7a62595c343e52ae856bcb33f
Diffstat (limited to 'edify/lexer.ll')
-rw-r--r--edify/lexer.ll112
1 files changed, 112 insertions, 0 deletions
diff --git a/edify/lexer.ll b/edify/lexer.ll
new file mode 100644
index 00000000..fb2933be
--- /dev/null
+++ b/edify/lexer.ll
@@ -0,0 +1,112 @@
1%{
2/*
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <string.h>
19
20#include "expr.h"
21#include "yydefs.h"
22#include "parser.h"
23
24int gLine = 1;
25int gColumn = 1;
26int gPos = 0;
27
28// TODO: enforce MAX_STRING_LEN during lexing
29char string_buffer[MAX_STRING_LEN];
30char* string_pos;
31
32#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
33 gColumn+=yyleng; gPos+=yyleng;} while(0)
34
35%}
36
37%x STR
38
39%option noyywrap
40
41%%
42
43
44\" {
45 BEGIN(STR);
46 string_pos = string_buffer;
47 yylloc.start = gPos;
48 ++gColumn;
49 ++gPos;
50}
51
52<STR>{
53 \" {
54 ++gColumn;
55 ++gPos;
56 BEGIN(INITIAL);
57 *string_pos = '\0';
58 yylval.str = strdup(string_buffer);
59 yylloc.end = gPos;
60 return STRING;
61 }
62
63 \\n { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\n'; }
64 \\t { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\t'; }
65 \\\" { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\"'; }
66 \\\\ { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\\'; }
67
68 \\x[0-9a-fA-F]{2} {
69 gColumn += yyleng;
70 gPos += yyleng;
71 int val;
72 sscanf(yytext+2, "%x", &val);
73 *string_pos++ = val;
74 }
75
76 \n {
77 ++gLine;
78 ++gPos;
79 gColumn = 1;
80 *string_pos++ = yytext[0];
81 }
82
83 . {
84 ++gColumn;
85 ++gPos;
86 *string_pos++ = yytext[0];
87 }
88}
89
90if ADVANCE; return IF;
91then ADVANCE; return THEN;
92else ADVANCE; return ELSE;
93endif ADVANCE; return ENDIF;
94
95[a-zA-Z0-9_:/.]+ {
96 ADVANCE;
97 yylval.str = strdup(yytext);
98 return STRING;
99}
100
101\&\& ADVANCE; return AND;
102\|\| ADVANCE; return OR;
103== ADVANCE; return EQ;
104!= ADVANCE; return NE;
105
106[+(),!;] ADVANCE; return yytext[0];
107
108[ \t]+ ADVANCE;
109
110(#.*)?\n gPos += yyleng; ++gLine; gColumn = 1;
111
112. return BAD;