Thread: Building a NFA help

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    7

    Building a NFA help

    I am trying to create a NFA from a regular expression. I have a grasp on reading in the regular expression and being able to make a stack from it. The part I am struggling on is mapping the characters in the regular expression to an integer indicating the variables order in the expression. I am just not sure how to go about this. Any help is welcome. My code so far...

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include "stack.h"
    
    
    int main(void)
    {
    	char expression[80];//array to store regular expression
    	char capital[130];//Array to store capital letters
    	int i=0,x=0,y=0,z=65;
    	char input;
    
    
    	while(scanf("%c",&input) != EOF){//check for end of input
    		if(!isspace((unsigned char)input)){//skip whitespaces
    			if((input != ')')&&(input != '(')){
    				for(i=i;i<80;i++){//initialize array with input
    					expression[x]=input;
    					x++;
    					break;
    				}
    				for(y=y;y<91;y++){//initialize letter array
    					if(input>=65 && input<=90){//check for capital
    						capital[input]=input;
    						pushChar(input);
    					}
    					break;
    				}
    			}
    		}
    	}
    
    
    
    
    	for(z=z;z<91;z++){
    		if(capital[z]>=65 && capital[z]<=90){//Print each letter once
    			printf("%c ",capital[z]);
    		}
    	}
    	printf("\n\n");
    
    
    	for(i=0;i<x;i++)//printing full regular expression
    		printf("%c",expression[i]);
    
    
    
    
    	printf("\n");
    
    
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    120
    Quote Originally Posted by crashband View Post
    Code:
    for(i=i;i<80;i++){//initialize array with input
        expression[x]=input;
        x++;
        break;
    }
    for(y=y;y<91;y++){//initialize letter array
        if(input>=65 && input<=90){//check for capital
            capital[input]=input;
            pushChar(input);
        }
        break;
    }
    What is the logic behind using for loop like this? I don't see any.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    7
    Quote Originally Posted by DRK View Post
    What is the logic behind using for loop like this? I don't see any.
    It is to put the full regular expression in one array and just the capital letters in another. It worked which I guess is the most important thing. How would you have put it?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by crashband View Post
    It is to put the full regular expression in one array and just the capital letters in another. It worked which I guess is the most important thing. How would you have put it?
    Probably with strcpy and isupper. (Admittedly I don't really know why we care about capitals, but I'm assuming you know so I guess that's okay.)

    As to the question, I'm not sure I know what you mean by this mapping. Do you mean you want an array such that, if (say) the first parenthesized expression matched characters 18-21 in the array, then array[17] through array[20] would be 1? Or something else?

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    7
    Quote Originally Posted by tabstop View Post
    Probably with strcpy and isupper. (Admittedly I don't really know why we care about capitals, but I'm assuming you know so I guess that's okay.)

    As to the question, I'm not sure I know what you mean by this mapping. Do you mean you want an array such that, if (say) the first parenthesized expression matched characters 18-21 in the array, then array[17] through array[20] would be 1? Or something else?
    By mapping I mean mapping one of the letters to an integer and the integer will represent the column numbers in the state table. That is how my professor put it if that makes sense.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by crashband View Post
    By mapping I mean mapping one of the letters to an integer and the integer will represent the column numbers in the state table. That is how my professor put it if that makes sense.
    Juuuust realized that we're talking about those kinds of regular expressions. Anyway.

    First off: you should probably try to forget 65 and 90. You can use 'A' and 'B' and ... and 'Z' as numbers already (because they are). I'm assuming the capital letters are your input/alphabet? If so, I don't see a reason to keep a bunch of columns around that you're not going to use; I would suggest just creating 26 columns, and address them using 'A' - 'A', 'B' - 'A' , ..., 'Z' - 'A'.

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    1
    Any luck with your code?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with building
    By Darkinyuasha1 in forum Windows Programming
    Replies: 1
    Last Post: 02-10-2013, 03:00 AM
  2. GUI building, is RAD the way to go?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-21-2007, 09:36 PM
  3. need help with building DLL
    By Frantic- in forum C++ Programming
    Replies: 6
    Last Post: 06-25-2005, 11:10 PM
  4. building/using dll's
    By bluehead in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2005, 07:03 AM
  5. building pc..
    By Shadow in forum Tech Board
    Replies: 13
    Last Post: 01-08-2003, 07:53 PM