Skip to content

Commit 676dd07

Browse files
authored
Add files via upload
1 parent b4477e9 commit 676dd07

16 files changed

+782
-100
lines changed

coding details proforma.docx

25.2 KB
Binary file not shown.

def.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Group 28
3+
Utkarsh Kumar 2017B2A71008P
4+
Suchisattam Saran 2017B2A70585P
5+
Supratik Bhattacharya 2017B2A70745P
6+
*/
7+
#include<stdio.h>
8+
#include<stdlib.h>
9+
10+
typedef struct tokenStream
11+
{
12+
char token[20];
13+
char lexeme[20];
14+
int linenumber;
15+
struct tokenStream *next;
16+
} tokenStream;
17+
18+
typedef struct data {
19+
char symbol[20];
20+
struct data *next;
21+
}data;
22+
23+
typedef data* grammar;
24+
typedef data node;
25+
26+
int x;
27+
28+
typedef struct parseTree
29+
{
30+
char sym[25];
31+
int line;
32+
int term;
33+
int key;
34+
int gram;
35+
struct parseTree *child;
36+
}parseTree;
37+
38+
typedef struct ope {
39+
char sym[5];
40+
struct ope *next;
41+
} ope;
42+
typedef struct ope ope;
43+
typedef struct string {
44+
char term[20];
45+
struct string *next;
46+
}string;
47+
typedef struct string string;
48+
typedef struct dataEntry {
49+
int dec;
50+
int type;
51+
int sizeofArray;
52+
ope *list;
53+
string *stringlist;
54+
}dataEntry;
55+
56+
char * getToken(char *lexeme);
57+
char * stripTab(char *t);
58+
tokenStream * tokeniseSourcecode( char *f, tokenStream *s);
59+
grammar getPoint(grammar G);
60+
grammar readGrammar(FILE *fp, grammar G);
61+
parseTree *createParse(parseTree *t, tokenStream *s, grammar G);
62+
parseTree *createParseTree(parseTree *t, tokenStream *s, grammar G);

driver.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Group 28
3+
Utkarsh Kumar 2017B2A71008P
4+
Suchisattam Saran 2017B2A70585P
5+
Supratik Bhattacharya 2017B2A70745P
6+
*/
7+
#include<stdio.h>
8+
#include<stdlib.h>
9+
#include<string.h>
10+
#include "def.h"
11+
//#include "read.h"
12+
13+
void printParseTree(parseTree *t)
14+
{
15+
if(t != NULL)
16+
{
17+
char term[5] = "NO";
18+
char gram[5] = "NA";
19+
if(t->term)
20+
strcpy(term, "YES");
21+
if(t->gram)
22+
printf("\nSymbol : %s, line : %d, term? : %s, keyword? : %d, Grammar : %d\n",t->sym, t->line, term, t->key, t->gram);
23+
24+
else
25+
printf("\nlabel : %s, line : %d, term? : %s, keyword? : %d, Grammar : %s\n",t->sym, t->line, term, t->key, gram);
26+
printParseTree(t->child);
27+
}
28+
fflush(stdout);
29+
return;
30+
}
31+
32+
int main()
33+
{
34+
tokenStream *s =NULL;
35+
char filename[20];
36+
printf("enter name of test case file (example : t1.txt): ");
37+
scanf("%s",&filename);
38+
s = tokeniseSourcecode(filename, s);
39+
tokenStream *ptr = s;
40+
grammar G = getPoint(G);
41+
FILE *fp2 = fopen("group_28_grammar.txt", "r");
42+
G = readGrammar(fp2, G);
43+
parseTree *t = NULL;
44+
int option = 1;
45+
while(option != 0){
46+
printf("\nprovide options for the file (0-4): ");
47+
scanf("%d", &option);
48+
switch(option)
49+
{
50+
case 0:
51+
break;
52+
case 1:
53+
t = createParseTree(t, s, G); break;
54+
case 2:
55+
printf("Traversal in level order not implemented !\n"); break;
56+
case 3:
57+
if(t != NULL){
58+
printParseTree(t); break;}
59+
else
60+
{printf("Create tree first (option = 1)\n"); break;}
61+
case 4:
62+
printf("type expression table not implemented fully !\n"); break;
63+
default :
64+
printf("Not an option!\n");
65+
}
66+
}
67+
return 0;
68+
}

