NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
lexer.l
Go to the documentation of this file.
1/*** Flex Declarations and Options ***/
2
3
4/* enable c++ scanner class generation */
5%option c++
6
7%option 8bit
8
9/* change the name of the scanner class. results in "ExampleFlexLexer" */
10%option prefix="NewLang"
11
12/* the manual says "somewhat more optimized" */
13%option batch
14
15/* enable scanner to generate debug output. disable this for release
16 * versions. */
17%option debug
18%option warn
19
20/* no support for include files is planned */
21%option yywrap nounput
22
23%option yylineno
24
25/* enables the use of start condition stacks */
26%option stack
27
28
29%{ /*** C/C++ Declarations ***/
30
31#include "lexer.h"
32
33#include "nlc-rt.h"
34#include "term.h"
35
36using namespace newlang;
37
38/* import the parser's token type into a local typedef */
39typedef newlang::parser::token token;
40typedef newlang::parser::token_type token_type;
41
42/* By default yylex returns int, we use token_type. Unfortunately yyterminate
43 * by default returns 0, which is not of token_type. */
44#define yyterminate() return token::END
45
46/* This disables inclusion of unistd.h, which is not available under Visual C++
47 * on Win32. The C++ scanner uses STL streams instead. */
48#define YY_NO_UNISTD_H
49
50/* The following paragraph suffices to track locations accurately. Each time
51 * yylex is invoked, the begin position is moved onto the end position. */
52#define YY_USER_ACTION yylloc->columns(yyleng);
53
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
56
57%}
58
59alpha [A-Za-z]
60U1 [\x80-\xbf]
61U2 [\xc2-\xdf]
62U3 [\xe0-\xef]
63U4 [\xf0-\xf4]
64ualpha {alpha}|{U2}{U1}|{U3}{U1}{U1}|{U4}{U1}{U1}{U1}
65
66/* запрет использования U+202A, U+202B, U+202C, U+202D, U+202E, U+2066, U+2067, U+2068, U+2069, U+061C, U+200E и U+200F */
67
68
69/*
70sign ::= "+" | "-"
71infinity ::= "Infinity" | "inf"
72nan ::= "nan"
73digit ::= <a Unicode decimal digit, i.e. characters in Unicode general category Nd>
74digitpart ::= digit (["_"] digit)*
75number ::= [digitpart] "." digitpart | digitpart ["."]
76exponent ::= ("e" | "E") ["+" | "-"] digitpart
77floatnumber ::= number [exponent]
78floatvalue ::= [sign] (floatnumber | infinity | nan)
79*/
80
81digit [0-9]
82/* In numbers, it is allowed to separate digits using a handwriting symbol... */
83integer {digit}([_]?{digit}+)*
84name ({ualpha}|[_])({ualpha}|{digit}|[_])*
85/* macro @({ualpha}|[_])?({name})? */
86
87number1 -?{digit}+\.{digit}+([eE][-+]?{digit}+)?
88number2 (-?{digit}+\.([eE][-+]?)?)?-?{digit}+
89number ({number1}|{number2})
90
91/* number [-+]?{integer}[.]{integer}([eE][-+]?[0-9]+)? */
92
93/* field \.({name}|{digit})+ */
94
95/* local $({ualpha}|[_])?({name}|{digit})? */
96
97/* The first digit character is allowed in module names because they are filenames... */
98/* The module name uses only lowercase letters of the Latin alphabet.
99 The first character cannot be an underscore, but this check occurs at the level
100 of parsing the syntax tree and checking for the presence of the file. */
101module_name \\‍({ualpha}|[_]|{digit})+
102module \\?{module_name}+
103
104mangled_name ({alpha}|[_$]|{digit})+
105mangled _${mangled_name}?$_{mangled_name}+
106
107%x state_STRWIDE
108%x state_STRCHAR
109%x state_STRWIDE_RAW
110%x state_STRCHAR_RAW
111%x state_TEMPLATE1
112%x state_TEMPLATE2
113%x state_DOC_BEFORE
114%x state_DOC_AFTER
115%x state_COMMENT
116%x state_SOURCE
117%x state_MACRO_STR
118%x state_EVAL
119
120
121%% /*** Regular Expressions Part ***/
122
123
124 /* code to place at the beginning of yylex() */
125%{
126 // reset location
127 yylloc->step();
128%}
129
130"///<"[^\n]* {
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
Definition lexer.l:716
* yylval
Definition lexer.l:131
133}
134
135"///"[^\n]* {
136 *yylval = Term::Create(TermID::DOC_BEFORE, &yytext[4], token::DOC_BEFORE, yyleng-5, yylloc, source_string);
137 return token::DOC_BEFORE;
138}
139
140"<@" YY_TOKEN_ONLY(TEMPLATE_OPEN);
141"@>" YY_TOKEN_ONLY(TEMPLATE_CLOSE);
142
143"@##" YY_TOKEN(MACRO_CONCAT);
144"@#'" YY_TOKEN(MACRO_TOSTR);
145"@#\"" YY_TOKEN(MACRO_TOSTR);
146"@#" YY_TOKEN(MACRO_TOSTR);
147
148"@$"{name} YY_TOKEN(MACRO_ARGNAME);
149"@$"[0-9]+ YY_TOKEN(MACRO_ARGPOS);
150
151"@$..." YY_TOKEN(MACRO_ARGUMENT);
152"@$*" YY_TOKEN(MACRO_ARGUMENT);
153"@$#" YY_TOKEN(MACRO_ARGCOUNT);
154
155"##<"[^\n]* {
156 *yylval = Term::Create(TermID::DOC_AFTER, &yytext[4], token::DOC_AFTER, yyleng-5, yylloc, source_string);
157 return token::DOC_AFTER;
158}
159
160"##"[^\n]* {
161 *yylval = Term::Create(TermID::DOC_BEFORE, &yytext[3], token::DOC_BEFORE, yyleng-4, yylloc, source_string);
162 return token::DOC_BEFORE;
163}
164
165"/**" {
166 yy_push_state(state_DOC_BEFORE);
167 buffer.clear();
168 buffer.append(yytext, yyleng);
169 }
yy_push_state(state_DOC_BEFORE)
170
171<state_DOC_BEFORE>{
172
173"/*" {
174 YY_FATAL_ERROR("Document comments cannot be nested!");
175 }
YY_FATAL_ERROR("Document comments cannot be nested!")
176
177\n {
178 buffer.append(yytext, yyleng);
179 yylloc->lines(yyleng);
180 yylloc->step();
181 }
182
183"*/" {
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;
188 }
yy_pop_state()
189
190. {
191 buffer.append(yytext, yyleng);
192 }
193
194} /* End of state_DOC_BEFORE state */
195
196
197"/*" {
198 yy_push_state(state_COMMENT);
199 buffer.clear();
200 buffer.append(yytext, yyleng);
201 }
202
203<state_COMMENT>{
204
205"/*" {
206 yy_push_state(state_COMMENT);
207 buffer.append(yytext, yyleng);
208 }
209
210\n {
211 buffer.append(yytext, yyleng);
212 yylloc->lines(yyleng);
213 yylloc->step();
214 }
215
216"*/" {
217 yy_pop_state();
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;
222 }
223 }
224
225. {
226 buffer.append(yytext, yyleng);
227 }
228
229} /* End of state_COMMENT state */
230
231"#"[^\n]* {
232 if(!m_ignore_comment){
233 *yylval = Term::Create(TermID::COMMENT, yytext, token::COMMENT, yyleng, yylloc, source_string);
234 return token::COMMENT;
235 }
236}
237
238
239"{%" {
240 BEGIN(state_SOURCE);
241 buffer.clear();
BEGIN(state_SOURCE)
242}
243
244<state_SOURCE>{
245. buffer.append(yytext, yyleng);
246\n {
247 buffer.append(yytext, yyleng);
248 yylloc->lines(yyleng);
249 yylloc->step();
250 }
251"%}" {
252 BEGIN(INITIAL);
253 *yylval = Term::Create(TermID::EMBED, buffer.c_str(), token::EMBED, buffer.size(), yylloc, source_string);
254 return token::EMBED;
255 }
256} /* End of state_SOURCE state */
257
258
259"@@@@" {
261 *yylval = Term::Create(TermID::MACRO_DEL, yytext, token::MACRO_DEL, yyleng, yylloc, source_string);
262 return token::MACRO_DEL;
263 }
m_macro_del
Definition lexer.l:260
264
265"@@@" {
266 BEGIN(state_MACRO_STR);
267 buffer.clear();
268 }
269
270"@@" {
272 *yylval = Term::Create(TermID::MACRO_SEQ, yytext, token::MACRO_SEQ, yyleng, yylloc, source_string);
273 return token::MACRO_SEQ;
274 }
m_macro_count
Definition lexer.l:271
275
276<state_MACRO_STR>{
277
278\n {
279 buffer.append(yytext, yyleng);
280 yylloc->lines(yyleng);
281 yylloc->step();
282 }
283
284[^@^\n]* buffer.append(yytext, yyleng);
285"@"[^@^\n]* buffer.append(yytext, yyleng);
286"@@"[^@^\n]* buffer.append(yytext, yyleng);
287
288"@@@" {
289 BEGIN(INITIAL);
290 *yylval = Term::Create(TermID::MACRO_STR, buffer.c_str(), token::MACRO_STR, buffer.size(), yylloc, source_string);
291 return token::MACRO_STR;
292 }
293} /* End of state_MACRO_STR state */
294
295
296"'''" {
297 BEGIN(state_TEMPLATE1);
298 buffer.clear();
299}
300
301<state_TEMPLATE1>{
302. buffer.append(yytext, yyleng);
303\n {
304 buffer.append(yytext, yyleng);
305 yylloc->lines(yyleng);
306 yylloc->step();
307 }
308"'''" {
309 BEGIN(INITIAL);
310 *yylval = Term::Create(TermID::TEMPLATE, buffer.c_str(), token::TEMPLATE, buffer.size(), yylloc, source_string);
311 return token::TEMPLATE;
312 }
313} /* End of state_TEMPLATE1 state */
314
315
316
317"\"\"\"" {
318 BEGIN(state_TEMPLATE2);
319 buffer.clear();
320}
321
322<state_TEMPLATE2>{
323. buffer.append(yytext, yyleng);
324\n {
325 buffer.append(yytext, yyleng);
326 yylloc->lines(yyleng);
327 yylloc->step();
328 }
329
330"\"\"\"" {
331 BEGIN(INITIAL);
332 *yylval = Term::Create(TermID::TEMPLATE, buffer.c_str(), token::TEMPLATE, buffer.size(), yylloc, source_string);
333 return token::TEMPLATE;
334 }
335} /* End of state_TEMPLATE2 state */
336
337
338\" { /* Start state state_STRWIDE*/
339 BEGIN(state_STRWIDE);
340 buffer.clear();
341}
342
343"r\"" {
344 BEGIN(state_STRWIDE_RAW);
345 buffer.clear();
346}
347
348<state_STRWIDE_RAW>{
349. buffer.append(yytext, yyleng);
350}
351
352<state_STRWIDE>{
353
354\" { /* saw closing quote - all done */
355 BEGIN(INITIAL);
356 *yylval = Term::Create(TermID::STRWIDE, buffer.c_str(), token::STRWIDE, buffer.size(), yylloc, source_string);
357 return token::STRWIDE;
358 }
359
360\n {
361 /* generate error message */
362 YY_FATAL_ERROR("Unterminated string constant");
363 }
364
365@[0-7]{1,3} {
366 /* octal escape sequence */
int result
Definition lexer.l:367
368
369 (void) sscanf( yytext + 1, "%o", &result );
370 if ( result > 0xff ) {
371 YY_FATAL_ERROR("Octal constant is out-of-bounds");
372 }
373 char byte = (char)result;
374 buffer.append(&byte, 1);
375 }
void sscanf(yytext+1, "%o", &result)
376
377\\[0-9]+ {
378 /* generate error - bad escape sequence; something
379 * like '\48' or '\0777777'
380 */
381 YY_FATAL_ERROR("Bad escape sequence");
382 }
383
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");
390
391\\‍(.|\n) buffer.append(&yytext[1], 1);
392[^\\\n\"]+ buffer.append(yytext, yyleng);
393
394
395} /* End of state_STRWIDE state*/
396
397
398"r'" {
399 BEGIN(state_STRCHAR_RAW);
400 buffer.clear();
401}
402
403<state_STRCHAR_RAW>{
404. buffer.append(yytext, yyleng);
405}
406
407
408' { /* Start state state_STRCHAR */
409 BEGIN(state_STRCHAR);
410 buffer.clear();
411}
412
413<state_STRCHAR>{
414
415' { /* saw closing quote - all done */
416 BEGIN(INITIAL);
417 *yylval = Term::Create(TermID::STRCHAR, buffer.c_str(), token::STRCHAR, buffer.size(), yylloc, source_string);
418 return token::STRCHAR;
419 }
420
421\n {
422 /* generate error message */
423 YY_FATAL_ERROR("Unterminated string constant");
424 }
425
426\\[0-7]{1,3} {
427 /* octal escape sequence */
428 int result;
429
430 (void) sscanf( yytext + 1, "%o", &result );
431 if ( result > 0xff ) {
432 YY_FATAL_ERROR("Octal constant is out-of-bounds");
433 }
434 char byte = (char)result;
435 buffer.append(&byte, 1);
436 }
437
438\\[0-9]+ {
439 /* generate error - bad escape sequence; something
440 * like '\48' or '\0777777'
441 */
442 YY_FATAL_ERROR("Bad escape sequence");
443 }
444
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");
451
452\\‍(.|\n) buffer.append(&yytext[1], 1);
453[^\\\n']+ buffer.append(yytext, yyleng);
454
455
456} /* End of state_STRCHAR state*/
457
458
459"`" { /* Start state state_EVAL */
460 BEGIN(state_EVAL);
461 buffer.clear();
462}
463
464<state_EVAL>{
465
466"`" {
467 BEGIN(INITIAL);
468 *yylval = Term::Create(TermID::EVAL, buffer.c_str(), token::EVAL, buffer.size(), yylloc, source_string);
469 return token::EVAL;
470 }
471
472\n {
473 /* generate error message */
474 YY_FATAL_ERROR("Unterminated eval string");
475 }
476
477\\[0-7]{1,3} {
478 /* octal escape sequence */
479 int result;
480
481 (void) sscanf( yytext + 1, "%o", &result );
482 if ( result > 0xff ) {
483 YY_FATAL_ERROR("Octal constant is out-of-bounds");
484 }
485 char byte = (char)result;
486 buffer.append(&byte, 1);
487 }
488
489\\[0-9]+ {
490 /* generate error - bad escape sequence; something
491 * like '\48' or '\0777777'
492 */
493 YY_FATAL_ERROR("Bad escape sequence");
494 }
495
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");
502
503\\‍(.|\n) buffer.append(&yytext[1], 1);
504[^\\\n`]+ buffer.append(yytext, yyleng);
505
506. buffer.append(yytext, yyleng);
507
508
509} /* End of state_EVAL state*/
510
511 /* "-1j-0.2" "1.333+0.e10j" */
512
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);
517
518-?{number}j YY_TOKEN(COMPLEX);
519-?{number}i YY_TOKEN(COMPLEX);
520
521-?{integer}\\-?{integer} YY_TOKEN(RATIONAL);
522-?{integer} YY_TOKEN(INTEGER);
523{number} YY_TOKEN(NUMBER);
524
525
526"$"[0-9]+"^"? YY_TOKEN(ARGUMENT);
527
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);
535".." YY_TOKEN(RANGE);
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);
543
544"::=" YY_TOKEN(CREATE_NEW);
545":=" YY_TOKEN(CREATE_USE);
546"[]=" YY_TOKEN(APPEND);
547"::-" YY_TOKEN(PURE_NEW);
548":-" YY_TOKEN(PURE_USE);
549":=:" YY_TOKEN(SWAP);
550
551"::" YY_TOKEN(NAMESPACE);
552"$*" YY_TOKEN(ARGS);
553"$^" YY_TOKEN(ARGS);
554"$$" YY_TOKEN(NAME);
555"\\\\" YY_TOKEN(MODULE);
556
557 /*
558 "\\\\$" YY_TOKEN(NEWLANG);
559 "\\$" YY_TOKEN(NEWLANG);
560 */
561
562"@::" YY_TOKEN_ONLY(MACRO_NAMESPACE);
563"@$$" YY_TOKEN_ONLY(MACRO_NAMESPACE);
564"$::" YY_TOKEN_ONLY(MACRO_NAMESPACE);
565
566 /* "@\\\\" YY_TOKEN_ONLY(MACRO); */
567"$\\\\" YY_TOKEN_ONLY(MACRO);
568
569"@\\" YY_TOKEN(ESCAPE);
570 /*
571 "@\\‍)"
572
573 "@\\,"
574 "@\\;"
575 "@\\:"
576
577 "@\\s"
578 "@\\t"
579 "@\\n"
580 "@\\r"
581 "@\\b"
582 "@\\f"
583
584 "@\\#"
585 "@\\##"
586 */
587
588"[@" m_bracket_depth++; YY_TOKEN_ONLY(MACRO_ATTR_BEGIN);
589"@]" m_bracket_depth--; YY_TOKEN_ONLY(MACRO_ATTR_END);
590
591"{@" m_bracket_depth++; YY_TOKEN_ONLY(MACRO_EXPR_BEGIN);
592"@}" m_bracket_depth--; YY_TOKEN_ONLY(MACRO_EXPR_END);
593
594
595"++" YY_TOKEN(INT_PLUS);
596"--" YY_TOKEN(INT_MINUS);
597"-+" YY_TOKEN(INT_REPEAT);
598"+-" YY_TOKEN(INT_REPEAT);
599
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);
606
607
608"//" YY_TOKEN_ONLY(OPERATOR_DIV);
609 /* "++=" YY_TOKEN(OP_MATH); */
610"+=" YY_TOKEN(OP_MATH);
611"-=" YY_TOKEN(OP_MATH);
612"*=" YY_TOKEN(OP_MATH);
613 /* "**=" YY_TOKEN(OPERATOR); */
614"/=" YY_TOKEN(OP_MATH);
615"//=" YY_TOKEN(OP_MATH);
616"%=" YY_TOKEN(OP_MATH);
617"~=" YY_TOKEN(OP_COMPARE);
618
619"||" YY_TOKEN(OP_LOGICAL);
620"^^" YY_TOKEN(OP_LOGICAL);
621"&&" YY_TOKEN_ONLY(OPERATOR_AND);
622
623"&"[0-9]+"^"? YY_TOKEN(OPERATOR_PTR);
624
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);
631
632 /*
633 "&%" YY_TOKEN_ONLY(OPERATOR_PTR);
634 "&@" YY_TOKEN_ONLY(OPERATOR_PTR);
635 "&~" YY_TOKEN_ONLY(OPERATOR_PTR);
636 "&:" YY_TOKEN_ONLY(OPERATOR_PTR);
637 "&$" YY_TOKEN_ONLY(OPERATOR_PTR);
638 "&#" YY_TOKEN_ONLY(OPERATOR_PTR);
639 */
640
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);
648
649"*^" YY_TOKEN_ONLY(TAKE_CONST);
650"**" YY_TOKEN(WITH);
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);
663
664"[+]" YY_TOKEN(OP_MATH); /* Объединение множеств */
665"[-]" YY_TOKEN(OP_MATH); /* Разность множеств */
666"[*]" YY_TOKEN(OP_MATH); /* Пересечение множеств */
667"[/]" YY_TOKEN(OP_MATH);
668
669 /* Симметри́ческая ра́зность двух множеств — теоретико-множественная операция, результатом которой является новое множество, включающее все элементы исходных множеств, не принадлежащие одновременно обоим исходным множествам. Другими словами, если есть два множества A A и B B, их симметрическая разность есть объединение элементов A A, не входящих в B B, с элементами B B, не входящими в A A. На письме для обозначения симметрической разности множеств A A и B B используется обозначение A △ B {\displaystyle A\bigtriangleup B}, реже используется обозначение A − ˙ B {\displaystyle A\,{\dot {-}}\,B} или A + B A+B[1].
670 */
671 /*
672 Приоритет операций
673 Последовательность выполнения операций над множествами, как и обычно, может быть задана скобками.
674 При отсутствии скобок сначала выполняются унарные операции (дополнение), затем — пересечения, затем — объединения, разности и симметрической разности.
675 Операции одного приоритета выполняются слева направо. При этом надо иметь в виду, что в отличие от арифметических сложения и вычитания,
676 для которых, в частности, верно, что ( a + b ) − c = a + ( b − c ) {\displaystyle (a+b)-c=a+(b-c)},
677 для аналогичных операций над множествами это неверно.
678 Например, если A = { 1 , 3 } {\displaystyle A=\{1,3\}}, B = { 1 , 2 } {\displaystyle B=\{1,2\}}, C = { 2 , 3 } {\displaystyle C=\{2,3\}},
679 то ( A ∪ B ) ∖ C = { 1 } {\displaystyle (A\cup B)\setminus C=\{1\}},
680 но, в то же время, A ∪ ( B ∖ C ) = { 1 , 3 } {\displaystyle A\cup (B\setminus C)=\{1,3\}}.
681 */
682
683"!!" YY_TOKEN(ITERATOR);
684"??" YY_TOKEN(ITERATOR);
685"?!" YY_TOKEN_ONLY(ITERATOR_QQ);
686"!?" YY_TOKEN_ONLY(ITERATOR_QQ);
687
688
689^[ \t]+ {
690 yylloc->step();
691 if(!m_ignore_indent){
692 *yylval = Term::Create(TermID::INDENT, yytext, token::INDENT, yyleng, yylloc, source_string);
693 return token::INDENT;
694 }
695}
696
697[ \t]+ {
698 yylloc->step();
699 if(!m_ignore_space){
700 *yylval = Term::Create(TermID::SPACE, yytext, token::SPACE, yyleng, yylloc, source_string);
701 return token::SPACE;
702 }
703}
704
705\n {
706 yylloc->lines(yyleng); yylloc->step();
707 if(!m_ignore_crlf){
708 *yylval = Term::Create(TermID::CRLF, yytext, token::CRLF, yyleng, yylloc, source_string);
709 return token::CRLF;
710 }
711}
712
713"{" {
715 *yylval = Term::Create(TermID::SYMBOL, yytext, static_cast<token_type>(*yytext), yyleng, yylloc, source_string);
716 return static_cast<token_type>(*yytext);
717 }
m_bracket_depth
Definition lexer.l:714
718"}" {
720 *yylval = Term::Create(TermID::SYMBOL, yytext, static_cast<token_type>(*yytext), yyleng, yylloc, source_string);
721 return static_cast<token_type>(*yytext);
722 }
723
724. {
725
726 /* Нужно для работы парсера */
727
728 *yylval = Term::Create(TermID::SYMBOL, yytext, static_cast<token_type>(*yytext), yyleng, yylloc, source_string);
729 return static_cast<token_type>(*yytext);
730}
731
732<<EOF>> {
733 *yylval = Term::Create(TermID::END, yytext, token::END, yyleng, yylloc, source_string);
734 return token::END;
735}
736
737%% /*** Additional Code ***/
738