finite-automata

How to determine if a context-free grammar describes a regular language?

旧时模样 提交于 2021-02-19 07:56:05
问题 Given an arbitrary context-free grammar, how can I check whether it describes a regular language? I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code. If it helps, here's an example of a CFG that I might receive as an input. Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular. S: A B C D

I can't find the leftmost and rightmost derivations of strings because there is no Non-terminal state linked to another non-terminal state

青春壹個敷衍的年華 提交于 2020-08-10 19:58:26
问题 The following grammar generates the language of regular expression S → A | B | C A → 0A1 | 1 | A1 B → 0B1 | 0 | 0B C → D10D D → empty | 0D | 1D Give leftmost and rightmost derivations of the following strings: 010100 000011 来源: https://stackoverflow.com/questions/62273171/i-cant-find-the-leftmost-and-rightmost-derivations-of-strings-because-there-is

What is the most efficient way to create a lexer?

偶尔善良 提交于 2020-06-11 09:45:07
问题 I am currently trying to learn how to create my own lexical analyser, by hand. I had been using Flex (along with Bison) a lot to practice and learn how it works internally, but I am currently seeing at least 3 different solutions to develop my own. Using a list of REs, going through each and when one matches, simply return the associated token (see python docs about REs) Creating a DFA from REs (as does Flex for example: based on REs, create a big state machine) Creating my own 'state machine

What is the most efficient way to create a lexer?

偶尔善良 提交于 2020-06-11 09:45:01
问题 I am currently trying to learn how to create my own lexical analyser, by hand. I had been using Flex (along with Bison) a lot to practice and learn how it works internally, but I am currently seeing at least 3 different solutions to develop my own. Using a list of REs, going through each and when one matches, simply return the associated token (see python docs about REs) Creating a DFA from REs (as does Flex for example: based on REs, create a big state machine) Creating my own 'state machine

A finite possibly non-deterministic state machine with dwell durations

こ雲淡風輕ζ 提交于 2020-01-17 06:24:28
问题 after posting a somewhat ambiguous question, I believe I have nailed that what I am wondering (I am a complete novice in FSMs). I would like to simulate a state space using finite state machines (possibly non-deterministic automata i.e. multiple next-state transitions allowed) in clojure. This is essentially my problem: Suppose we have these states Q={flying,cycling,running,driving} and we have the state durations for each during an average day D={120,30,30,60} - where for the sake of

NFA to DFA Algorithm

半腔热情 提交于 2020-01-14 06:12:08
问题 I've read a text file of symbols, states and transitions and put it all in a table. It looks like this: symbols a, b states q1, q2, q3, q4 start state q4 final state q2, q3 transition state: q4, epsilon, q1 q1, a, q2 q3, a, q3 q3, b, q1 I've read an algorithm on how to convert NFA to DFA but I don't really understand the algorithm. How would I create transition methods and what should I have state class? 回答1: i have a nifty link right here: JFLAP JFLAP is an Java JAR which has some nice

(FInite State Machine) - Implementing a XML schema validator in javascript

二次信任 提交于 2020-01-13 01:42:10
问题 I have been working on a project for a month or so now to develop a XML validator (XSD) in javascript. I have gotten really close but keep running into problems. The only thing I have working well is normalizing schema structures into FSA that I store in the DOM. I have tried several methods to validate my xml structures against the FSA and come short each time. The validator is being used to run a client side WYSIWYG XML editor so it has to meet the following requirements Must be efficient (

This NFA to DFA conversion is confusing me

人盡茶涼 提交于 2020-01-05 06:42:13
问题 I'm trying to convert this NFA into DFA. I have the transition table for both the NFA and DFA: I have then tried to set up different states for the empty strings. But whatever i do i keep getting a DFA that doesn't work with the original NFA. I'm a bit over going round in circles, can someone show me what i'm doing wrong? 回答1: Well, as I understand it, the algorithm to produce an equivalent DFA for an NFA takes as the set of states of the DFA the power set of the set of states of the NFA;

How to perform FST (Finite State Transducer) composition

我怕爱的太早我们不能终老 提交于 2020-01-01 02:34:09
问题 Consider the following FSTs : T1 0 1 a : b 0 2 b : b 2 3 b : b 0 0 a : a 1 3 b : a T2 0 1 b : a 1 2 b : a 1 1 a : d 1 2 a : c How do I perform the composition operation on these two FSTs (i.e. T1 o T2) I saw some algorithms but couldn't understand much. If anyone could explain it in a easy way it would be a major help. Please note that this is NOT a homework. The example is taken from the lecture slides where the solution is given but I couldn't figure out how to get to it. 回答1: Since you

To use goto or not?

本小妞迷上赌 提交于 2019-12-29 04:16:05
问题 This question may sound cliched, but I am in a situation here. I am trying to implement a finite state automaton to parse a certain string in C. As I started writing the code, I realised the code may be more readable if I used labels to mark the different states and use goto to jump from one state to another as the case comes. Using the standard breaks and flag variables is quite cumbersome in this case and hard to keep track of the state. What approach is better? More than anything else I am