2 #define YYLTYPE cy::location
3 #include "Cycript.tab.hh"
4 typedef cy::parser::token tk;
6 #define YY_EXTRA_TYPE CYDriver *
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->file_ != NULL) { \
39 size_t copy(fread(data, 1, size, yyextra->file_)); \
40 value = copy == 0 ? YY_NULL : copy; \
41 } else if (yyextra->size_ == 0) \
44 size_t copy(std::min(size, yyextra->size_)); \
45 memcpy(data, yyextra->data_, copy); \
46 yyextra->data_ += copy; \
47 yyextra->size_ -= copy; \
56 %option bison-locations
63 Exponent [eE][+-]?[0-9]+
64 Escape \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\\n
69 \/\*(\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 :(
71 "&" L C return tk::Ampersand;
72 "&&" L C return tk::AmpersandAmpersand;
73 "&=" L C return tk::AmpersandEqual;
74 "^" L C return tk::Carrot;
75 "^=" L C return tk::CarrotEqual;
76 "=" L C return tk::Equal;
77 "==" L C return tk::EqualEqual;
78 "===" L C return tk::EqualEqualEqual;
79 "!" L C return tk::Exclamation;
80 "!=" L C return tk::ExclamationEqual;
81 "!==" L C return tk::ExclamationEqualEqual;
82 "-" L C return tk::Hyphen;
83 "-=" L C return tk::HyphenEqual;
84 "--" L C return yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen;
85 "->" L C return tk::HyphenRight;
86 "<" L C return tk::Left;
87 "<=" L C return tk::LeftEqual;
88 "<<" L C return tk::LeftLeft;
89 "<<=" L C return tk::LeftLeftEqual;
90 "%" L C return tk::Percent;
91 "%=" L C return tk::PercentEqual;
92 "." L C return tk::Period;
93 "|" L C return tk::Pipe;
94 "|=" L C return tk::PipeEqual;
95 "||" L C return tk::PipePipe;
96 "+" L C return tk::Plus;
97 "+=" L C return tk::PlusEqual;
98 "++" L C return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus;
99 ">" L C return tk::Right;
100 ">=" L C return tk::RightEqual;
101 ">>" L C return tk::RightRight;
102 ">>=" L C return tk::RightRightEqual;
103 ">>>" L C return tk::RightRightRight;
104 ">>>=" L C return tk::RightRightRightEqual;
105 "/" L C return tk::Slash;
106 "/=" L C return tk::SlashEqual;
107 "*" L C return tk::Star;
108 "*=" L C return tk::StarEqual;
109 "~" L C return tk::Tilde;
111 ":" L C return tk::Colon;
112 "," L C return tk::Comma;
113 "?" L C return tk::Question;
114 ";" L C return tk::SemiColon;
116 "(" L C return tk::OpenParen;
117 ")" L C return tk::CloseParen;
119 "{" L C return tk::OpenBrace;
120 "}" L C return tk::CloseBrace;
122 "[" L C return tk::OpenBracket;
123 "]" L C return tk::CloseBracket;
125 "@class" L C return tk::AtClass;
126 "@end" L C return tk::AtEnd;
127 "@selector" L C return tk::AtSelector;
129 "false" L C yylval->false_ = new CYFalse(); return tk::False;
130 "null" L C yylval->null_ = new CYNull(); return tk::Null;
131 "true" L C yylval->true_ = new CYTrue(); return tk::True;
133 "break" L R yylval->word_ = new CYWord("break"); return tk::Break;
134 "case" L C yylval->word_ = new CYWord("case"); return tk::Case;
135 "catch" L C yylval->word_ = new CYWord("catch"); return tk::Catch;
136 "continue" L R yylval->word_ = new CYWord("continue"); return tk::Continue;
137 "default" L C yylval->word_ = new CYWord("default"); return tk::Default;
138 "delete" L C yylval->word_ = new CYWord("delete"); return tk::Delete;
139 "do" L C yylval->word_ = new CYWord("do"); return tk::Do;
140 "else" L C yylval->word_ = new CYWord("else"); return tk::Else;
141 "finally" L C yylval->word_ = new CYWord("finally"); return tk::Finally;
142 "for" L C yylval->word_ = new CYWord("for"); return tk::For;
143 "function" L C yylval->word_ = new CYWord("function"); return tk::Function;
144 "if" L C yylval->word_ = new CYWord("if"); return tk::If;
145 "in" L C yylval->word_ = new CYWord("in"); return tk::In;
146 "instanceof" L C yylval->word_ = new CYWord("instanceof"); return tk::InstanceOf;
147 "new" L C yylval->word_ = new CYWord("new"); return tk::New;
148 "return" L R yylval->word_ = new CYWord("return"); return tk::Return;
149 "switch" L C yylval->word_ = new CYWord("switch"); return tk::Switch;
150 "this" L C yylval->this_ = new CYThis(); return tk::This;
151 "throw" L R yylval->word_ = new CYWord("throw"); return tk::Throw;
152 "try" L C yylval->word_ = new CYWord("try"); return tk::Try;
153 "typeof" L C yylval->word_ = new CYWord("typeof"); return tk::TypeOf;
154 "var" L C yylval->word_ = new CYWord("var"); return tk::Var;
155 "void" L C yylval->word_ = new CYWord("void"); return tk::Void;
156 "while" L C yylval->word_ = new CYWord("while"); return tk::While;
157 "with" L C yylval->word_ = new CYWord("with"); return tk::With;
159 "debugger" L C yylval->word_ = new CYWord("debugger"); return tk::Debugger;
161 "const" L C yylval->word_ = new CYWord("const"); return tk::Const;
163 "class" L C yylval->word_ = new CYWord("class"); return tk::Class;
164 "enum" L C yylval->word_ = new CYWord("enum"); return tk::Enum;
165 "export" L C yylval->word_ = new CYWord("export"); return tk::Export;
166 "extends" L C yylval->word_ = new CYWord("extends"); return tk::Extends;
167 "import" L C yylval->word_ = new CYWord("import"); return tk::Import;
168 "super" L C yylval->word_ = new CYWord("super"); return tk::Super;
170 "implements" L C yylval->identifier_ = new CYIdentifier("implements"); return tk::Implements;
171 "interface" L C yylval->identifier_ = new CYIdentifier("interface"); return tk::Interface;
172 "package" L C yylval->identifier_ = new CYIdentifier("package"); return tk::Package;
173 "private" L C yylval->identifier_ = new CYIdentifier("private"); return tk::Private;
174 "protected" L C yylval->identifier_ = new CYIdentifier("protected"); return tk::Protected;
175 "public" L C yylval->identifier_ = new CYIdentifier("public"); return tk::Public;
176 "static" L C yylval->identifier_ = new CYIdentifier("static"); return tk::Static;
178 "abstract" L C yylval->identifier_ = new CYIdentifier("abstract"); return tk::Abstract;
179 "boolean" L C yylval->identifier_ = new CYIdentifier("boolean"); return tk::Boolean;
180 "byte" L C yylval->identifier_ = new CYIdentifier("byte"); return tk::Byte;
181 "char" L C yylval->identifier_ = new CYIdentifier("char"); return tk::Char;
182 "double" L C yylval->identifier_ = new CYIdentifier("double"); return tk::Double;
183 "final" L C yylval->identifier_ = new CYIdentifier("final"); return tk::Final;
184 "float" L C yylval->identifier_ = new CYIdentifier("float"); return tk::Float;
185 "goto" L C yylval->identifier_ = new CYIdentifier("goto"); return tk::Goto;
186 "int" L C yylval->identifier_ = new CYIdentifier("int"); return tk::Int;
187 "long" L C yylval->identifier_ = new CYIdentifier("long"); return tk::Long;
188 "native" L C yylval->identifier_ = new CYIdentifier("native"); return tk::Native;
189 "short" L C yylval->identifier_ = new CYIdentifier("short"); return tk::Short;
190 "synchronized" L C yylval->identifier_ = new CYIdentifier("synchronized"); return tk::Synchronized;
191 "throws" L C yylval->identifier_ = new CYIdentifier("throws"); return tk::Throws;
192 "transient" L C yylval->identifier_ = new CYIdentifier("transient"); return tk::Transient;
193 "volatile" L C yylval->identifier_ = new CYIdentifier("volatile"); return tk::Volatile;
195 "let" L C yylval->identifier_ = new CYIdentifier("let"); return tk::Let;
196 "yield" L C yylval->identifier_ = new CYIdentifier("yield"); return tk::Yield;
198 "each" L C yylval->identifier_ = new CYIdentifier("each"); return tk::Each;
200 [a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier_;
202 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); L C return tk::NumericLiteral;
204 0[xX][0-9a-fA-F]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
206 0[bB][0-1]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 2)); return tk::NumericLiteral;
208 \"([^"\\\n]|{Escape})*\"|'([^'\\\n]|{Escape})*' L C {
209 char *value(reinterpret_cast<char *>(apr_palloc(yyextra->pool_, yyleng)));
212 for (int i(1); i != yyleng - 1; ++i) {
213 char next(yytext[i]);
215 if (yytext[i] == '\\')
216 switch (next = yytext[++i]) {
218 case '\\': next = '\\'; break;
219 case '\'': next = '\''; break;
220 case '"': next = '"'; break;
221 case 'b': next = '\b'; break;
222 case 'f': next = '\f'; break;
223 case 'n': next = '\n'; break;
224 case 'r': next = '\r'; break;
225 case 't': next = '\t'; break;
226 case 'v': next = '\v'; break;
227 case '0': next = '\0'; break;
230 next = H(yytext[i + 1]) << 4 | H(yytext[i + 2]);
239 yylval->string_ = new CYString(value, local - value);
240 return tk::StringLiteral;
243 \n yylloc->end.lines(); yylloc->step(); N
246 <<EOF>> L yyterminate();
249 CYDriver::Error error;
250 error.location_ = *yylloc;
251 error.message_ = "syntax error, unknown token";
252 yyextra->errors_.push_back(error);
258 void CYDriver::ScannerInit() {
259 cylex_init(&scanner_);
260 cyset_extra(this, scanner_);
263 void CYDriver::ScannerDestroy() {
264 cylex_destroy(scanner_);