-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.c
More file actions
652 lines (553 loc) · 18.7 KB
/
parser.c
File metadata and controls
652 lines (553 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*
*Batch Number 6
*Abhinav Bhatia (2011A7PS371P)
*Mukul Bhutani (2011A7PS343P)
*/
#include "definitions.h"
#include "parser.h"
#include "compiler.h"
#include "first.h"
#include "follow.h"
char usefullArray[NO_RULES][MAX_NO_RHS + 1];
Grammar populateRules(FILE *fp)
{
Grammar grammar;
LinkList allGrammarRules = linkList_createNew((int(*)(void*, void*))compareRulesByReference);
char line[LINE_LENGTH];
Rule* newRule;
int SymbolCount = 0;
int ruleNoInGrammar = 0;
Symbol* dollar;
HashSet nonTerminalSet = set_create(MAX_NO_SYMBOLS, (int(*)(void*, void*)) symbolCompareByName, hashFunctionForSymbols);
HashSet terminalSet = set_create(MAX_NO_SYMBOLS, (int(*)(void*, void*))symbolCompareByName, hashFunctionForSymbols);
Symbol* epsilon = (Symbol*)malloc(sizeof(Symbol));
epsilon->symbolID = 0;
epsilon->isNonTerminal = 0;
strcpy(epsilon->symbolName, "e");
grammar.epsilon = epsilon;
terminalSet = set_add(terminalSet, epsilon);
dollar = (Symbol*)malloc(sizeof(Symbol));
dollar->symbolID = 1;
dollar->isNonTerminal = 0;
strcpy(dollar->symbolName, "$");
grammar.dollar = dollar;
terminalSet = set_add(terminalSet, dollar);
while (1)
{
if (fscanf(fp, "%s", line) > 0)
{
Symbol* newSymbol;
ruleNoInGrammar++;
newRule = (Rule*)malloc(sizeof(Rule));
newRule->lhs = NULL;
newRule->no_of_rhs = 0;
newRule->rhsSymbols = linkList_createNew((int(*)(void*, void*))symbolCompareByName);
newRule->ruleNo = ruleNoInGrammar;
newSymbol = (Symbol*)malloc(sizeof(Symbol));
newSymbol->isNonTerminal = 1;
strcpy(newSymbol->symbolName, line);
// should compare with symbol name
if (set_contains(nonTerminalSet, newSymbol))
{
newRule->lhs = (Symbol*)set_getElement(nonTerminalSet, newSymbol);
free(newSymbol);
}
else
{
newSymbol->symbolID = nonTerminalSet.hashTable.size;
nonTerminalSet = set_add(nonTerminalSet, newSymbol);
newRule->lhs = newSymbol;
}
//now for RHS
while (1)
{
fscanf(fp, "%s", line);
if (strcmp(line, "->") == 0)
continue;
else
{
if (line[0] == '<')
{
newSymbol = (Symbol*)malloc(sizeof(Symbol));
newSymbol->isNonTerminal = 1;
strcpy(newSymbol->symbolName, line);
/// should compare with symbol name
if (set_contains(nonTerminalSet, newSymbol))
{
newRule->rhsSymbols = linkList_addToTail(newRule->rhsSymbols, set_getElement(nonTerminalSet, newSymbol));
newRule->no_of_rhs = newRule->rhsSymbols.size;
free(newSymbol);
}
else
{
newSymbol->symbolID = nonTerminalSet.hashTable.size;
nonTerminalSet = set_add(nonTerminalSet, newSymbol);
newRule->rhsSymbols = linkList_addToTail(newRule->rhsSymbols, newSymbol);
}
}
else if (strcmp(line, ".") == 0)
{
allGrammarRules = linkList_addToTail(allGrammarRules, newRule);
break;
}
else
{ //this time its a terminal
newSymbol = (Symbol*)malloc(sizeof(Symbol));
newSymbol->isNonTerminal = 0;
strcpy(newSymbol->symbolName, line);
/// should compare with symbol name
if (set_contains(terminalSet, newSymbol))
{
newRule->rhsSymbols = linkList_addToTail(newRule->rhsSymbols, set_getElement(terminalSet, newSymbol));
newRule->no_of_rhs = newRule->rhsSymbols.size;
free(newSymbol);
}
else
{
newSymbol->symbolID = terminalSet.hashTable.size;
terminalSet = set_add(terminalSet, newSymbol);
newRule->rhsSymbols = linkList_addToTail(newRule->rhsSymbols, newSymbol);
}
}
}
}
}
else
break;
}
grammar.nonTerminalSet = nonTerminalSet;
grammar.terminalsSet = terminalSet;
grammar.rules = allGrammarRules;
return grammar;
}
void printRule(Rule* r)
{
LinkListNode* rhsItr;
printf("%s -> ", r->lhs->symbolName, r->lhs->symbolID);
for (rhsItr = r->rhsSymbols.head; rhsItr != NULL; rhsItr = rhsItr->next)
{
Symbol* s = (Symbol*)rhsItr->element;
printf("%s ", s->symbolName, s->symbolID);
}
}
void printRules(Grammar g)
{
LinkListNode* itr;
for (itr = g.rules.head; itr != NULL; itr = itr->next)
{
Rule* currentRule = (Rule*)itr->element;
printRule(currentRule);
printf("\n");
}
}
Parser parser_initialise(FILE* grammarInputFile, FILE* astRulesFile)
{
Parser p;
int row;
printf("\nInitializing parser.....");
printf("\nReading Grammar Rules...");
p.grammar = populateRules(grammarInputFile);
initUsefulArray(astRulesFile);
printf("\nSuccessfully Read Grammar Rules :)");
//printRules(p.grammar);
//Allocate and clean memory for the parse table:
p.parseTable = (Rule***)malloc(p.grammar.nonTerminalSet.hashTable.size*sizeof(Rule**));
for (row = 0; row < p.grammar.nonTerminalSet.hashTable.size; row++)
{
int col;
p.parseTable[row] = (Rule**)malloc(p.grammar.terminalsSet.hashTable.size*sizeof(Rule*));
for (col = 0; col < p.grammar.terminalsSet.hashTable.size; col++)
{
p.parseTable[row][col] = NULL;
}
}
printf("\nCreating parse table...");
createParseTable(p.grammar, p.parseTable);
printf("\nParse Table created :)\n");
p.parseTree = tree_createNew();
return p;
}
void createParseTable(Grammar grammar, ParseTable parseTable)
{
LinkListNode* itr;
HashSetIterator columnIterator;
int isLL1 = 1;
for (itr = grammar.rules.head; itr != NULL; itr = itr->next)
{
int rowNo;
Rule* rule = (Rule*)itr->element;
//printf("\n\nConsidering Rule: "); printRule(rule); printf("\n");
HashSet correspondingTerminals;
HashSet firstSet = first(rule->rhsSymbols, grammar);
//
/*printf("First of %s = ", rule->lhs->symbolName);
HashSetIterator itr = set_getIterator(firstSet);
while (!set_iterationEnded(firstSet, itr))
{
Symbol* fi = (Symbol*)itr.bucketNode->element;
printf("%s, ", fi->symbolName);
itr = set_getNextIterator(firstSet, itr);
}
printf(" ");*/
//
if (set_contains(firstSet, grammar.epsilon))
{
HashSet followSet = follow(rule->lhs, grammar);
/*printf("Follow of %s = ", rule->lhs->symbolName);
HashSetIterator itr = set_getIterator(followSet);
while (!set_iterationEnded(followSet, itr))
{
Symbol* fo = (Symbol*)itr.bucketNode->element;
printf("%s, ", fo->symbolName);
itr = set_getNextIterator(followSet, itr);
}
printf(" ");*/
correspondingTerminals = set_union(firstSet, followSet);
firstSet = set_clear(firstSet);
followSet = set_clear(followSet);
}
else
{
correspondingTerminals = firstSet;
}
rowNo = rule->lhs->symbolID;
for (columnIterator = set_getIterator(correspondingTerminals); !set_iterationEnded(correspondingTerminals, columnIterator); columnIterator = set_getNextIterator(correspondingTerminals, columnIterator))
{
int col = ((Symbol*)columnIterator.bucketNode->element)->symbolID;
if (parseTable[rowNo][col] != NULL)
{
printf("\n\nGrammar Not LL1: Conflicting rules for (%d,%d):\n", rowNo, col);
printRule(parseTable[rowNo][col]); printf("\n");
printRule(rule);
printf("\nThe latter rule will be retained for this cell\n");
isLL1 = 0;
}
parseTable[rowNo][col] = rule;
}
correspondingTerminals = set_clear(correspondingTerminals);
}
if (isLL1) printf("\nThe grammar is LL1.. OK :)");
}
int compareRulesByReference(Rule* r1, Rule* r2)
{
return r1 == r2;
}
Symbol* findSymbolByName(char* symbolString, Grammar g)
{
if (symbolString[0] == '<')
{
Symbol s;
strcpy(s.symbolName, symbolString);
return (Symbol*)set_getElement(g.nonTerminalSet, &s);
}
else
{
Symbol s;
strcpy(s.symbolName, symbolString);
return (Symbol*)set_getElement(g.terminalsSet, &s);
}
}
void printParseTable(Parser p)
{
int row, col;
printf("\n\n\nThe Parse Table:\n\n");
for (row = 0; row < p.grammar.nonTerminalSet.hashTable.size; row++)
{
for (col = 0; col < p.grammar.terminalsSet.hashTable.size; col++)
{
if (p.parseTable[row][col])
{
printf("(%d, %d): ", row, col);
printRule(p.parseTable[row][col]);
printf("\n");
}
}
}
}
TreeNode* findFirstNonTerminalLeafNode(TreeNode* t)
{
ParseTreeNodeData* nodeData;
if (t == NULL) return NULL;
nodeData = (ParseTreeNodeData*)t->data;
if (nodeData->symbol->isNonTerminal)
{
int i;
if (t->no_of_children == 0) return t;
for (i = 0; i < t->no_of_children; i++)
{
TreeNode* ans;
ParseTreeNodeData* childData = (ParseTreeNodeData*)t->children[i]->data;
if (!childData->symbol->isNonTerminal) continue;
if (ans = findFirstNonTerminalLeafNode(t->children[i])) return ans;
}
}
return NULL;
}
void _printParseTree(TreeNode* PT, FILE* outputFile)
{
int i;
ParseTreeNodeData *nodeData, *parentData;
if (PT == NULL) return;
for (i = 0; i < PT->no_of_children; i++)
{
_printParseTree(PT->children[i], outputFile);
}
nodeData = (ParseTreeNodeData*)PT->data;
parentData = (ParseTreeNodeData*)PT->parent->data;
//lexeme lineNo token value parent yes nodeSymbol
if (nodeData->symbol->isNonTerminal)
{
//---- ---- ---- ---- parent no symbolName
fprintf(outputFile, "\n %-25s \t| %-7s \t| %-10s \t| %-8s \t| %-30s \t| %-12s \t| %-30s", "----"
, "----"
, "----"
, "----"
, parentData->symbol->symbolName
, "no"
, nodeData->symbol->symbolName);
}
else
{
if (strcmp(nodeData->tokenInfo.token, "NUM") == 0 || strcmp(nodeData->tokenInfo.token, "RNUM") == 0)
{
//lexeme lineNo token value parent yes ---
fprintf(outputFile, "\n %-25s \t| %-7d \t| %-10s \t| %-8s \t| %-30s \t| %-12s \t| %-30s", nodeData->tokenInfo.lexeme
, nodeData->tokenInfo.lineNo
, nodeData->tokenInfo.token
, nodeData->tokenInfo.lexeme
, parentData->symbol->symbolName
, "yes"
, "----");
}
else
{
//lexeme lineNo token value parent yes ---
fprintf(outputFile, "\n %-25s \t| %-7d \t| %-10s \t| %-8s \t| %-30s \t| %-12s \t| %-30s", nodeData->tokenInfo.lexeme
, nodeData->tokenInfo.lineNo
, nodeData->tokenInfo.token
, "----"
, parentData->symbol->symbolName
, "yes"
, "----");
}
}
}
void printParseTree(Tree PT, char *outfile)
{
FILE* outputFile = fopen(outfile, "w");
if (outputFile)
{
printf("\nPrinting Parse Tree...");
fprintf(outputFile, "\n %-25s \t| %-7s \t| %-10s \t| %-8s \t| %-30s \t| %-12s \t| %-30s"
, "Lexeme"
, "Line No"
, "Token"
, "Value"
, "Parent"
, "Is Leaf Node"
, "Node Symbol");
fprintf(outputFile, "\n----------------------------------------------------------------------------------------------");
fprintf(outputFile, "----------------------------------------------------------------------------------------------\n");
_printParseTree(PT.root->children[0], outputFile);
printf("\nParse Tree printed to %s.", outfile);
fclose(outputFile);
}
else
{
printf("\nError: Could not open file %s for writing parse tree. :(", outfile);
}
}
void printParseTreeNatural(TreeLink subtreeRoot)
{
int i;
printf("\n\nMy Name is %s and I have %d children: ", ((ParseTreeNodeData*)subtreeRoot->data)->symbol->symbolName, subtreeRoot->no_of_children);
for (i = 0; i < subtreeRoot->no_of_children; i++)
{
printf(" %s", ((ParseTreeNodeData*)subtreeRoot->children[i]->data)->symbol->symbolName);
}
for (i = 0; i < subtreeRoot->no_of_children; i++)
{
printParseTreeNatural(subtreeRoot->children[i]);
}
}
void initUsefulArray(FILE* fin)
{
int size = 1;
while (fscanf(fin, "%s", usefullArray[size++]) > 0){}
}
UsefulNess getUsefullness(int ruleNo, int index)
{
return (UsefulNess)(usefullArray[ruleNo][index] -'0');
}
int parseInputSourceCode(Parser* parser, Lexer l)
{
Stack parserMainStack;
Symbol* stackTop;
TokenInfo lookAheadToken;
Symbol* lookAheadSymbol;
//stores pointers to those data of parse tree nodes for which tokenInfo is unknown because the lexer has not yet read those terminals from input.
LinkList unInformedTerminalsInTree;
//The node at which children are to be added when next time a rule is followed.
TreeNode* currentTreeNode;
Symbol* rootSymbol;
Symbol* startSymbol;
Rule* startRule;
int usefullNessRHScount;
ParseTreeNodeData* startSymbolNode;
//Add a symbol "ROOT" as root of parse tree
rootSymbol = (Symbol* )malloc(sizeof(Symbol));
rootSymbol->isNonTerminal = 1;
rootSymbol->symbolID = -1;
strcpy(rootSymbol->symbolName, "ROOT");
parser->parseTree = tree_add(parser->parseTree, NULL, parseTree_createNodeNTValue(rootSymbol));
//Add the start symbol to the parse tree
startRule = (Rule*)parser->grammar.rules.head->element;
startSymbol = ((Rule*)parser->grammar.rules.head->element)->lhs;
startSymbolNode = parseTree_createNodeNTValue(startSymbol);
//modification..................................................................................................
startSymbolNode->usefulNess = concrete;
//......................................................................................
parser->parseTree = tree_add(parser->parseTree, parser->parseTree.root, startSymbolNode);
currentTreeNode = findFirstNonTerminalLeafNode(parser->parseTree.root);
parserMainStack = stack_createNew(compareByReference);
parserMainStack = stack_push(parserMainStack, parser->grammar.dollar);
parserMainStack = stack_push(parserMainStack, ((Rule*)parser->grammar.rules.head->element)->lhs);
unInformedTerminalsInTree = linkList_createNew(compareByReference);
lookAheadToken = getNextToken(&l);
printf("\nParsing Input... \n");
while (1)
{
if (strcmp(lookAheadToken.token, "BLANK") == 0 || strcmp(lookAheadToken.token, "COMMENT") == 0)
{
lookAheadToken = getNextToken(&l);
continue;
}
if (strcmp(lookAheadToken.token, "BAD_TOKEN")==0)
{
printf("\nLine %d: Syntax Error: Bad Token: %s", lookAheadToken.lineNo, lookAheadToken.lexeme);
parserMainStack = linkList_clear(parserMainStack);
return 0;
}
lookAheadSymbol = findSymbolByName(lookAheadToken.token, parser->grammar);
//lookAheadSymbol now points to one of the symbols in the set of grammar symbols.
stackTop = (Symbol*)stack_top(parserMainStack);
//printf("\n\nLookAhead is %s and StackTop is %s", lookAheadSymbol->symbolName, stackTop->symbolName);
if (stackTop == parser->grammar.dollar || lookAheadSymbol == parser->grammar.dollar)
{
if (stackTop == lookAheadSymbol)
{
return 1;
}
else
{
if (stackTop == parser->grammar.dollar)
{
printf("\nLine %d: Syntax Error: The token %s for lexeme %s is unexpected. Expected end of file.", lookAheadToken.lineNo, lookAheadToken.token, lookAheadToken.lexeme);
}
else
{
printf("\nLine %d: Syntax Error: Unexpected end of file. ", lookAheadToken.lineNo);
if (stackTop->isNonTerminal == 0)
{
printf(" The expected token is %s", stackTop->symbolName);
}
}
return 0;
}
}
else if (stackTop == parser->grammar.epsilon)
{
//printf("\nPopping Terminal %s", stackTop->symbolName);
ParseTreeNodeData* terminalNodeValue;
parserMainStack = stack_pop(parserMainStack);
terminalNodeValue = (ParseTreeNodeData*)unInformedTerminalsInTree.head->element;
strcpy(terminalNodeValue->tokenInfo.lexeme, "epsilon");
terminalNodeValue->tokenInfo.lineNo = -1;
strcpy(terminalNodeValue->tokenInfo.token, "----");
unInformedTerminalsInTree = linkList_remove(unInformedTerminalsInTree, terminalNodeValue);
}
else if (stackTop->isNonTerminal == 0 && stackTop == lookAheadSymbol)
{
//printf("\nPopping Terminal %s", stackTop->symbolName);
ParseTreeNodeData* terminalNodeValue = (ParseTreeNodeData*)unInformedTerminalsInTree.head->element;
terminalNodeValue->tokenInfo = lookAheadToken;
unInformedTerminalsInTree = linkList_remove(unInformedTerminalsInTree, terminalNodeValue);
parserMainStack = stack_pop(parserMainStack);
lookAheadToken = getNextToken(&l);
}
else if (stackTop->isNonTerminal && parser->parseTable[stackTop->symbolID][lookAheadSymbol->symbolID]!=NULL)
{
Stack stackTemp;
LinkListNode* rhsIterator;
LinkList tempLinkList = linkList_createNew(compareByReference);
Rule* thisRule = parser->parseTable[stackTop->symbolID][lookAheadSymbol->symbolID];
ParseTreeNodeData* currentTreeNodeData = (ParseTreeNodeData*)currentTreeNode->data;
usefullNessRHScount = 0;
currentTreeNodeData->expandsToRule = thisRule;
//printf("\nFollowing Rule: "); printRule(thisRule);
stackTemp = linkList_createNew(compareByReference); //RHS symbols are first poured into this stack and then into mainStack
//so that they are poured in correct order.
parserMainStack = stack_pop(parserMainStack);
for (rhsIterator = thisRule->rhsSymbols.head; rhsIterator != NULL; rhsIterator = rhsIterator->next)
{
Symbol* thisSymbol = (Symbol*)rhsIterator->element;
stackTemp = stack_push(stackTemp, rhsIterator->element);
//Add the RHS symbols to parse tree.
if (thisSymbol->isNonTerminal)
{
ParseTreeNodeData* childNodeData = parseTree_createNodeNTValue(thisSymbol);
childNodeData->expandsFrom = thisRule;
childNodeData->usefulNess = getUsefullness(thisRule->ruleNo, usefullNessRHScount++);
parser->parseTree = tree_add(parser->parseTree, currentTreeNode, childNodeData);
}
else
{
//this is actually insertion of terminal only with garbage token info for time being....would be corrected later.
ParseTreeNodeData* terminalTreeNodeValue = parseTree_createNodeNTValue(thisSymbol);
terminalTreeNodeValue->expandsFrom = thisRule;
terminalTreeNodeValue->usefulNess = getUsefullness(thisRule->ruleNo, usefullNessRHScount++);
parser->parseTree = tree_add(parser->parseTree, currentTreeNode,terminalTreeNodeValue );
tempLinkList = linkList_addToTail(tempLinkList, terminalTreeNodeValue);
}
}
unInformedTerminalsInTree = linkList_merge(tempLinkList, unInformedTerminalsInTree);
currentTreeNode = findFirstNonTerminalLeafNode(parser->parseTree.root); //find the next currentNode
while (stackTemp.size != 0)
{
parserMainStack = stack_push(parserMainStack, stack_top(stackTemp));
stackTemp = stack_pop(stackTemp);
}
}
else
{
printf("\nLine %d: Syntax Error: The token %s for lexeme %s is unexpected.", lookAheadToken.lineNo, lookAheadToken.token, lookAheadToken.lexeme);
if (stackTop->isNonTerminal == 0)
{
printf(" The expected token here is %s", stackTop->symbolName);
}
parserMainStack = linkList_clear(parserMainStack);
return 0;
}
}
return 0;
}
ParseTreeNodeData* parseTree_createNodeValue(Symbol* symbol, TokenInfo info)
{
ParseTreeNodeData* ptNodeInfo = (ParseTreeNodeData*)malloc(sizeof(ParseTreeNodeData));
ptNodeInfo->symbol = symbol;
ptNodeInfo->tokenInfo = info;
ptNodeInfo->expandsFrom = NULL;
ptNodeInfo->expandsToRule = NULL;
return ptNodeInfo;
}
ParseTreeNodeData* parseTree_createNodeNTValue(Symbol* symbol)
{
ParseTreeNodeData* ptNodeInfo = (ParseTreeNodeData*)malloc(sizeof(ParseTreeNodeData));
ptNodeInfo->symbol = symbol;
ptNodeInfo->expandsFrom = NULL;
ptNodeInfo->expandsToRule = NULL;
ptNodeInfo->tokenInfo.lexeme[0] = '\0';
ptNodeInfo->tokenInfo.lineNo = -1;
ptNodeInfo->tokenInfo.token[0] = '\0';
return ptNodeInfo;
}