Compiler design first two program
Compiler design first two program
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char input[1000];
lexicalAnalysis(input);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STATES 10
#define MAX_SYMBOLS 2
// Global variables
NFA_State nfa[MAX_STATES];
DFA_State dfa[MAX_STATES * MAX_STATES]; // DFA can have up to 2^N states
int num_nfa_states, num_dfa_states;
int symbols[MAX_SYMBOLS] = {0, 1}; // Example symbols: 0 and 1
int closure_result[MAX_STATES];
int num_closure_result;
epsilon_closure(move_result, num_move_result, closure_result, &num_closure_result);
int main() {
// Example NFA
num_nfa_states = 3;
nfa[0].num_transitions[0] = 1; nfa[0].transitions[0][0] = 1; // State 0 -> State 1 on 0
nfa[0].num_transitions[1] = 1; nfa[0].transitions[1][0] = 0; // State 0 -> State 0 on 1
nfa[1].num_transitions[0] = 1; nfa[1].transitions[0][0] = 2; // State 1 -> State 2 on 0
nfa[1].num_transitions[1] = 1; nfa[1].transitions[1][0] = 1; // State 1 -> State 1 on 1
nfa[2].num_transitions[0] = 0; // State 2 has no transitions on 0
nfa[2].num_transitions[1] = 0; // State 2 has no transitions on 1
nfa[2].is_final = 1; // State 2 is a final state
return 0;
}