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); \
27 #define YY_INPUT(data, value, size) { \
28 if (yyextra->size_ == 0) \
31 size_t copy(std::min(size, yyextra->size_)); \
32 memcpy(data, yyextra->data_, copy); \
33 yyextra->data_ += copy; \
34 yyextra->size_ -= copy; \
43 %option bison-locations
50 Exponent [eE][+-]?[0-9]+
51 Escape \\['"\\bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
56 \/\*(\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 :(
58 "&" L C return tk::Ampersand;
59 "&&" L C return tk::AmpersandAmpersand;
60 "&=" L C return tk::AmpersandEqual;
61 "^" L C return tk::Carrot;
62 "^=" L C return tk::CarrotEqual;
63 "=" L C return tk::Equal;
64 "==" L C return tk::EqualEqual;
65 "===" L C return tk::EqualEqualEqual;
66 "!" L C return tk::Exclamation;
67 "!=" L C return tk::ExclamationEqual;
68 "!==" L C return tk::ExclamationEqualEqual;
69 "-" L C return tk::Hyphen;
70 "-=" L C return tk::HyphenEqual;
71 "--" L C return yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen;
72 "->" L C return tk::HyphenRight;
73 "<" L C return tk::Left;
74 "<=" L C return tk::LeftEqual;
75 "<<" L C return tk::LeftLeft;
76 "<<=" L C return tk::LeftLeftEqual;
77 "%" L C return tk::Percent;
78 "%=" L C return tk::PercentEqual;
79 "." L C return tk::Period;
80 "|" L C return tk::Pipe;
81 "|=" L C return tk::PipeEqual;
82 "||" L C return tk::PipePipe;
83 "+" L C return tk::Plus;
84 "+=" L C return tk::PlusEqual;
85 "++" L C return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus;
86 ">" L C return tk::Right;
87 ">=" L C return tk::RightEqual;
88 ">>" L C return tk::RightRight;
89 ">>=" L C return tk::RightRightEqual;
90 ">>>" L C return tk::RightRightRight;
91 ">>>=" L C return tk::RightRightRightEqual;
92 "/" L C return tk::Slash;
93 "/=" L C return tk::SlashEqual;
94 "*" L C return tk::Star;
95 "*=" L C return tk::StarEqual;
96 "~" L C return tk::Tilde;
98 ":" L C return tk::Colon;
99 "," L C return tk::Comma;
100 "?" L C return tk::Question;
101 ";" L C return tk::SemiColon;
103 "(" L C return tk::OpenParen;
104 ")" L C return tk::CloseParen;
106 "{" L C return tk::OpenBrace;
107 "}" L C return tk::CloseBrace;
109 "[" L C return tk::OpenBracket;
110 "]" L C return tk::CloseBracket;
112 "@selector" L C return tk::AtSelector;
114 "break" L R yylval->word_ = new CYWord("break"); return tk::Break;
115 "case" L C yylval->word_ = new CYWord("case"); return tk::Case;
116 "catch" L C yylval->word_ = new CYWord("catch"); return tk::Catch;
117 "continue" L R yylval->word_ = new CYWord("continue"); return tk::Continue;
118 "default" L C yylval->word_ = new CYWord("default"); return tk::Default;
119 "delete" L C yylval->word_ = new CYWord("delete"); return tk::Delete;
120 "do" L C yylval->word_ = new CYWord("do"); return tk::Do;
121 "else" L C yylval->word_ = new CYWord("else"); return tk::Else;
122 "false" L C yylval->false_ = new CYFalse(); return tk::False;
123 "finally" L C yylval->word_ = new CYWord("finally"); return tk::Finally;
124 "for" L C yylval->word_ = new CYWord("for"); return tk::For;
125 "function" L C yylval->word_ = new CYWord("function"); return tk::Function;
126 "if" L C yylval->word_ = new CYWord("if"); return tk::If;
127 "in" L C yylval->word_ = new CYWord("in"); return tk::In;
128 "instanceof" L C yylval->word_ = new CYWord("instanceof"); return tk::InstanceOf;
129 "new" L C yylval->word_ = new CYWord("new"); return tk::New;
130 "null" L C yylval->null_ = new CYNull(); return tk::Null;
131 "return" L R yylval->word_ = new CYWord("return"); return tk::Return;
132 "switch" L C yylval->word_ = new CYWord("switch"); return tk::Switch;
133 "this" L C yylval->this_ = new CYThis(); return tk::This;
134 "throw" L R yylval->word_ = new CYWord("throw"); return tk::Throw;
135 "true" L C yylval->true_ = new CYTrue(); return tk::True;
136 "try" L C yylval->word_ = new CYWord("try"); return tk::Try;
137 "typeof" L C yylval->word_ = new CYWord("typeof"); return tk::TypeOf;
138 "var" L C yylval->word_ = new CYWord("var"); return tk::Var;
139 "void" L C yylval->word_ = new CYWord("void"); return tk::Void;
140 "while" L C yylval->word_ = new CYWord("while"); return tk::While;
141 "with" L C yylval->word_ = new CYWord("with"); return tk::With;
143 [a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier;
145 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); L C return tk::NumericLiteral;
147 0[xX][0-9a-fA-F]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
149 0[bB][0-1]+ L C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 2)); return tk::NumericLiteral;
151 \"([^"\\\n]|{Escape})*\" L C return tk::StringLiteral;
152 '([^'\\\n]|{Escape})*' L C return tk::StringLiteral;
154 \n yylloc->end.lines(); yylloc->step(); N
157 <<EOF>> L yyterminate();
161 void CYDriver::ScannerInit() {
162 cylex_init(&scanner_);
163 cyset_extra(this, scanner_);
166 void CYDriver::ScannerDestroy() {
167 cylex_destroy(scanner_);