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;
11 #define N if (yyextra->state_ != CYNewLine) { bool restricted(yyextra->state_ == CYRestricted); if (restricted) { yyextra->state_ = CYClear; return tk::NewLine; } else yyextra->state_ = CYNewLine; }
13 #define YY_INPUT(data, value, size) { \
14 if (yyextra->size_ == 0) \
17 size_t copy(std::min(size, yyextra->size_)); \
18 memcpy(data, yyextra->data_, copy); \
19 yyextra->data_ += copy; \
20 yyextra->size_ -= copy; \
29 %option bison-locations
36 Exponent [eE][+-]?[0-9]+
37 Escape \\['"\\bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
42 \/\*(\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 :(
44 "&" C return tk::Ampersand;
45 "&&" C return tk::AmpersandAmpersand;
46 "&=" C return tk::AmpersandEqual;
47 "^" C return tk::Carrot;
48 "^=" C return tk::CarrotEqual;
49 "=" C return tk::Equal;
50 "==" C return tk::EqualEqual;
51 "===" C return tk::EqualEqualEqual;
52 "!" C return tk::Exclamation;
53 "!=" C return tk::ExclamationEqual;
54 "!==" C return tk::ExclamationEqualEqual;
55 "-" C return tk::Hyphen;
56 "-=" C return tk::HyphenEqual;
57 "--" C return yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen;
58 "->" C return tk::HyphenRight;
59 "<" C return tk::Left;
60 "<=" C return tk::LeftEqual;
61 "<<" C return tk::LeftLeft;
62 "<<=" C return tk::LeftLeftEqual;
63 "%" C return tk::Percent;
64 "%=" C return tk::PercentEqual;
65 "." C return tk::Period;
66 "|" C return tk::Pipe;
67 "|=" C return tk::PipeEqual;
68 "||" C return tk::PipePipe;
69 "+" C return tk::Plus;
70 "+=" C return tk::PlusEqual;
71 "++" C return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus;
72 ">" C return tk::Right;
73 ">=" C return tk::RightEqual;
74 ">>" C return tk::RightRight;
75 ">>=" C return tk::RightRightEqual;
76 ">>>" C return tk::RightRightRight;
77 ">>>=" C return tk::RightRightRightEqual;
78 "/" C return tk::Slash;
79 "/=" C return tk::SlashEqual;
80 "*" C return tk::Star;
81 "*=" C return tk::StarEqual;
82 "~" C return tk::Tilde;
84 ":" C return tk::Colon;
85 "," C return tk::Comma;
86 "?" C return tk::Question;
87 ";" C return tk::SemiColon;
89 "(" C return tk::OpenParen;
90 ")" C return tk::CloseParen;
92 "{" C return tk::OpenBrace;
93 "}" C return tk::CloseBrace;
95 "[" C return tk::OpenBracket;
96 "]" C return tk::CloseBracket;
98 "@selector" C return tk::AtSelector;
100 "break" R yylval->word_ = new CYWord("break"); return tk::Break;
101 "case" C yylval->word_ = new CYWord("case"); return tk::Case;
102 "catch" C yylval->word_ = new CYWord("catch"); return tk::Catch;
103 "continue" R yylval->word_ = new CYWord("continue"); return tk::Continue;
104 "default" C yylval->word_ = new CYWord("default"); return tk::Default;
105 "delete" C yylval->word_ = new CYWord("delete"); return tk::Delete;
106 "do" C yylval->word_ = new CYWord("do"); return tk::Do;
107 "else" C yylval->word_ = new CYWord("else"); return tk::Else;
108 "false" C yylval->false_ = new CYFalse(); return tk::False;
109 "finally" C yylval->word_ = new CYWord("finally"); return tk::Finally;
110 "for" C yylval->word_ = new CYWord("for"); return tk::For;
111 "function" C yylval->word_ = new CYWord("function"); return tk::Function;
112 "if" C yylval->word_ = new CYWord("if"); return tk::If;
113 "in" C yylval->word_ = new CYWord("in"); return tk::In;
114 "instanceof" C yylval->word_ = new CYWord("instanceof"); return tk::InstanceOf;
115 "new" C yylval->word_ = new CYWord("new"); return tk::New;
116 "null" C yylval->null_ = new CYNull(); return tk::Null;
117 "return" R yylval->word_ = new CYWord("return"); return tk::Return;
118 "switch" C yylval->word_ = new CYWord("switch"); return tk::Switch;
119 "this" C yylval->this_ = new CYThis(); return tk::This;
120 "throw" R yylval->word_ = new CYWord("throw"); return tk::Throw;
121 "true" C yylval->true_ = new CYTrue(); return tk::True;
122 "try" C yylval->word_ = new CYWord("try"); return tk::Try;
123 "typeof" C yylval->word_ = new CYWord("typeof"); return tk::TypeOf;
124 "var" C yylval->word_ = new CYWord("var"); return tk::Var;
125 "void" C yylval->word_ = new CYWord("void"); return tk::Void;
126 "while" C yylval->word_ = new CYWord("while"); return tk::While;
127 "with" C yylval->word_ = new CYWord("with"); return tk::With;
129 [a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); C return tk::Identifier;
131 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); C return tk::NumericLiteral;
133 0[xX][0-9a-fA-F]+ C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
135 0[bB][0-1]+ C yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 2)); return tk::NumericLiteral;
137 \"([^"\\\n]|{Escape})*\" C return tk::StringLiteral;
138 '([^'\\\n]|{Escape})*' C return tk::StringLiteral;
145 void CYDriver::ScannerInit() {
146 cylex_init(&scanner_);
147 cyset_extra(this, scanner_);
150 void CYDriver::ScannerDestroy() {
151 cylex_destroy(scanner_);