2 #include "Cycript.tab.hh"
3 typedef cy::parser::token tk;
5 #define YY_EXTRA_TYPE CYDriver *
6 #define YYLTYPE cy::location
8 #define T yylval->newline_ = yyextra->state_ == CYNewLine;
9 #define C T yyextra->state_ = CYClear;
10 #define R T yyextra->state_ = CYRestricted;
13 if (yyextra->state_ != CYNewLine) { \
14 bool restricted(yyextra->state_ == CYRestricted); \
16 yyextra->state_ = CYClear; \
19 yyextra->state_ = CYNewLine; \
24 yylloc->columns(yyleng); \
28 if (c >= '0' && c <= '9')
30 if (c >= 'a' && c <= 'f')
32 if (c >= 'A' && c <= 'F')
37 #define YY_INPUT(data, value, size) { \
38 if (yyextra->size_ == 0) \
41 size_t copy(std::min(size, yyextra->size_)); \
42 memcpy(data, yyextra->data_, copy); \
43 yyextra->data_ += copy; \
44 yyextra->size_ -= copy; \
53 %option bison-locations
60 Exponent [eE][+-]?[0-9]+
61 Escape \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
66 \/\*(\n|[^\*]|\*[^/])\*\/ if (memchr(yytext, '\n', yyleng) != NULL) N // XXX: supposedly I will be screwed on very very long multi-line comments and need to replace this with a manual lexer. http://websrv.cs.fsu.edu/~engelen/courses/COP5621/Pr2.pdf ; XXX: this rule doesn't work anyway, fucking A :(
68 "&" L C return tk::Ampersand;
69 "&&" L C return tk::AmpersandAmpersand;
70 "&=" L C return tk::AmpersandEqual;
71 "^" L C return tk::Carrot;
72 "^=" L C return tk::CarrotEqual;
73 "=" L C return tk::Equal;
74 "==" L C return tk::EqualEqual;
75 "===" L C return tk::EqualEqualEqual;
76 "!" L C return tk::Exclamation;
77 "!=" L C return tk::ExclamationEqual;
78 "!==" L C return tk::ExclamationEqualEqual;
79 "-" L C return tk::Hyphen;
80 "-=" L C return tk::HyphenEqual;
81 "--" L C return yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen;
82 "->" L C return tk::HyphenRight;
83 "<" L C return tk::Left;
84 "<=" L C return tk::LeftEqual;
85 "<<" L C return tk::LeftLeft;
86 "<<=" L C return tk::LeftLeftEqual;
87 "%" L C return tk::Percent;
88 "%=" L C return tk::PercentEqual;
89 "." L C return tk::Period;
90 "|" L C return tk::Pipe;
91 "|=" L C return tk::PipeEqual;
92 "||" L C return tk::PipePipe;
93 "+" L C return tk::Plus;
94 "+=" L C return tk::PlusEqual;
95 "++" L C return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus;
96 ">" L C return tk::Right;
97 ">=" L C return tk::RightEqual;
98 ">>" L C return tk::RightRight;
99 ">>=" L C return tk::RightRightEqual;
100 ">>>" L C return tk::RightRightRight;
101 ">>>=" L C return tk::RightRightRightEqual;
102 "/" L C return tk::Slash;
103 "/=" L C return tk::SlashEqual;
104 "*" L C return tk::Star;
105 "*=" L C return tk::StarEqual;
106 "~" L C return tk::Tilde;
108 ":" L C return tk::Colon;
109 "," L C return tk::Comma;
110 "?" L C return tk::Question;
111 ";" L C return tk::SemiColon;
113 "(" L C return tk::OpenParen;
114 ")" L C return tk::CloseParen;
116 "{" L C return tk::OpenBrace;
117 "}" L C return tk::CloseBrace;
119 "[" L C return tk::OpenBracket;
120 "]" L C return tk::CloseBracket;
122 "@class" L C return tk::AtClass;
123 "@end" L C return tk::AtEnd;
124 "@selector" L C return tk::AtSelector;
126 "break" L R yylval->word_ = new CYWord("break"); return tk::Break;
127 "case" L C yylval->word_ = new CYWord("case"); return tk::Case;
128 "catch" L C yylval->word_ = new CYWord("catch"); return tk::Catch;
129 "continue" L R yylval->word_ = new CYWord("continue"); return tk::Continue;
130 "default" L C yylval->word_ = new CYWord("default"); return tk::Default;
131 "delete" L C yylval->word_ = new CYWord("delete"); return tk::Delete;
132 "do" L C yylval->word_ = new CYWord("do"); return tk::Do;
133 "else" L C yylval->word_ = new CYWord("else"); return tk::Else;
134 "false" L C yylval->false_ = new CYFalse(); return tk::False;
135 "finally" L C yylval->word_ = new CYWord("finally"); return tk::Finally;
136 "for" L C yylval->word_ = new CYWord("for"); return tk::For;
137 "function" L C yylval->word_ = new CYWord("function"); return tk::Function;
138 "if" L C yylval->word_ = new CYWord("if"); return tk::If;
139 "in" L C yylval->word_ = new CYWord("in"); return tk::In;
140 "instanceof" L C yylval->word_ = new CYWord("instanceof"); return tk::InstanceOf;
141 "new" L C yylval->word_ = new CYWord("new"); return tk::New;
142 "null" L C yylval->null_ = new CYNull(); return tk::Null;
143 "return" L R yylval->word_ = new CYWord("return"); return tk::Return;
144 "switch" L C yylval->word_ = new CYWord("switch"); return tk::Switch;
145 "this" L C yylval->this_ = new CYThis(); return tk::This;
146 "throw" L R yylval->word_ = new CYWord("throw"); return tk::Throw;
147 "true" L C yylval->true_ = new CYTrue(); return tk::True;
148 "try" L C yylval->word_ = new CYWord("try"); return tk::Try;
149 "typeof" L C yylval->word_ = new CYWord("typeof"); return tk::TypeOf;
150 "var" L C yylval->word_ = new CYWord("var"); return tk::Var;
151 "void" L C yylval->word_ = new CYWord("void"); return tk::Void;
152 "while" L C yylval->word_ = new CYWord("while"); return tk::While;
153 "with" L C yylval->word_ = new CYWord("with"); return tk::With;
155 "abstract" L C yylval->word_ = new CYWord("abstract"); return tk::Abstract;
156 "boolean" L C yylval->word_ = new CYWord("boolean"); return tk::Boolean;
157 "byte" L C yylval->word_ = new CYWord("byte"); return tk::Byte;
158 "char" L C yylval->word_ = new CYWord("char"); return tk::Char;
159 "class" L C yylval->word_ = new CYWord("class"); return tk::Class;
160 "const" L C yylval->word_ = new CYWord("const"); return tk::Const;
161 "debugger" L C yylval->word_ = new CYWord("debugger"); return tk::Debugger;
162 "double" L C yylval->word_ = new CYWord("double"); return tk::Double;
163 "enum" L C yylval->word_ = new CYWord("enum"); return tk::Enum;
164 "export" L C yylval->word_ = new CYWord("export"); return tk::Export;
165 "extends" L C yylval->word_ = new CYWord("extends"); return tk::Extends;
166 "final" L C yylval->word_ = new CYWord("final"); return tk::Final;
167 "float" L C yylval->word_ = new CYWord("float"); return tk::Float;
168 "goto" L C yylval->word_ = new CYWord("goto"); return tk::Goto;
169 "implements" L C yylval->word_ = new CYWord("implements"); return tk::Implements;
170 "import" L C yylval->word_ = new CYWord("import"); return tk::Import;
171 "int" L C yylval->word_ = new CYWord("int"); return tk::Int;
172 "interface" L C yylval->word_ = new CYWord("interface"); return tk::Interface;
173 "long" L C yylval->word_ = new CYWord("long"); return tk::Long;
174 "native" L C yylval->word_ = new CYWord("native"); return tk::Native;
175 "package" L C yylval->word_ = new CYWord("package"); return tk::Package;
176 "private" L C yylval->word_ = new CYWord("private"); return tk::Private;
177 "protected" L C yylval->word_ = new CYWord("protected"); return tk::Protected;
178 "public" L C yylval->word_ = new CYWord("public"); return tk::Public;
179 "short" L C yylval->word_ = new CYWord("short"); return tk::Short;
180 "static" L C yylval->word_ = new CYWord("static"); return tk::Static;
181 "super" L C yylval->word_ = new CYWord("super"); return tk::Super;
182 "synchronized" L C yylval->word_ = new CYWord("synchronized"); return tk::Synchronized;
183 "throws" L C yylval->word_ = new CYWord("throws"); return tk::Throws;
184 "transient" L C yylval->word_ = new CYWord("transient"); return tk::Transient;
185 "volatile" L C yylval->word_ = new CYWord("volatile"); return tk::Volatile;
187 [a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier;
189 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); L C return tk::NumericLiteral;
191 0[xX][0-9a-fA-F]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
193 0[bB][0-1]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 2)); return tk::NumericLiteral;
195 \"([^"\\\n]|{Escape})*\"|'([^'\\\n]|{Escape})*' L C {
196 char *value(reinterpret_cast<char *>(apr_palloc(yyextra->pool_, yyleng)));
199 for (int i(1); i != yyleng - 1; ++i) {
200 char next(yytext[i]);
202 if (yytext[i] == '\\')
203 switch (next = yytext[++i]) {
204 case '\\': next = '\\'; break;
205 case '\'': next = '\''; break;
206 case '"': next = '"'; break;
207 case 'b': next = '\b'; break;
208 case 'f': next = '\f'; break;
209 case 'n': next = '\n'; break;
210 case 'r': next = '\r'; break;
211 case 't': next = '\t'; break;
212 case 'v': next = '\v'; break;
213 case '0': next = '\0'; break;
216 next = H(yytext[i + 1]) << 4 | H(yytext[i + 2]);
225 yylval->string_ = new CYString(value, local - value);
226 return tk::StringLiteral;
229 \n yylloc->end.lines(); yylloc->step(); N
232 <<EOF>> L yyterminate();
235 CYDriver::Error error;
236 error.location_ = *yylloc;
237 error.message_ = "syntax error, unknown token";
238 yyextra->errors_.push_back(error);
244 void CYDriver::ScannerInit() {
245 cylex_init(&scanner_);
246 cyset_extra(this, scanner_);
249 void CYDriver::ScannerDestroy() {
250 cylex_destroy(scanner_);