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