瀏覽代碼

added class with the array of bit

main
benoit.thomas 4 年之前
父節點
當前提交
ffdf5112bc
共有 1 個檔案被更改,包括 7 行新增10 行删除
  1. +7
    -10
      parse.leg

+ 7
- 10
parse.leg 查看文件

@ -7,6 +7,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "inputBuffer.c" #include "inputBuffer.c"
#include "class.c"
; ;
void fatal(char *fmt, ...) void fatal(char *fmt, ...)
@ -38,7 +39,7 @@ struct Star { enum op type; Node *children[1]; };
struct Plus { enum op type; Node *children[1]; }; struct Plus { enum op type; Node *children[1]; };
struct Or { enum op type; Node *children[2]; }; struct Or { enum op type; Node *children[2]; };
struct And { enum op type; Node *children[2]; }; struct And { enum op type; Node *children[2]; };
struct Class { enum op type; char *stringValue; int len; };
struct Class { enum op type; char *array; };
struct Dot { enum op type; }; struct Dot { enum op type; };
struct Exc { enum op type; Node *children[1]; }; struct Exc { enum op type; Node *children[1]; };
struct Et { enum op type; Node *children[1]; }; struct Et { enum op type; Node *children[1]; };
@ -140,8 +141,7 @@ Node *mkStar(Node *n)
Node *mkClass(char* str) Node *mkClass(char* str)
{ {
Node *node= new(Class); Node *node= new(Class);
node->Class.stringValue= str;
node->Class.len=strlen(str);
node->Class.array= str;
return node; return node;
} }
@ -211,7 +211,7 @@ void print(Node *node)
return; return;
case Class: case Class:
printf("Class"); printf("Class");
printf("\"%s\"", node->Class.stringValue);
printf("\"%s\"", node->Class.array);
return; return;
case Dot: case Dot:
printf("Dot"); printf("Dot");
@ -317,7 +317,7 @@ id = < [a-zA-z_][a-zA-z_0-9]* > - { $$ = mkId(intern(yytext)) }
string = '"' < [^\"]* > '"' - { $$ = mkString(yytext) } string = '"' < [^\"]* > '"' - { $$ = mkString(yytext) }
class = '['-<(!']'string)*> ']' - { $$=mkClass(yytext) }
class = '['-<(!']'string)*> ']' - { $$=mkClass(classify(yytext)) }
dot = '.' - { $$=mkDot() } dot = '.' - { $$=mkDot() }
@ -367,11 +367,8 @@ int execute(Node *node, InputBuffer *in)
return 1; return 1;
} }
case Class: { case Class: {
if (!currentChar(in)) {
return 0;
}
if (strchr(get(node,Class,stringValue), currentChar(in))) {
advance(in, 1);
if (testBit(get(Node,Class,array),currentChar(in))) {
advance(in, 1);
return 1; return 1;
} }
return 0; return 0;

Loading…
取消
儲存