From 0b58ea1a016dc99b349ae2fd733ebbad9fd785ee Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 24 Jun 2021 09:39:13 +0200 Subject: [PATCH] ? expression --- lexer.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lexer.c b/lexer.c index 6a45097..e566f68 100644 --- a/lexer.c +++ b/lexer.c @@ -10,7 +10,8 @@ enum opcode { STRING, AND, STAR, - PLUS + PLUS, + QMARK }; struct Exploration { @@ -96,6 +97,12 @@ Node *mkPlus(Node *child) return node; } +Node *mkQmark(Node *child) +{ + Node *node= mkNode(QMARK); + node->children[0]= child; + return node; +} int execute(Node *node, Exploration *in) { @@ -146,6 +153,11 @@ int execute(Node *node, Exploration *in) } } + case QMARK: { + // 0 ou 1 + if(execute(node->children[0], in)==1) return execute(node->children[0], in); + return 1; + } } printf("this cannot happen\n"); abort(); @@ -154,7 +166,7 @@ int execute(Node *node, Exploration *in) int main(int argc, char **argv) { - Exploration *in= mkExploration("aabbcc"); + Exploration *in= mkExploration("acc"); /*Node *program= mkString("aabbcc"); @@ -175,8 +187,8 @@ int main(int argc, char **argv) mkStar(mkString("c"))))); */ Node *program= - mkAnd(mkPlus(mkString("a")), // "a"*"b"*"c"* - mkAnd(mkPlus(mkString("b")), + mkAnd(mkQmark(mkString("a")), // "a"*"b"*"c"* + mkAnd(mkQmark(mkString("b")), mkPlus(mkString("c")))); if (execute(program, in)<=0)