LL (1) Parsing Source Code
LL (1) Parsing Source Code
text.txt
E->TA
A->+TA|^
T->FB
B->*FB|^
F->t|(E)
#include<stdio.h>
#include<string.h>
// table[i][j] stores
// jth nonterminal
int table[100][TSIZE];
// can be nonterminals
char nonterminal[26];
struct product {
char str[100];
int len;
}pro[20];
int no_pro;
char first[26][TSIZE];
char follow[26][TSIZE];
char first_rhs[100][TSIZE];
int isNT(char c) {
FILE* fptr;
char buffer[255];
int i;
int j;
printf("%s", buffer);
j = 0;
nonterminal[buffer[0] - 'A'] = 1;
if (buffer[i] == '|') {
++no_pro;
pro[no_pro - 1].len = j;
j = 3;
else {
pro[no_pro].str[j] = buffer[i];
++j;
terminal[buffer[i]] = 1;
}
pro[no_pro].len = j;
++no_pro;
int i;
if (i != '^')
int i;
if (i != '^')
void FOLLOW() {
int t = 0;
int i, j, k, x;
if (!nonterminal[k]) continue;
char nt = k + 'A';
if (nt == pro[i].str[j]) {
char sc = pro[i].str[x];
if (isNT(sc)) {
add_FIRST_A_to_FOLLOW_B(sc, nt);
if (first[sc - 'A']['^'])
continue;
else {
follow[nt - 'A'][sc] = 1;
break;
if (x == pro[i].len)
add_FOLLOW_A_to_FOLLOW_B(pro[i].str[0], nt);
}
}
int i;
if (i != '^') {
void FIRST() {
int i, j;
int t = 0;
char sc = pro[i].str[j];
if (isNT(sc)) {
add_FIRST_A_to_FIRST_B(sc, pro[i].str[0]);
if (first[sc - 'A']['^'])
continue;
else {
first[pro[i].str[0] - 'A'][sc] = 1;
break;
}
if (j == pro[i].len)
first[pro[i].str[0] - 'A']['^'] = 1;
++t;
int i;
if (i != '^')
void FIRST_RHS() {
int i, j;
int t = 0;
char sc = pro[i].str[j];
if (isNT(sc)) {
add_FIRST_A_to_FIRST_RHS__B(sc, i);
if (first[sc - 'A']['^'])
continue;
else {
first_rhs[i][sc] = 1;
break;
if (j == pro[i].len)
first_rhs[i]['^'] = 1;
++t;
int main() {
readFromFile();
follow[pro[0].str[0] - 'A']['$'] = 1;
FIRST();
FOLLOW();
FIRST_RHS();
int i, j, k;
printf("\n");
if (first[c - 'A'][j]) {
printf("\n");
printf("\n");
char c = pro[i].str[0];
if (follow[c - 'A'][j]) {
printf("\n");
}
// display first of each variable ß
// in form A->ß
printf("\n");
if (first_rhs[i][j]) {
printf("\n");
// set terminal['$'] = 1
terminal['$'] = 1;
// as input
// so we set terminal['^'] = 0
terminal['^'] = 0;
printf("\t--------------------------------------------------------\n");
printf("%-10s", "");
printf("\n");
int p = 0;
p = p + 1;
table[p][j] = i + 1;
else if (first_rhs[i]['^']) {
if (follow[pro[i].str[0] - 'A'][k]) {
table[p][k] = i + 1;
}
k = 0;
printf("%-10c", pro[i].str[0]);
if (table[k][j]) {
else if (terminal[j]) {
printf("%-10s", "");
++k;
printf("\n");