#identifier state is undefined issue

9 messages · Page 1 of 1 (latest)

young umbraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

winter vector
#

this isn't python, you need to enclose scopes with {}

#

indentations have "no meaning"

#

and characters are single quotes

#

and you need semicolons to end statements

#

and you're missing a bunch of assignment operators

#
#include <iostream>
#include <string>

using namespace std;

//(TT + G)* (A + T)

bool DFA(string S) {
  int x = 0;
  int yes = false;
  char state = 'S';

  for (auto x : S) {
    if (state == 'S') {
      if (x == 'T')
        state = '1';
      else
        state = '2';
    }

    if (state = '2') {
      if (x == 'T')
        state = '1';
      else
        state = '3';
    }

    if (state == '2') {
      if (x == 'T')
        state == '3';
      else
        state = '2';
    }

    if (state == '3') {
      if (x == 'a' or x == 'b') state == '3';
    }
  }

  if (state == '1' or state == '2') {
    yes = true;
    return yes;
  }
}
#

to iterate over some container, you can use the for (auto x : S) { syntax, where x is an element (char) of S (string)

young umbraBOT
#

This question thread is being automatically marked as solved.