Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eccfb8a

Browse files
committed
update ply
Change-Id: I8fd5635a9f3ac99d7dfebdfa56a546357480a4cf
1 parent f6d4f4d commit eccfb8a

File tree

6 files changed

+134
-62
lines changed

6 files changed

+134
-62
lines changed

‎code/lex.yy.c

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,18 @@ static void yy_fatal_error (yyconst char msg[] );
360360
*yy_cp = '0円'; \
361361
(yy_c_buf_p) = yy_cp;
362362

363-
#define YY_NUM_RULES 4
364-
#define YY_END_OF_BUFFER 5
363+
#define YY_NUM_RULES 3
364+
#define YY_END_OF_BUFFER 4
365365
/* This struct is not used in this scanner,
366366
but its presence is necessary. */
367367
struct yy_trans_info
368368
{
369369
flex_int32_t yy_verify;
370370
flex_int32_t yy_nxt;
371371
};
372-
static yyconst flex_int16_t yy_accept[20] =
372+
static yyconst flex_int16_t yy_accept[10] =
373373
{ 0,
374-
0, 0, 5, 4, 4, 4, 0, 0, 0, 0,
375-
0, 0, 1, 0, 2, 0, 0, 3, 0
374+
0, 0, 4, 3, 1, 2, 1, 2, 0
376375
} ;
377376

378377
static yyconst flex_int32_t yy_ec[256] =
@@ -381,16 +380,16 @@ static yyconst flex_int32_t yy_ec[256] =
381380
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
382381
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
383382
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
384-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
385-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
386-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
387-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
388-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
389-
1, 1, 1, 1, 1, 1, 2, 1, 1, 3,
390-
391-
1, 1, 1, 1, 4, 1, 1, 1, 1, 5,
392-
6, 7, 1, 8, 9, 10, 1, 1, 11, 1,
393-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
383+
1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
384+
2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
385+
1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
386+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
387+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
388+
1, 1, 1, 1, 1, 1, 3, 3, 3, 3,
389+
390+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
391+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
392+
3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
394393
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
395394
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
396395
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -407,38 +406,33 @@ static yyconst flex_int32_t yy_ec[256] =
407406
1, 1, 1, 1, 1
408407
} ;
409408

410-
static yyconst flex_int32_t yy_meta[12] =
409+
static yyconst flex_int32_t yy_meta[4] =
411410
{ 0,
412-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413-
1
411+
1, 2, 3
414412
} ;
415413

416-
static yyconst flex_int16_t yy_base[21] =
414+
static yyconst flex_int16_t yy_base[12] =
417415
{ 0,
418-
0, 3, 23, 24, 12, 17, 13, 15, 10, 10,
419-
13, 3, 24, 8, 24, 0, 0, 24, 24, 0
416+
0, 0, 7, 8, 0, 0, 0, 0, 8, 4,
417+
2
420418
} ;
421419

422-
static yyconst flex_int16_t yy_def[21] =
420+
static yyconst flex_int16_t yy_def[12] =
423421
{ 0,
424-
20, 20, 19, 19, 19, 19, 19, 19, 19, 19,
425-
19, 19, 19, 19, 19, 19, 19, 19, 0, 19
422+
9, 1, 9, 9, 10, 11, 10, 11, 0, 9,
423+
9
426424
} ;
427425

428-
static yyconst flex_int16_t yy_nxt[36] =
426+
static yyconst flex_int16_t yy_nxt[12] =
429427
{ 0,
430-
4, 19, 18, 19, 19, 19, 19, 17, 5, 16,
431-
6, 5, 15, 6, 9, 14, 13, 12, 10, 11,
432-
8, 7, 19, 3, 19, 19, 19, 19, 19, 19,
433-
19, 19, 19, 19, 19
428+
4, 5, 6, 8, 8, 7, 9, 3, 9, 9,
429+
9
434430
} ;
435431

436-
static yyconst flex_int16_t yy_chk[36] =
432+
static yyconst flex_int16_t yy_chk[12] =
437433
{ 0,
438-
20, 0, 17, 0, 0, 0, 0, 16, 1, 14,
439-
1, 2, 12, 2, 7, 11, 10, 9, 7, 8,
440-
6, 5, 3, 19, 19, 19, 19, 19, 19, 19,
441-
19, 19, 19, 19, 19
434+
1, 1, 1, 11, 11, 10, 3, 9, 9, 9,
435+
9
442436
} ;
443437

