Browse Source

PLUS et STAR

main
leo 3 years ago
parent
commit
ae199b3d0e
1 changed files with 44 additions and 11 deletions
  1. +44
    -11
      lexer.c

+ 44
- 11
lexer.c View File

@ -9,7 +9,8 @@ typedef struct Exploration Exploration;
enum opcode { enum opcode {
STRING, STRING,
AND, AND,
STAR
STAR,
PLUS
}; };
struct Exploration struct Exploration
{ {
@ -19,7 +20,7 @@ struct Exploration
Exploration *mkExploration(char *text) Exploration *mkExploration(char *text)
{ {
Exploration *exploration = calloc(1,sizeof(Exploration));
Exploration *exploration = calloc(1,sizeof(Exploration*)); //sizeof du type pointeur
exploration->position= 0; exploration->position= 0;
exploration->text= text; exploration->text= text;
return exploration; return exploration;
@ -57,6 +58,7 @@ struct Node
}; };
Node *mkNode(enum opcode type) Node *mkNode(enum opcode type)
{ {
Node *node= calloc(1, sizeof(Node)); Node *node= calloc(1, sizeof(Node));
@ -79,6 +81,7 @@ Node *mkAnd(Node *node1, Node *node2)
return node; return node;
} }
Node *mkStar(Node *child) Node *mkStar(Node *child)
{ {
Node *node= mkNode(STAR); Node *node= mkNode(STAR);
@ -86,6 +89,13 @@ Node *mkStar(Node *child)
return node; return node;
} }
Node *mkPlus(Node *child)
{
Node *node= mkNode(PLUS);
node->children[0]= child;
return node;
}
int execute(Node *node, Exploration *in) int execute(Node *node, Exploration *in)
{ {
@ -116,8 +126,25 @@ int execute(Node *node, Exploration *in)
} }
} }
case STAR: { case STAR: {
//TODO
return 0;
if(execute(node->children[0], in) == 1){
execute(node->children[0], in);
}
else return 1;
}
case PLUS: {
if(execute(node->children[0],in)==0){
return 0;
}
else{
while(execute(node->children[0], in) == 1){
execute(node->children[0], in);
}
return 1;
}
} }
} }
printf("this cannot happen\n"); printf("this cannot happen\n");
@ -136,15 +163,21 @@ int main(int argc, char **argv)
mkAnd(mkString("aab"), mkAnd(mkString("aab"),
mkString("bcc"));*/ mkString("bcc"));*/
Node *program=
/*Node *program=
mkAnd(mkString("aa"), mkAnd(mkString("aa"),
mkAnd(mkString("bb"), mkAnd(mkString("bb"),
mkString("cc")));
/*Node *program=
mkAnd(mkStar(mkString("a")), // "a"*"b"*"c"*
mkAnd(mkStar(mkString("b")),
mkStar(mkString("c")));*/
mkString("cc")));*/
/* Node *program=
mkAnd( mkString("aabbcc"),
mkAnd(mkStar(mkString("c")), // "a"*"b"*"c"*
mkAnd(mkStar(mkString("b")),
mkStar(mkString("c")))));
*/
Node *program=
mkAnd(mkPlus(mkString("a")), // "a"*"b"*"c"*
mkAnd(mkPlus(mkString("b")),
mkPlus(mkString("c"))));
if (execute(program, in)<=0) if (execute(program, in)<=0)
{ {

Loading…
Cancel
Save