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#include <string> 20 21#include "expr.h" 22#include "yydefs.h" 23#include "parser.h" 24 25int gLine = 1; 26int gColumn = 1; 27int gPos = 0; 28 29std::string string_buffer; 30 31#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \ 32 gColumn+=yyleng; gPos+=yyleng;} while(0) 33 34%} 35 36%x STR 37 38%option noyywrap 39 40%% 41 42 43\" { 44 BEGIN(STR); 45 string_buffer.clear(); 46 yylloc.start = gPos; 47 ++gColumn; 48 ++gPos; 49} 50 51<STR>{ 52 \" { 53 ++gColumn; 54 ++gPos; 55 BEGIN(INITIAL); 56 yylval.str = strdup(string_buffer.c_str()); 57 yylloc.end = gPos; 58 return STRING; 59 } 60 61 \\n { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\n'); } 62 \\t { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\t'); } 63 \\\" { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\"'); } 64 \\\\ { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\\'); } 65 66 \\x[0-9a-fA-F]{2} { 67 gColumn += yyleng; 68 gPos += yyleng; 69 int val; 70 sscanf(yytext+2, "%x", &val); 71 string_buffer.push_back(static_cast<char>(val)); 72 } 73 74 \n { 75 ++gLine; 76 ++gPos; 77 gColumn = 1; 78 string_buffer.push_back(yytext[0]); 79 } 80 81 . { 82 ++gColumn; 83 ++gPos; 84 string_buffer.push_back(yytext[0]); 85 } 86} 87 88if ADVANCE; return IF; 89then ADVANCE; return THEN; 90else ADVANCE; return ELSE; 91endif ADVANCE; return ENDIF; 92 93[a-zA-Z0-9_:/.]+ { 94 ADVANCE; 95 yylval.str = strdup(yytext); 96 return STRING; 97} 98 99\&\& ADVANCE; return AND; 100\|\| ADVANCE; return OR; 101== ADVANCE; return EQ; 102!= ADVANCE; return NE; 103 104[+(),!;] ADVANCE; return yytext[0]; 105 106[ \t]+ ADVANCE; 107 108(#.*)?\n gPos += yyleng; ++gLine; gColumn = 1; 109 110. return BAD; 111