How to design a DFA that accepts basic arithmetic expressions - dfa

For my university task I must design a Deterministic Finite Automata which recognises basic arithmetic. We're basically building a very basic lexical analyzer.
The DFA uses the operators "+,-,*,/".
The DFA has only positive numbers so expressions like "-1+1","+1+1" aren't accepted.
It can accept decimals but only when they start with 0. so "0.3415" is accepted while "1.3415" is not.
Finally it can accept just a "0" by itself.
I'm confused about the best way to approach this. I have a basic foundation of DFAs and NFAs so can someone please just give me some hints as to how I should start?
My current approach is to draw some small DFAs. One for decimal numbers, one for whole numbers, one for operators, and one that's just a 0. Then I want to concatenate them and do the union of the smaller DFAs to create one big NFA and end it by converting back to a DFA.

Related

DFA of two simple languages and then product construction of those two languages

The language below is the intersection of two simpler languages. First, identify the simpler languages and give the state diagrams of the DFAs that recognize them. Then, use the product construction to build a DFA that recognizes the language specified below; give its state diagram before and after simplification if there are any unneeded states or states that can be combined.
Language: {w is a member of {0,1}* | w contains an odd number of 0s and the sum of its 0s and 1s is equal to 1}
This is my proposed solution: https://imgur.com/a/lh5Hwfr Should the bottom two states be connected with 0s?
Also, what would be the DFA if it was OR instead of AND?
Here's a drawing I hope will help understand how to do this:
Language A is "odd number of zeros". States are labeled Z0 and Z1 indicating even or odd number of zeros.
Language B is "exactly one one" (which is equivalent to "sum of digits equals one"). States are labeled I0, I1 and I2 indicaing zero, one or more ones.
Language A+B can be interpreted as A∩B (ignoring the dotted circles) or AUB (counting the dotted circles). If building A∩B, states Z0I2 and Z1I2 can be joined together.
I hope this gives not only an answer to the exact problem in the question, but also an idea how to build similar answers for similar problems.

Insert math equation into binary tree in C

I was wondering how inserting an equation such as 5 * 4 + 2 / 3 into a binary tree would work. I have tried doing this on my own however I can only make the tree grow to one side.
I am not an expert in the field, but I wrote basic expression parsers in the past.
You will need to tokenize your expression. Transform it from a string of characters to a list of understandable chunks.
You may want to create two structures, one for operators and one for operands. Hint, operators have a priority associated with them.
You can apply an algorithm to transform your operators/operands to an abstract syntax tree (AST) it's basically just a set of rules, generally used with a queue and a stack.

For each of the following regex, draw a DFA recognizing the corresponding language

I want to draw a DFA for each of the following regex.
The first one is that
(0|1)*110*
The second one is that
(1|110)*0
I wrote lots of diagrams, but I can't draw deterministic finite automata.
how can I get these?

NFA to DFA conversion = deterministic?

I am struggling a bit with the meaning of determinism and nondeterminism. I get the difference when it comes to automata, but I can't seem to find an answer for the following: Is a NFA to DFA transformation deterministic?
If multiple DFAs can be constructed for the same regular language, does that mean that the result of a NFA to DFA transformation is not unique? And thus a nondeterministic algorithm?
I'm happy with any information you guys might be able to provide.
Thanks in advance!
There are two different concepts at play here. First, you are correct that there can be many different DFAs equivalent to the same NFA, just as there can be many NFAs that are all equivalent to one another.
Independently, there are several algorithms for converting an NFA into a DFA. The standard algorithm taught in most introductory classes on formal languages is the subset construction (also called the powerset construction). That algorithm is deterministic - there's a specific sequence of steps to follow to convert an NFA to a DFA, and accordingly you'll always get back the same DFA whenever you feed in the same NFA. You could conceivably have a nondeterministic algorithm for converting an NFA to a DFA, where the algorithm might produce one of many different DFAs as output, but to the best of my knowledge there aren't any famous algorithms of this sort.
Hope this helps!
DFA- means deterministic finite automata
Where as NFA- means non deterministic finite automata..
In dfa for every state there is a transition for both the inputs... I we have...{a, b} are the inputs for the given question.. For.. Every state there is a transition for both a and b... That automata is known as deterministic finite automata..
Where as in NDA we need not to have both input transitions for every state... At least one transition... is sufficient...
In NFA Epsilon transition is also accepted.. And dead state is also accepted...
In nfa... No of states required is less.. When compare to dfa.. Every dfa is equivalent to nfa... But every dfa is not equivalent to nfa...

NFA to DFA conversion whose language is the complement of L(A)

Can someone please help me with this question?
Describe an algorithm that converts an NFA into a DFA whose language is the complement of L(A). The complement should be taken with respect to the alphabet of A. Given an informal argument for why your construction works. You need not give a formal proof.
Any kind of guidance is appreciated...
You can convert a FA to its complement by turning its accept states into non-accept states, and turning its non-accept states into accept states. Easy!
You can convert a NFA to a DFA by considering that any NFA state is a power of the states: that is, for each state in the NFA, it is either active or not active. You can map each of these states to a state in a DFA, so you end up with at most 2|Q| states for your DFA which represents your NFA.
Edit: this algorithm and its proof do not actually need the details of A, so long as it is a valid Finite State Automaton.

Resources