10%option prefix="NewLang"
29%{ /*** C/C++ Declarations ***/
36using namespace newlang;
39typedef newlang::parser::token token;
40typedef newlang::parser::token_type token_type;
44#define yyterminate() return token::END
52#define YY_USER_ACTION yylloc->columns(yyleng);
54#define YY_TOKEN(tok) *yylval = Term::Create(TermID:: tok, yytext, token:: tok, yyleng, yylloc, source_string); (*yylval)->m_bracket_depth = m_bracket_depth; return token:: tok
55#define YY_TOKEN_ONLY(tok) *yylval = Term::Create(TermID::UNKNOWN, yytext, token:: tok, yyleng, yylloc, source_string); return token:: tok
64ualpha {alpha}|{U2}{U1}|{U3}{U1}{U1}|{U4}{U1}{U1}{U1}
83integer {digit}([_]?{digit}+)*
84name ({ualpha}|[_])({ualpha}|{digit}|[_])*
87number1 -?{digit}+\.{digit}+([eE][-+]?{digit}+)?
88number2 (-?{digit}+\.([eE][-+]?)?)?-?{digit}+
89number ({number1}|{number2})
101module_name \\({ualpha}|[_]|{digit})+
102module \\?{module_name}+
104mangled_name ({alpha}|[_$]|{digit})+
105mangled _${mangled_name}?$_{mangled_name}+
121%% /*** Regular Expressions Part ***/
131 *
yylval = Term::Create(TermID::DOC_AFTER, &
yytext[5], token::DOC_AFTER, yyleng-6, yylloc, source_string);
132 return token::DOC_AFTER;
return static_cast< token_type > * yytext
136 *
yylval = Term::Create(TermID::DOC_BEFORE, &
yytext[4], token::DOC_BEFORE, yyleng-5, yylloc, source_string);
137 return token::DOC_BEFORE;
140"<@" YY_TOKEN_ONLY(TEMPLATE_OPEN);
141"@>" YY_TOKEN_ONLY(TEMPLATE_CLOSE);
143"@##" YY_TOKEN(MACRO_CONCAT);
144"@#'" YY_TOKEN(MACRO_TOSTR);
145"@#\"" YY_TOKEN(MACRO_TOSTR);
146"@#" YY_TOKEN(MACRO_TOSTR);
148"@$"{name} YY_TOKEN(MACRO_ARGNAME);
149"@$"[0-9]+ YY_TOKEN(MACRO_ARGPOS);
151"@$..." YY_TOKEN(MACRO_ARGUMENT);
152"@$*" YY_TOKEN(MACRO_ARGUMENT);
153"@$#" YY_TOKEN(MACRO_ARGCOUNT);
156 *
yylval = Term::Create(TermID::DOC_AFTER, &
yytext[4], token::DOC_AFTER, yyleng-5, yylloc, source_string);
157 return token::DOC_AFTER;
161 *
yylval = Term::Create(TermID::DOC_BEFORE, &
yytext[3], token::DOC_BEFORE, yyleng-4, yylloc, source_string);
162 return token::DOC_BEFORE;
yy_push_state(state_DOC_BEFORE)
YY_FATAL_ERROR("Document comments cannot be nested!")
178 buffer.append(
yytext, yyleng);
179 yylloc->lines(yyleng);
185 buffer.append(
yytext, yyleng);
186 *
yylval = Term::Create(TermID::DOC_BEFORE, buffer.c_str(), token::DOC_BEFORE, buffer.size(), yylloc, source_string);
187 return token::DOC_BEFORE;
191 buffer.append(
yytext, yyleng);
194} /* End of state_DOC_BEFORE state */
200 buffer.append(
yytext, yyleng);
207 buffer.append(
yytext, yyleng);
211 buffer.append(
yytext, yyleng);
212 yylloc->lines(yyleng);
218 buffer.append(
yytext, yyleng);
219 if(!m_ignore_comment && yy_start_stack_ptr == 0){
220 *
yylval = Term::Create(TermID::COMMENT, buffer.c_str(), token::COMMENT, buffer.size(), yylloc, source_string);
221 return token::COMMENT;
226 buffer.append(
yytext, yyleng);
229} /* End of state_COMMENT state */
232 if(!m_ignore_comment){
233 *
yylval = Term::Create(TermID::COMMENT,
yytext, token::COMMENT, yyleng, yylloc, source_string);
234 return token::COMMENT;
245. buffer.append(yytext, yyleng);
247 buffer.append(
yytext, yyleng);
248 yylloc->lines(yyleng);
253 *
yylval = Term::Create(TermID::EMBED, buffer.c_str(), token::EMBED, buffer.size(), yylloc, source_string);
256} /* End of state_SOURCE state */
261 *
yylval = Term::Create(TermID::MACRO_DEL,
yytext, token::MACRO_DEL, yyleng, yylloc, source_string);
262 return token::MACRO_DEL;
272 *
yylval = Term::Create(TermID::MACRO_SEQ,
yytext, token::MACRO_SEQ, yyleng, yylloc, source_string);
273 return token::MACRO_SEQ;
279 buffer.append(
yytext, yyleng);
280 yylloc->lines(yyleng);
284[^@^\n]* buffer.append(yytext, yyleng);
285"@"[^@^\n]* buffer.append(yytext, yyleng);
286"@@"[^@^\n]* buffer.append(yytext, yyleng);
290 *
yylval = Term::Create(TermID::MACRO_STR, buffer.c_str(), token::MACRO_STR, buffer.size(), yylloc, source_string);
291 return token::MACRO_STR;
293} /* End of state_MACRO_STR state */
302. buffer.append(yytext, yyleng);
304 buffer.append(
yytext, yyleng);
305 yylloc->lines(yyleng);
310 *
yylval = Term::Create(TermID::TEMPLATE, buffer.c_str(), token::TEMPLATE, buffer.size(), yylloc, source_string);
311 return token::TEMPLATE;
313} /* End of state_TEMPLATE1 state */
323. buffer.append(yytext, yyleng);
325 buffer.append(
yytext, yyleng);
326 yylloc->lines(yyleng);
332 *
yylval = Term::Create(TermID::TEMPLATE, buffer.c_str(), token::TEMPLATE, buffer.size(), yylloc, source_string);
333 return token::TEMPLATE;
335} /* End of state_TEMPLATE2 state */
338\" { /* Start state state_STRWIDE*/
349. buffer.append(yytext, yyleng);
354\" { /* saw closing quote - all done */
356 *
yylval = Term::Create(TermID::STRWIDE, buffer.c_str(), token::STRWIDE, buffer.size(), yylloc, source_string);
357 return token::STRWIDE;
374 buffer.append(&
byte, 1);
void sscanf(yytext+1, "%o", &result)
384\\n buffer.append("\n");
385\\t buffer.append("\t");
386\\r buffer.append("\r");
387\\b buffer.append("\b");
388\\f buffer.append("\f");
389\\s buffer.append("\x20");
391\\(.|\n) buffer.append(&yytext[1], 1);
392[^\\\n\"]+ buffer.append(yytext, yyleng);
395} /* End of state_STRWIDE state*/
404. buffer.append(yytext, yyleng);
408' { /* Start state state_STRCHAR */
415' { /* saw closing quote - all done */
417 *
yylval = Term::Create(TermID::STRCHAR, buffer.c_str(), token::STRCHAR, buffer.size(), yylloc, source_string);
418 return token::STRCHAR;
435 buffer.append(&
byte, 1);
445\\n buffer.append("\n");
446\\t buffer.append("\t");
447\\r buffer.append("\r");
448\\b buffer.append("\b");
449\\f buffer.append("\f");
450\\s buffer.append("\x20");
452\\(.|\n) buffer.append(&yytext[1], 1);
453[^\\\n']+ buffer.append(yytext, yyleng);
456} /* End of state_STRCHAR state*/
459"`" { /* Start state state_EVAL */
468 *
yylval = Term::Create(TermID::EVAL, buffer.c_str(), token::EVAL, buffer.size(), yylloc, source_string);
486 buffer.append(&
byte, 1);
496\\n buffer.append("\n");
497\\t buffer.append("\t");
498\\r buffer.append("\r");
499\\b buffer.append("\b");
500\\f buffer.append("\f");
501\\s buffer.append("\x20");
503\\(.|\n) buffer.append(&yytext[1], 1);
504[^\\\n`]+ buffer.append(yytext, yyleng);
506. buffer.append(yytext, yyleng);
509} /* End of state_EVAL state*/
513-?{number}[-+]{number}j YY_TOKEN(COMPLEX);
514-?{number}[-+]{number}i YY_TOKEN(COMPLEX);
515-?{number}j[-+]{number} YY_TOKEN(COMPLEX);
516-?{number}i[-+]{number} YY_TOKEN(COMPLEX);
518-?{number}j YY_TOKEN(COMPLEX);
519-?{number}i YY_TOKEN(COMPLEX);
521-?{integer}\\-?{integer} YY_TOKEN(RATIONAL);
522-?{integer} YY_TOKEN(INTEGER);
523{number} YY_TOKEN(NUMBER);
526"$"[0-9]+"^"? YY_TOKEN(ARGUMENT);
528{mangled} YY_TOKEN(MANGLED);
529{name}"^"? YY_TOKEN(NAME);
530@{name}"^"? YY_TOKEN(MACRO);
531${name}"^"? YY_TOKEN(LOCAL);
532{module} YY_TOKEN(MODULE);
533"$..." YY_TOKEN(LOCAL); /* For statement macros */
534"..." YY_TOKEN(ELLIPSIS);
536"<->" YY_TOKEN_ONLY(REPEAT);
537"-->" YY_TOKEN(FOLLOW);
538"~>" YY_TOKEN(MATCHING);
539"~~>" YY_TOKEN(MATCHING);
540"~~~>" YY_TOKEN(MATCHING);
541"==>" YY_TOKEN(MATCHING);
542"===>" YY_TOKEN(MATCHING);
544"::=" YY_TOKEN(CREATE_NEW);
545":=" YY_TOKEN(CREATE_USE);
546"[]=" YY_TOKEN(APPEND);
547"::-" YY_TOKEN(PURE_NEW);
548":-" YY_TOKEN(PURE_USE);
551"::" YY_TOKEN(NAMESPACE);
555"\\\\" YY_TOKEN(MODULE);
562"@::" YY_TOKEN_ONLY(MACRO_NAMESPACE);
563"@$$" YY_TOKEN_ONLY(MACRO_NAMESPACE);
564"$::" YY_TOKEN_ONLY(MACRO_NAMESPACE);
567"$\\\\" YY_TOKEN_ONLY(MACRO);
569"@\\" YY_TOKEN(ESCAPE);
588"[@" m_bracket_depth++; YY_TOKEN_ONLY(MACRO_ATTR_BEGIN);
589"@]" m_bracket_depth--; YY_TOKEN_ONLY(MACRO_ATTR_END);
591"{@" m_bracket_depth++; YY_TOKEN_ONLY(MACRO_EXPR_BEGIN);
592"@}" m_bracket_depth--; YY_TOKEN_ONLY(MACRO_EXPR_END);
595"++" YY_TOKEN(INT_PLUS);
596"--" YY_TOKEN(INT_MINUS);
597"-+" YY_TOKEN(INT_REPEAT);
598"+-" YY_TOKEN(INT_REPEAT);
600"{*" m_bracket_depth++; YY_TOKEN_ONLY(TRY_ALL_BEGIN);
601"*}" m_bracket_depth--; YY_TOKEN_ONLY(TRY_ALL_END);
602"{+" m_bracket_depth++; YY_TOKEN_ONLY(TRY_PLUS_BEGIN);
603"+}" m_bracket_depth--; YY_TOKEN_ONLY(TRY_PLUS_END);
604"{-" m_bracket_depth++; YY_TOKEN_ONLY(TRY_MINUS_BEGIN);
605"-}" m_bracket_depth--; YY_TOKEN_ONLY(TRY_MINUS_END);
608"//" YY_TOKEN_ONLY(OPERATOR_DIV);
610"+=" YY_TOKEN(OP_MATH);
611"-=" YY_TOKEN(OP_MATH);
612"*=" YY_TOKEN(OP_MATH);
614"/=" YY_TOKEN(OP_MATH);
615"//=" YY_TOKEN(OP_MATH);
616"%=" YY_TOKEN(OP_MATH);
617"~=" YY_TOKEN(OP_COMPARE);
619"||" YY_TOKEN(OP_LOGICAL);
620"^^" YY_TOKEN(OP_LOGICAL);
621"&&" YY_TOKEN_ONLY(OPERATOR_AND);
623"&"[0-9]+"^"? YY_TOKEN(OPERATOR_PTR);
625"&^" YY_TOKEN_ONLY(OPERATOR_PTR);
626"&&^" YY_TOKEN_ONLY(OPERATOR_PTR);
627"&*" YY_TOKEN_ONLY(OPERATOR_PTR);
628"&*^" YY_TOKEN_ONLY(OPERATOR_PTR);
629"&?" YY_TOKEN_ONLY(OPERATOR_PTR);
630"&?^" YY_TOKEN_ONLY(OPERATOR_PTR);
641".>." YY_TOKEN(OP_BITWISE);
642".<." YY_TOKEN(OP_BITWISE);
643".>>." YY_TOKEN(OP_BITWISE);
644".&." YY_TOKEN(OP_BITWISE);
645".|." YY_TOKEN(OP_BITWISE);
646".^." YY_TOKEN(OP_BITWISE);
647".~." YY_TOKEN(OP_BITWISE);
649"*^" YY_TOKEN_ONLY(TAKE_CONST);
651"!~~~" YY_TOKEN(OP_COMPARE);
652"~~~" YY_TOKEN_ONLY(OPERATOR_DUCK);
653"!~~" YY_TOKEN(OP_COMPARE);
654"~~" YY_TOKEN_ONLY(OPERATOR_DUCK);
655"!~" YY_TOKEN(OP_COMPARE);
656"===" YY_TOKEN(OP_COMPARE);
657"==" YY_TOKEN(OP_COMPARE);
658"!==" YY_TOKEN(OP_COMPARE);
659"!=" YY_TOKEN(OP_COMPARE);
660"=/=" YY_TOKEN(OP_COMPARE);
661"<=" YY_TOKEN(OP_COMPARE);
662">=" YY_TOKEN_ONLY(OPERATOR_ANGLE_EQ);
664"[+]" YY_TOKEN(OP_MATH); /* Объединение множеств */
665"[-]" YY_TOKEN(OP_MATH); /* Разность множеств */
666"[*]" YY_TOKEN(OP_MATH); /* Пересечение множеств */
667"[/]" YY_TOKEN(OP_MATH);
683"!!" YY_TOKEN(ITERATOR);
684"??" YY_TOKEN(ITERATOR);
685"?!" YY_TOKEN_ONLY(ITERATOR_QQ);
686"!?" YY_TOKEN_ONLY(ITERATOR_QQ);
691 if(!m_ignore_indent){
692 *
yylval = Term::Create(TermID::INDENT,
yytext, token::INDENT, yyleng, yylloc, source_string);
693 return token::INDENT;
700 *
yylval = Term::Create(TermID::SPACE,
yytext, token::SPACE, yyleng, yylloc, source_string);
706 yylloc->lines(yyleng); yylloc->step();
708 *
yylval = Term::Create(TermID::CRLF,
yytext, token::CRLF, yyleng, yylloc, source_string);
715 *
yylval = Term::Create(TermID::SYMBOL,
yytext,
static_cast<token_type
>(*
yytext), yyleng, yylloc, source_string);
716 return static_cast<token_type
>(*yytext);
720 *
yylval = Term::Create(TermID::SYMBOL,
yytext,
static_cast<token_type
>(*
yytext), yyleng, yylloc, source_string);
721 return static_cast<token_type
>(*yytext);
728 *
yylval = Term::Create(TermID::SYMBOL,
yytext,
static_cast<token_type
>(*
yytext), yyleng, yylloc, source_string);
729 return static_cast<token_type
>(*yytext);
733 *
yylval = Term::Create(TermID::END,
yytext, token::END, yyleng, yylloc, source_string);
737%% /*** Additional Code ***/