group_28_grammar.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<program> -> PROGRAM ROOP ROCL BROP <stmt> BRCL
2+
<stmt> -> DECLARE <declaretype> COLON <typespecifier> <stmt>
3+
<stmt> -> STRINGCONST <assilhs> <stmt>
4+
<stmt> -> EPS
5+
<declaretype> -> LIST OF VARIABLES STRINGCONST <stringlist>
6+
<declaretype> -> STRINGCONST
7+
<stringlist> -> STRINGCONST <stringlist>
8+
<stringlist> -> EPS
9+
<typespecifier> -> INTEGER SEMICOLON
10+
<typespecifier> -> REAL SEMICOLON
11+
<typespecifier> -> BOOLEAN SEMICOLON
12+
<typespecifier> -> ARRAY <rangedim> OF INTEGER SEMICOLON
13+
<typespecifier> -> JAGGED ARRAY SQOP <low> DOT <high> SQCL <bracketlist> OF INTEGER SEMICOLON <jaggedlist>
14+
<rangedim> -> SQOP <low> DOT <high> SQCL <rangedim>
15+
<rangedim> -> EPS
16+
<low> -> NUM
17+
<low> -> STRINGCONST
18+
<high> -> NUM
19+
<high> -> STRINGCONST
20+
<bracketlist> -> SQOP SQCL <bracketlist>
21+
<bracketlist> -> EPS
22+
<jaggedlist> -> RONE SQOP NUM SQCL COLON SIZE NUM COLON VALUES BROP <arglist> BRCL <jaggedlist>
23+
<jaggedlist> -> RTWO SQOP NUM SQCL COLON SIZE NUM COLON VALUES BROP <arglist> BRCL <jaggedlist>
24+
<jaggedlist> -> RTHREE SQOP NUM SQCL COLON SIZE NUM COLON VALUES BROP <arglist> BRCL <jaggedlist>
25+
<jaggedlist> -> EPS
26+
<arglist> -> NUM <args> <sep> <arglist>
27+
<arglist> -> EPS
28+
<sep> -> SEMICOLON
29+
<sep> -> EPS
30+
<args> -> NUM <args>
31+
<args> -> EPS
32+
<assilhs> -> SQOP <args> SQCL EQUAL STRINGCONST <term> SEMICOLON
33+
<assilhs> -> EQUAL STRINGCONST <term> SEMICOLON
34+
<term> -> MUL STRINGCONST <term>
35+
<term> -> DIV STRINGCONST <term>
36+
<term> -> PLUS STRINGCONST <term>
37+
<term> -> MINUS STRINGCONST <term>
38+
<term> -> AND STRINGCONST <term>
39+
<term> -> OOR STRINGCONST <term>
40+
<term> -> SQOP <args> SQCL <term>
41+
<term> -> EPS
42+
<bool> -> EPS

makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
GY = "./"
2+
3+
.DEFAULT_GOAL := TARGET
4+
RUN : driver.c read.c token.c parseTree.c
5+
gcc -o exeRUN driver.c read.c token.c parseTree.c
6+
TARGET : RUN
7+
$(GY)exeRUN

nonterminals.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<program>
2+
<stmt>
3+
<declaretype>
4+
<stringlist>
5+
<typespecifier>
6+
<rangedim>
7+
<low>
8+
<high>
9+
<bracketlist>
10+
<jaggedlist>
11+
<arglist>
12+
<sep>
13+
<args>
14+
<assilhs>
15+
<term>

0 commit comments

Comments
 (0)