0

I'm looking at an exam question which says

'Explain how a correctly formed arithmetic expression over variables a, b, c that contains additions, multiplication and brackets can be recognised by a DFA with a counter. (Such a DFA can increment and decrement the counter on each transition as well as test it for zero).'

I'm not quite sure I understand what it's actually asking. If someone could provide a hint that would be greatly appreciated. (i.e. what the multiplication of a and b would be for example)

  • 1
    I'm voting to close this question as off-topic because this is not related to programming directly! This *maybe* a better fit for CS Stack Exchange! – Am_I_Helpful May 13 '18 at 17:31

1 Answers1

1

If all you want is just a hint, then I think this should be enough:

  1. Some strings represent valid arithmetic expressions such as
a + b
(a + b)*(c + d)

and some are invalid such as

a + - b
a b
)
()
(a + b)*)c+d(
  1. "can be recognised by a DFA with a counter" here means that you can build a Deterministic finite automaton such that it stops at one of the "accept states" after processing a sting if and only if that string represents a valid arithmetic expression

P.S. Additional hint: the counting part is important here because a simple DFA can't even recognize whether an arbitrary string of brackets is properly matched.

SergGr
  • 23,570
  • 2
  • 30
  • 51
  • So would it just be a DFA such that each transition adds to the expression, from the alphabet of a,b,c,+,*,(,), and each time an open bracket is read, the counter is incremented, and when the closed bracket is read it is decremented, and only when it is 0 does it accept an input? – Sonya Arnolds May 13 '18 at 21:27
  • @SonyaArnolds, It is correct general direction but that's not enough. Look closer at my invalid examples. Some of them will be accepted by your DFA. – SergGr May 13 '18 at 22:11