444438
static yy_state_type yy_last_accepting_state;
@@ -455,10 +449,10 @@ int yy_flex_debug = 0;
455449
#define YY_MORE_ADJ 0
456450
#define YY_RESTORE_YY_MORE_OFFSET
457451
char *yytext;
458-
#line 1 "lex_start.lt"
459-
#line 2 "lex_start.lt"
460-
#include "stdio.h"
461-
#line 462 "lex.yy.c"
452+
#line 1 "lex_regex.lt"
453+
#line 2 "lex_regex.lt"
454+
#include <stdio.h>
455+
#line 456 "lex.yy.c"
462456

463457
#define INITIAL 0
464458

@@ -640,9 +634,9 @@ YY_DECL
640634
register char *yy_cp, *yy_bp;
641635
register int yy_act;
642636

643-
#line 5 "lex_start.lt"
637+
#line 5 "lex_regex.lt"
644638

645-
#line 646 "lex.yy.c"
639+
#line 640 "lex.yy.c"
646640

647641
if ( !(yy_init) )
648642
{
@@ -695,13 +689,13 @@ YY_DECL
695689
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
696690
{
697691
yy_current_state = (int) yy_def[yy_current_state];
698-
if ( yy_current_state >= 20 )
692+
if ( yy_current_state >= 10 )
699693
yy_c = yy_meta[(unsigned int) yy_c];
700694
}
701695
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
702696
++yy_cp;
703697
}
704-
while ( yy_base[yy_current_state] != 24 );
698+
while ( yy_base[yy_current_state] != 8 );
705699

706700
yy_find_action:
707701
yy_act = yy_accept[yy_current_state];
@@ -727,25 +721,20 @@ YY_DECL
727721

728722
case 1:
729723
YY_RULE_SETUP
730-
#line 6 "lex_start.lt"
731-
printf("Stop command received");
724+
#line 6 "lex_regex.lt"
725+
printf("NUMBER\n");
732726
YY_BREAK
733727
case 2:
734728
YY_RULE_SETUP
735-
#line 7 "lex_start.lt"
736-
printf("Start command reveived");
729+
#line 7 "lex_regex.lt"
730+
printf("WORD\n");
737731
YY_BREAK
738732
case 3:
739733
YY_RULE_SETUP
740-
#line 8 "lex_start.lt"
741-
printf("Meeting you, my lord");
742-
YY_BREAK
743-
case 4:
744-
YY_RULE_SETUP
745-
#line 9 "lex_start.lt"
734+
#line 8 "lex_regex.lt"
746735
ECHO;
747736
YY_BREAK
748-
#line 749 "lex.yy.c"
737+
#line 738 "lex.yy.c"
749738
case YY_STATE_EOF(INITIAL):
750739
yyterminate();
751740

@@ -1037,7 +1026,7 @@ static int yy_get_next_buffer (void)
10371026
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
10381027
{
10391028
yy_current_state = (int) yy_def[yy_current_state];
1040-
if ( yy_current_state >= 20 )
1029+
if ( yy_current_state >= 10 )
10411030
yy_c = yy_meta[(unsigned int) yy_c];
10421031
}
10431032
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1065,11 +1054,11 @@ static int yy_get_next_buffer (void)
10651054
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
10661055
{
10671056
yy_current_state = (int) yy_def[yy_current_state];
1068-
if ( yy_current_state >= 20 )
1057+
if ( yy_current_state >= 10 )
10691058
yy_c = yy_meta[(unsigned int) yy_c];
10701059
}
10711060
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1072-
yy_is_jam = (yy_current_state == 19);
1061+
yy_is_jam = (yy_current_state == 9);
10731062

10741063
return yy_is_jam ? 0 : yy_current_state;
10751064
}
@@ -1742,7 +1731,6 @@ void yyfree (void * ptr )
17421731

17431732
#define YYTABLES_NAME "yytables"
17441733

1745-
#line 9 "lex_start.lt"
1746-
1734+
#line 8 "lex_regex.lt"
17471735
17481736

‎code/lex_regex

19.3 KB
Binary file not shown.

‎code/lex_regex.lt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
%}
44

55
%%
6-
[0-9]+ printf("NUMBER")
7-
[a-zA-Z][a-zA-Z0-9]* printf("WORD")
8-
%%
6+
[0-9]+ printf("NUMBER\n");
7+
[a-zA-Z][a-zA-Z0-9]* printf("WORD\n");
8+
%%

