kleene-star

Find all paths in directed cyclic graph as regular expression

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 00:45:03
问题 Let G = (V,E,r) a rooted directed graph, defined by a set of vertices V and a set of edges E with a designated root node r. The graph may contain cycles. The task: Given two vertices x and y from V, find all paths from x to y. Since cycles are allowed, the set of paths may obviously be infinite. Therefore, I want to find the set of paths in the form of a regular expression (Kleene Algebra). Here are a few examples: Examples graphs. Multiplication means sequence, so a path abc means first a,

Automata with kleene star

蹲街弑〆低调 提交于 2019-12-12 17:42:58
问题 Im learning about automata. Can you please help me understand how automata with Kleene closure works? Let's say I have letters a,b,c and I need to find text that ends with Kleene star - like ab*bac - how will it work? 回答1: The question seems to be more about how an automaton would handle Kleene closure than what Kleene closure means. With a simple regular expression, e.g., abc , it's pretty straightforward to design an automaton to recognize it. Each state essentially tells you where you are

How do I rewrite a context free grammar so that it is LR(1)?

江枫思渺然 提交于 2019-12-08 09:12:14
问题 For the given context free grammar: S -> G $ G -> PG | P P -> id : R R -> id R | epsilon How do I rewrite the grammar so that it is LR(1)? The current grammar has shift/reduce conflicts when parsing the input "id : .id", where "." is the input pointer for the parser. This grammar produces the language satisfying the regular expression (id:(id)*)+ 回答1: It's easy enough to produce an LR(1) grammar for the same language. The trick is finding one which has a similar parse tree, or at least from

Ambiguity in transition: How to process string in NFA?

时光毁灭记忆、已成空白 提交于 2019-11-27 07:12:02
问题 I have made DFA from a given regular expression to match the test string. There are some cases in which .* occurs. ( for example .*ab ) . Let say now the machine is in state 1. In the DFA, .* refers to the transition for all the characters to itself and another transition for a from the state 1 for 'a'. If test string contains 'a' then what could be the transition because from state 1, machine can go to two states that is not possible in DFA. 回答1: I start with fundamental with your example so