-1

I am tasked with a program that is a scanner. My alphabet is as follows:

all english letters (upper and lower), digits, 
plus the extra character _ (underscore) & ws. Identifier begins with a letter and can 
continue with any number of letters, digits or _ up to 10 significant characters.

I am wanting to make sure my table is correct. For some reason my scanner is not working with the underscore. I can get it work for letters and digits. I am trying to narrow down my problem and wanting to make sure it is not the table.

Here is my table, just a partial part:

// state token      ws    L   D   _   
 {   0,  0,         0,    1, 11,  21, 
 {   1,  id_tk,    -1,    2,  2,   2,
 {   2,  id_tk,    -1,    3,  3,   3,
 {   3,  id_tk,    -1,    4,  4,   4,
 {   4,  id_tk,    -1,    5,  5,   5,
 {   5,  id_tk,    -1,    6,  6,   6,
 {   6,  id_tk,    -1,    7,  7,   7,
 {   7,  id_tk,    -1,    8,  8,   8,
 {   8,  id_tk,    -1,    9,  9,   9,
 {   9,  id_tk,    -1,   10, 10,  10,
 { 10, id_tk,      -1,   -2, -2,  -2,
 { 11, num_tk,     -1,   -1, 12,  -2,
 { 12, num_tk,     -1,   -1, 13,  -2,
 { 13, num_tk,     -1,   -1, 14,  -2,
 { 14, num_tk,     -1,   -1, 14,  -2,
 { 15, num_tk,     -1,   -1, 15,  -2,
 { 16, num_tk,     -1,   -1, 16,  -2,
 { 17, num_tk,     -1,   -1, 17,  -2,
 { 18, num_tk,     -1,   -1, 18,  -2,
 { 19, num_tk,     -1,   -1, 19,  -2,
 { 20, num_tk,     -1,   -1, 20,  -2,
 { 21, undrs_tk,   -1,   -2, -2,  -2,

Legend is as follows:

WS = whitespace
L = letter
D = digit
_ = underscore

-1 = final state
-2 = error state

Is this table correct with the above mentioned alphabet? I really appreciate the help. Thanks

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
c_sharp
  • 281
  • 1
  • 5
  • 13
  • It's not clear to me what you're asking -- perhaps you can provide some more context, or an example showing what you're looking for? Be sure also to check the [question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). Thanks! – Christian Ternus Oct 30 '13 at 20:39
  • 2
    you want us to check a table (which you only partially give and not syntactically correct) that's used in code that we can't see? – Keith Nicholas Oct 30 '13 at 20:40
  • @KeithNicholas Code would not be needed if one is familiar with finite state automata tables. Also code is very lengthy. – c_sharp Oct 30 '13 at 20:43
  • @ChristianTernus question has been clarified. – c_sharp Oct 30 '13 at 20:44
  • "Code would not be needed" is almost always wrong. See [SSCCE.org](http://sscce.org) and the [Stack Overflow Question Checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). – Christian Ternus Oct 30 '13 at 20:47
  • No reason for a down vote. This is a very legitimate question. I did not ask for anyone to write code, I did not ask for anyone to come up with the table and question has definitely and distinctly been stated – c_sharp Oct 30 '13 at 20:47
  • its not that you're asking for code, your question is poor, you have stated you have a problem ( not even an attempt to describe exactly the nature of that problem) you've presented a syntactically incorrect table assuming there might be a problem with it. If you are asking us to check it, that's not a question and isn't valid. If you are trying to get help with the real problem, you have given too little detail. – Keith Nicholas Oct 30 '13 at 20:51
  • Forget it. Thanks for the down votes. – c_sharp Oct 30 '13 at 20:51
  • downvotes aren't an attack, they just say your question is poor, just think about how you can package up your problem into something someone else can reason about and come up with an answer. And yes, sometimes getting your problem into a good question is hard! – Keith Nicholas Oct 30 '13 at 20:53

1 Answers1

1

Your spec says an identifier has 10 significant characters, which usually means that the identifier can be longer, one just ignores any characters beyond 10 for comparison purposes. Your automaton rejects any identifier that's longer than 10 characters.

Your spec does not specify what num_tk and undrs_tk should be, so I cannot comment on them.

There is no obvious problem with your handling of underscore in the table. If it doesn't work, the problem is likely in your driver code, which you do not show.

ibid
  • 3,891
  • 22
  • 17