‎content/datetime.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ISO 8601的标准格式是:`YYYY-MM-DDTHH:mm:ss.sssZ`
1919
- `DD`:日,01 ~ 31
2020
- `T`:分隔日期和时间,可以使用 `T` 或者空格。
2121
- `HH`:小时,00 ~ 24
22+
- `hh`: 小时,0-12
2223
- `mm`:分钟,00 ~ 59
2324
- `ss`:秒,00 ~ 59
2425
- `.sss`:毫秒
@@ -115,6 +116,31 @@ format(datetime.datetime.now(), "%Y-%m-%d %H:%M")
115116

116117
### 时间格式的转换
117118

119+
python中时间日期格式化符号:
120+
121+
- `%y` 两位数的年份表示(00-99)
122+
- `%Y` 四位数的年份表示(000-9999)
123+
- `%m` 月份(01-12)
124+
- `%d` 月内中的一天(0-31)
125+
- `%H` 24小时制小时数(0-23)
126+
- `%I` 12小时制小时数(01-12)
127+
- `%M` 分钟数(00=59)
128+
- `%S` 秒(00-59)
129+
- `%a` 本地简化星期名称
130+
- `%A` 本地完整星期名称
131+
- `%b` 本地简化的月份名称
132+
- `%B` 本地完整的月份名称
133+
- `%c` 本地相应的日期表示和时间表示
134+
- `%j` 年内的一天(001-366)
135+
- `%p` 本地A.M.或P.M.的等价符
136+
- `%U` 一年中的星期数(00-53)星期天为星期的开始
137+
- `%w` 星期(0-6),星期天为星期的开始
138+
- `%W` 一年中的星期数(00-53)星期一为星期的开始
139+
- `%x` 本地相应的日期表示
140+
- `%X` 本地相应的时间表示
141+
- `%Z` 当前时区的名称
142+
- `%%` %号本身
143+
118144
```
119145
# coding=utf-8
120146

‎content/other_thing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ npm install http-server -g
7979
7. 转义
8080

8181
- re.escape 转义非法字符串
82+
- cgi.escape XSS 转义
8283

8384
```
8485
# -*- coding: utf-8 -*-

‎content/ply.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ start printf("Start command reveived");
4848

4949
使用 `lex lex_start.lt` 对其进行编译,将会生成 `lex.yy.c` 的 C 语言文件,然后使用 `cc lex.yy.c -o lex_start -ll` 生成可执行文件 `lex_start`
5050

51-
执行结果,当遇到 `start` 时,输出 `Start command reveived`,当遇到 `stop` 时,输出 `Stop command received`, 这里区分大小写,遇到其他值,则原样输出。
51+
执行结果,当遇到 `start` 时,输出 `Start command reveived`,当遇到 `stop` 时,输出 `Stop command received`, 这里区分大小写,遇到其他值,则原样输出。输入多少,输出多少,只有大小写完全匹配 `start``stop` 的时候才会有不同的回应。
5252

5353
```
5454
$ ./lex_start
@@ -78,4 +78,61 @@ no
7878
[a-z]* # 表示0个或多个字母
7979
```
8080

81+
所以我们的正则匹配就开始了
82+
83+
lex_regex.lt
84+
85+
```
86+
%{
87+
#include <stdio.h>
88+
%}
89+
90+
%%
91+
[0-9]+ printf("NUMBER\n");
92+
[a-zA-Z][a-zA-Z0-9]* printf("WORD\n");
93+
%%
94+
95+
```
96+
97+
同样的编译运行查看结果。
98+
99+
```
100+
$ lex lex_regex.lt
101+
$ cc lex.yy.c -o lex_regex -ll
102+
$ ./lex_regex
103+
2334
104+
NUMBER
105+
106+
dervr
107+
WORD
108+
109+
str1
110+
WORD
111+
112+
123avc
113+
NUMBER
114+
WORD
115+
116+
-12
117+
-NUMBER
118+
119+
12.43
120+
NUMBER
121+
.NUMBER
122+
123+
a@a
124+
WORD
125+
@WORD
126+
127+
^C
128+
```
129+
130+
看起来一切都很正常,数字和变量的定义都没问题.但是后面几个怎么看起来就不正常了,包括负数,小数,异常值。
131+
132+
#### 语法解析
133+
134+
虽然上面👆的词法解析有点小瑕疵,但是不影响,我们继续进行下一步语法解析。
135+
136+
137+
81138
[如何使用Lex/YACC](https://segmentfault.com/a/1190000000396608#articleHeader24)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /