forked from justinmeza/lci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.h
822 lines (755 loc) · 22.2 KB
/
parser.h
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/**
* Structures and functions for parsing tokens to a parse tree. The parser
* reads through a list of tokens (generated by the tokenizer) and adds semantic
* meaning to them by forming them into a parse tree which can then be passed on
* to later stages (such as the interpreter).
*
* \file parser.h
*
* \author Justin J. Meza
*
* \date 2010-2012
*/
/**
* \page impvar The Implicit Variable
*
* The implicit variable in LOLCODE is denoted by the keyword \c IT and stores a
* copy of the result of the most recently evaluated expression statement (an
* expression all by itself on a line). (See
* http://lolcode.com/specs/1.2#conditionals for an example.)
*/
/**
* \page lolebnf The LOLCODE EBNF
*
* Presented below is the EBNF (see
* http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form) for the
* LOLCODE language that \c lci parses. Note that by this stage, the scanner
* has:
* - already removed any whitespace between tokens,
* - added in and truncated newline tokens at logical line breaks, and
* - added an end-of-file (\c $) token.
*
* \section progebnf Program Structure
*
* These production rules dictate the overall form of the program.
*
* \par
* MainNode ::= \c TT_HAI \a version \c TT_NEWLINE BlockNode \c $
*
* \par
* BlockNode ::= StmtNode *
*
* \section typesebnf Types
*
* These production rules specify some general types of parse structures.
*
* \par
* ConstantNode ::= Boolean | Integer | Float | String
*
* \par
* IdentifierNode ::= Identifier | \c TT_SRS ExprNode
*
* \par
* TypeNode ::= \c TT_NOOB | \c TT_TROOF | \c TT_NUMBR | \c TT_NUMBAR | \c
* TT_YARN
*
* \section stmtebnf Statements
*
* These production rules specify the types of statements formed.
*
* \par
* StmtNode ::= CastStmtNode | PrintStmtNode | InputStmtNode |
* AssignmentStmtNode | DeclarationStmtNode | IfThenElseStmtNode |
* SwitchStmtNode | BreakStmt | ReturnStmtNode | LoopStmtNode |
* DeallocationStmtNode | FuncDefStmtNode | ExprStmt | AltArrayDefStmtNode
*
* \par
* CastStmtNode ::= IdentifierNode \c TT_ISNOWA TypeNode \c TT_NEWLINE
*
* \par
* PrintStmtNode ::= \c TT_VISIBLE ExprNodeList \c TT_BANG ? \c TT_NEWLINE
* | \c TT_INVISIBLE ExprNodeList \c TT_BANG ? \c TT_NEWLINE
*
* \par
* InputStmtNode ::= \c TT_GIMMEH IdentifierNode \c TT_NEWLINE
*
* \par
* AssignmentStmtNode ::= IdentifierNode \c TT_R ExprNode \c TT_NEWLINE
*
* \par
* DeclarationStmtNode ::= IdentifierNode \c TT_HASA IdentifierNode
* Initialization ? \c TT_NEWLINE | IdentifierNode \c TT_HASAN
* IdentifierNode Initialization ? \c TT_NEWLINE
*
* \par
* Initialization ::= \c TT_ITZ ExprNode | \c TT_ITZA TypeNode | \c TT_ITZLIEKA IdentifierNode
*
* \par
* IfThenElseStmtNode ::= \c TT_ORLY \c TT_NEWLINE \c TT_YARLY \c TT_NEWLINE
* BlockNode ElseIf * Else ? \c TT_OIC \c TT_NEWLINE
*
* \par
* ElseIf ::= \c TT_MEBBE ExprNode \c TT_NEWLINE BlockNode
*
* \par
* Else ::= \c TT_NOWAI \c TT_NEWLINE BlockNode
*
* \par
* SwitchStmtNode ::= \c TT_WTF \c TT_NEWLINE Case + DefaultCase ? \c TT_OIC \c
* TT_NEWLINE
*
* \par
* Case ::= \c TT_OMG ExprNode \c TT_NEWLINE BlockNode
*
* \par
* DefaultCase ::= \c TT_OMGWTF \c TT_NEWLINE BlockNode
*
* \par
* BreakStmt ::= \c TT_GTFO \c TT_NEWLINE
*
* \par
* ReturnStmtNode ::= \c TT_FOUNDYR ExprNode \c TT_NEWLINE
*
* \par
* LoopStmtNode ::= \c TT_IMINYR IdentifierNode LoopUpdate ? LoopGuard ? \c
* TT_NEWLINE BlockNode \c TT_IMOUTTAYR IdentifierNode \c TT_NEWLINE
*
* \par
* LoopUpdate ::= LoopUpdateOp \c TT_YR IdentifierNode
*
* \par
* LoopUpdateOp ::= \c TT_UPPIN | \c TT_NERFIN | UnaryFunction
*
* \par
* UnaryFunction ::= The name of a previously defined unary function.
*
* \par
* LoopGuard ::= \c TT_TIL ExprNode | \c TT_WILE ExprNode
*
* \par
* DeallocationStmtNode ::= IdentifierNode \c TT_RNOOB
*
* \par
* FuncDefStmtNode ::= \c TT_HOWIZ IdentifierNode IdentifierNode FunctionArgs ?
* \c TT_NEWLINE BlockNode \c TT_IFUSAYSO \c TT_NEWLINE
*
* \par
* FunctionArgs ::= \c TT_YR IdentifierNode FunctionArg *
*
* \par
* FunctionArg ::= \c TT_ANYR IdentifierNode
*
* \par
* ExprStmt ::= ExprNode \c TT_NEWLINE
*
* \par
* AltArrayDefStmtNode ::= \c TT_OHAIIM IdentifierNode AltArrayInheritance ? \c
* TT_NEWLINE BlockNode \c TT_KTHX \c TT_NEWLINE
*
* \par
* AltArrayInheritance ::= \c TT_IMLIEK IdentifierNode
*
* \section exprebnf Expressions
*
* These production rules specify the types of expressions formed.
*
* \par
* ExprNode ::= CastExprNode | ConstantNode | IdentifierNode | FuncCallExprNode
* | OpExprNode | ImplicitVariable
*
* \par
* CastExprNode ::= \c TT_MAEK ExprNode \c TT_A TypeNode
*
* \par
* FuncCallExprNode ::= IdentifierNode \c TT_IZ IdentifierNode FunctionArgs ?
* TT_MKAY
*
* \par
* OpExprNode ::= UnaryOp | BinaryOp | NaryOp
*
* \par
* UnaryOp ::= UnaryOpType ExprNode
*
* \par
* UnaryOpType ::= \c TT_NOT
*
* \par
* BinaryOp ::= BinaryOpType ExprNode \c TT_AN ? ExprNode
*
* \par
* BinaryOpType ::= \c TT_SUMOF | \c TT_DIFFOF | \c TT_PRODUKTOF | \c
* TT_QUOSHUNTOF | \c TT_MODOF | \c BIGGROF | \c SMALLROF | \c TT_BOTHOF | \c
* TT_EITHEROF | \c TT_WONOF
*
* \par
* NaryOp ::= NaryOpType NaryOpArgs \c TT_MKAY
*
* \par
* NaryOpType ::= \c TT_ALLOF | \c TT_ANYOF | \c TT_SMOOSH
*
* \par
* NaryOpArgs ::= ExprNode NaryOpArg +
*
* \par
* NaryOpArg ::= \c TT_AN ? ExprNode
*
* \par
* ImplicitVariable ::= \c TT_IT
*/
#ifndef __PARSER_H__
#define __PARSER_H__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include "tokenizer.h"
#undef DEBUG
/**
* Represents a statement type.
*/
typedef enum {
ST_CAST, /**< Cast statement. */
ST_PRINT, /**< Print statement. */
ST_INPUT, /**< Input statement. */
ST_ASSIGNMENT, /**< Assignment statement. */
ST_DECLARATION, /**< Declaration statement. */
ST_IFTHENELSE, /**< If/then/else statement. */
ST_SWITCH, /**< Switch statement. */
ST_BREAK, /**< Break statement. */
ST_RETURN, /**< Return statement. */
ST_LOOP, /**< Loop statement. */
ST_DEALLOCATION, /**< Deallocation statement. */
ST_FUNCDEF, /**< Function definition statement. */
ST_EXPR, /**< Expression statement. */
ST_ALTARRAYDEF, /**< Function definition statement. */
} StmtType;
/**
* Stores statement data.
*/
typedef struct {
StmtType type; /**< The type of statement in \a node. */
void *stmt; /**< The statement. */
} StmtNode;
/**
* Stores a list of statements.
*/
typedef struct {
unsigned int num; /**< The number of statements. */
StmtNode **stmts; /**< The array of statements. */
} StmtNodeList;
/**
* Represents an expression type.
*/
typedef enum {
ET_CAST, /**< Cast expression. */
ET_CONSTANT, /**< Constant expression. */
ET_IDENTIFIER, /**< Identifier expression. */
ET_FUNCCALL, /**< Function call expression. */
ET_OP, /**< Operation expression. */
ET_IMPVAR /**< \ref impvar "Implicit variable". */
} ExprType;
/**
* Stores an expression.
*/
typedef struct {
ExprType type; /**< The type of expression in \a expr. */
void *expr; /**< The expression. */
} ExprNode;
/**
* Stores a list of expressions.
*/
typedef struct {
unsigned int num; /**< The number of expressions. */
ExprNode **exprs; /**< The array of statements. */
} ExprNodeList;
/**
* Represents an identifier type.
*/
typedef enum {
IT_DIRECT, /**< Direct identifier. */
IT_INDIRECT /**< Indirect identifier. */
} IdentifierType;
/**
* Stores an identifier.
*/
typedef struct identifiernode {
IdentifierType type; /**< The type of identifier in \a id. */
void *id; /**< The identifier. */
char *fname; /**< The original file name. */
unsigned int line; /**< The original line number. */
struct identifiernode *slot; /**< The slot to access. */
} IdentifierNode;
/**
* Stores a list of identifiers.
*/
typedef struct {
unsigned int num; /**< The number of identifiers. */
IdentifierNode **ids; /**< The array of identifiers. */
} IdentifierNodeList;
/**
* Stores a code block.
*/
typedef struct {
StmtNodeList *stmts; /**< The list of statements in the block. */
} BlockNode;
/**
* Stores a list of code blocks.
*/
typedef struct {
unsigned int num; /**< The number of code blocks. */
BlockNode **blocks; /**< The array of code blocks. */
} BlockNodeList;
/**
* Represents a constant type.
*/
typedef enum {
CT_INTEGER, /**< Integer constant. */
CT_FLOAT, /**< Decimal constant. */
CT_BOOLEAN, /**< Boolean constant. */
CT_STRING, /**< String constant. */
CT_NIL, /**< Nil constant. */
CT_ARRAY /**< Array constant. */
} ConstantType;
/**
* Stores constant data.
*/
typedef union {
long long i; /**< Integer data. */
float f; /**< Decimal data. */
char *s; /**< String data. */
} ConstantData;
/**
* Stores a constant.
*/
typedef struct {
ConstantType type; /**< The type of constant in \a data. */
ConstantData data; /**< The constant. */
} ConstantNode;
/**
* Stores a function definition statement.
*/
typedef struct {
IdentifierNode *scope; /**< The scope of the function. */
IdentifierNode *name; /**< The name of the function. */
IdentifierNodeList *args; /**< The names of the function arguments. */
BlockNode *body; /**< The body of the function. */
} FuncDefStmtNode;
/**
* Stores an alternate array definition statement.
*/
typedef struct {
IdentifierNode *name; /**< The name of the array. */
BlockNode *body; /**< The body of the array definition. */
IdentifierNode *parent; /**< An optional inherited array. */
} AltArrayDefStmtNode;
/**
* Stores the main code block of a program.
*
* \note This could be represented with just a BlockNode, but it seems
* significant enough to merit its own structure.
*/
typedef struct {
BlockNode *block; /**< The first block of code to execute. */
} MainNode;
/**
* Stores a variable type.
*/
typedef struct {
ConstantType type; /**< The type variable. */
} TypeNode;
/**
* Stores a cast statement. This statement changes the type of a variable.
*/
typedef struct {
IdentifierNode *target; /**< The name of the variable to cast. */
TypeNode *newtype; /**< The type to cast \a target to. */
} CastStmtNode;
/**
* Stores a print statement. This statement prints a list of expressions with
* an optional newline.
*/
typedef struct {
ExprNodeList *args; /**< The expressions to print. */
FILE *file; /**< Where to print (\c stdout or \c stderr). */
int nonl; /**< Whether to print an ending newline. */
} PrintStmtNode;
/**
* Stores an input statement. This statement accepts input from the user and
* stores it in a variable.
*/
typedef struct {
IdentifierNode *target; /**< The variable to store the input in. */
} InputStmtNode;
/**
* Stores an assignment statement. This statement stores an evaluated
* expression in a variable.
*/
typedef struct {
IdentifierNode *target; /**< The variable to store \a expr in. */
ExprNode *expr; /**< The expression to store. */
} AssignmentStmtNode;
/**
* Stores a declaration statement. This statement creates a new variable in a
* given scope and optionally initializes it to an expression.
*
* \note Either provide \a expr OR \a type. If both are provided, the result is
* undefined.
*/
typedef struct {
IdentifierNode *scope; /**< The scope to create the variable in. */
IdentifierNode *target; /**< The name of the variable to create. */
ExprNode *expr; /**< An optional initialization expression. */
TypeNode *type; /**< An optional initialization type. */
IdentifierNode *parent; /**< An optional inherited array. */
} DeclarationStmtNode;
/**
* Stores an if/then/else statement. This statement checks the value of the
* \ref impvar "implicit variable" and executes the \c yes block if it can be
* cast to true. Else, the \c guards are evaluated and the corresponding code
* in one of the \c blocks is executed. Finally, if none of these things occur,
* the \c no block is executed.
*/
typedef struct {
BlockNode *yes; /**< The code to execute if \c IT is true. */
BlockNode *no; /**< The code to execute if nothing else does. */
ExprNodeList *guards; /**< The guards for the \c blocks. */
BlockNodeList *blocks; /**< The code to execute if a guard is true. */
} IfThenElseStmtNode;
/**
* Stores a switch statement. This statement compares the value of the \ref
* impvar "implicit variable" to each of the \a guards and executes the
* respective block of code in \a blocks if they match. If no matches are
* found, the optional default block of code, \a def, is executed.
*/
typedef struct {
ExprNodeList *guards; /**< The expressions to evaluate. */
BlockNodeList *blocks; /**< The blocks of code to execute. */
BlockNode *def; /**< An optional default block of code. */
} SwitchStmtNode;
/**
* Stores a return statement. This statement signals that control should be
* returned to the caller with a status value.
*/
typedef struct {
ExprNode *value; /**< The value to return. */
} ReturnStmtNode;
/**
* Stores a loop statement. This statement repeatedly executes its \a body
* while \a guard evaluates to true, executing \a update at the end of each
* cycle.
*/
typedef struct {
IdentifierNode *name; /**< The name of the loop. */
IdentifierNode *var; /**< The variable to be updated. */
ExprNode *guard; /**< The expression to determine continuation. */
ExprNode *update; /**< The expression to update \a var with. */
BlockNode *body; /**< The code to execute at each iteration. */
} LoopStmtNode;
/**
* Stores a deallocation statement. This statement releases the resources used
* by a variable.
*/
typedef struct {
IdentifierNode *target; /**< The variable to deallocate. */
} DeallocationStmtNode;
/**
* Stores a cast expression. This expression evaluates an expression and casts
* its value to a particular type.
*/
typedef struct {
ExprNode *target; /**< The expression to cast. */
TypeNode *newtype; /**< The type to cast \a target to. */
} CastExprNode;
/**
* Stores a function call expression. This expression calls a named function
* and evaluates to the return value of that function.
*/
typedef struct {
IdentifierNode *scope; /**< The scope to call the function in. */
IdentifierNode *name; /**< The name of the function to call. */
ExprNodeList *args; /**< The arguments to supply the function. */
} FuncCallExprNode;
/**
* Represents the type of operation an OpExprNode performs.
*/
typedef enum {
OP_ADD, /**< Addition. */
OP_SUB, /**< Subtraction. */
OP_MULT, /**< Multiplication. */
OP_DIV, /**< Division. */
OP_MOD, /**< Modulo. */
OP_MAX, /**< Maximum. */
OP_MIN, /**< Minimum. */
OP_AND, /**< Logical AND. */
OP_OR, /**< Logical OR. */
OP_XOR, /**< Logical XOR. */
OP_NOT, /**< Logical NOT. */
OP_EQ, /**< Equality. */
OP_NEQ, /**< Inequality. */
OP_CAT /**< String concatenation. */
} OpType;
/**
* Stores an operation expression. This expression applies an operator to its
* arguments.
*/
typedef struct {
OpType type; /**< The type of operation to perform. */
ExprNodeList *args; /**< The arguments to perform the operation on. */
} OpExprNode;
/**
* \name MainNode modifiers
*
* Functions for creating and deleting MainNodes.
*/
/**@{*/
MainNode *createMainNode(BlockNode *);
void deleteMainNode(MainNode *);
/**@}*/
/**
* \name BlockNode modifiers
*
* Functions for creating and deleting single or multiple BlockNodes.
*/
/**@{*/
BlockNode *createBlockNode(StmtNodeList *);
void deleteBlockNode(BlockNode *);
BlockNodeList *createBlockNodeList(void);
int addBlockNode(BlockNodeList *, BlockNode *);
void deleteBlockNodeList(BlockNodeList *);
/**@}*/
/**
* \name IdentifierNode modifiers
*
* Functions for creating and deleting single or multiple IdentifierNodes.
*/
/**@{*/
IdentifierNode *createIdentifierNode(IdentifierType, void *, IdentifierNode *, const char *, unsigned int);
void deleteIdentifierNode(IdentifierNode *);
IdentifierNodeList *createIdentifierNodeList(void);
int addIdentifierNode(IdentifierNodeList *, IdentifierNode *);
void deleteIdentifierNodeList(IdentifierNodeList *);
/**@}*/
/**
* \name TypeNode modifiers
*
* Functions for creating and deleting TypeNodes.
*/
/**@{*/
TypeNode *createTypeNode(ConstantType);
void deleteTypeNode(TypeNode *);
/**@}*/
/**
* \name StmtNode modifiers
*
* Functions for creating and deleting single or multiple of StmtNodes.
*/
/**@{*/
StmtNode *createStmtNode(StmtType, void *);
void deleteStmtNode(StmtNode *);
StmtNodeList *createStmtNodeList(void);
int addStmtNode(StmtNodeList *, StmtNode *);
void deleteStmtNodeList(StmtNodeList *);
/**@}*/
/**
* \name CastStmtNode modifiers
*
* Functions for creating and deleting CastStmtNodes.
*/
/**@{*/
CastStmtNode *createCastStmtNode(IdentifierNode *, TypeNode *);
void deleteCastStmtNode(CastStmtNode *);
/**@}*/
/**
* \name PrintStmtNode modifiers
*
* Functions for creating and deleting PrintStmtNodes.
*/
/**@{*/
PrintStmtNode *createPrintStmtNode(ExprNodeList *, FILE *, int);
void deletePrintStmtNode(PrintStmtNode *);
/**@}*/
/**
* \name InputStmtNode modifiers
*
* Functions for creating and deleting InputStmtNodes.
*/
/**@{*/
InputStmtNode *createInputStmtNode(IdentifierNode *);
void deleteInputStmtNode(InputStmtNode *);
/**@}*/
/**
* \name AssignmentStmtNode modifiers
*
* Functions for creating and deleting AssignmentStmtNodes.
*/
/**@{*/
AssignmentStmtNode *createAssignmentStmtNode(IdentifierNode *, ExprNode *);
void deleteAssignmentStmtNode(AssignmentStmtNode *);
/**@}*/
/**
* \name DeclarationStmtNode modifiers
*
* Functions for creating and deleting DeclarationStmtNodes.
*/
/**@{*/
DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *, TypeNode *, IdentifierNode *);
void deleteDeclarationStmtNode(DeclarationStmtNode *);
/**@}*/
/**
* \name IfThenElseStmtNode modifiers
*
* Functions for creating and deleting IfThenElseStmtNodes.
*/
/**@{*/
IfThenElseStmtNode *createIfThenElseStmtNode(BlockNode *, BlockNode *, ExprNodeList *, BlockNodeList *);
void deleteIfThenElseStmtNode(IfThenElseStmtNode *);
/**@}*/
/**
* \name SwitchStmtNode modifiers
*
* Functions for creating and deleting SwitchStmtNodes.
*/
/**@{*/
SwitchStmtNode *createSwitchStmtNode(ExprNodeList *, BlockNodeList *, BlockNode *);
void deleteSwitchStmtNode(SwitchStmtNode *);
/**@}*/
/**
* \name ReturnStmtNode modifiers
*
* Functions for creating and deleting ReturnStmtNodes.
*/
/**@{*/
ReturnStmtNode *createReturnStmtNode(ExprNode *);
void deleteReturnStmtNode(ReturnStmtNode *);
/**@}*/
/**
* \name LoopStmtNode modifiers
*
* Functions for creating and deleting LoopStmtNodes.
*/
/**@{*/
LoopStmtNode *createLoopStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *, ExprNode *, BlockNode *);
void deleteLoopStmtNode(LoopStmtNode *);
/**@}*/
/**
* \name DeallocationStmtNode modifiers
*
* Functions for creating and deleting DeallocationStmtNodes.
*/
/**@{*/
DeallocationStmtNode *createDeallocationStmtNode(IdentifierNode *);
void deleteDeallocationStmtNode(DeallocationStmtNode *);
/**@}*/
/**
* \name FuncDefStmtNode modifiers
*
* Functions for creating and deleting FuncDefStmtNodes.
*/
/**@{*/
FuncDefStmtNode *createFuncDefStmtNode(IdentifierNode *, IdentifierNode *, IdentifierNodeList *, BlockNode *);
void deleteFuncDefStmtNode(FuncDefStmtNode *);
/**@}*/
/**
* \name AltArrayDefStmtNode modifiers
*
* Functions for creating and deleting AltArrayDefStmtNodes.
*/
/**@{*/
AltArrayDefStmtNode *createAltArrayDefStmtNode(IdentifierNode *, BlockNode *, IdentifierNode *);
void deleteAltArrayDefStmtNode(AltArrayDefStmtNode *);
/**@}*/
/**
* \name ExprNode modifiers
*
* Functions for creating and deleting single or multiple ExprNodes.
*/
/**@{*/
ExprNode *createExprNode(ExprType, void *);
void deleteExprNode(ExprNode *);
ExprNodeList *createExprNodeList(void);
int addExprNode(ExprNodeList *, ExprNode *);
void deleteExprNodeList(ExprNodeList *);
/**@}*/
/**
* \name CastExprNode modifiers
*
* Functions for creating and deleting CastExprNodes.
*/
/**@{*/
CastExprNode *createCastExprNode(ExprNode *, TypeNode *);
void deleteCastExprNode(CastExprNode *);
/**@}*/
/**
* \name FuncCallExprNode modifiers
*
* Functions for creating and deleting FuncCallExprNodes.
*/
/**@{*/
FuncCallExprNode *createFuncCallExprNode(IdentifierNode *, IdentifierNode *, ExprNodeList *);
void deleteFuncCallExprNode(FuncCallExprNode *);
/**@}*/
/**
* \name OpExprNode modifiers
*
* Functions for creating and deleting OpExprNodes.
*/
/**@{*/
OpExprNode *createOpExprNode(OpType, ExprNodeList *);
void deleteOpExprNode(OpExprNode *);
/**@}*/
/**
* \name Utilities
*
* Functions for performing helper tasks.
*/
/**@{*/
int acceptToken(Token ***, TokenType);
int peekToken(Token ***, TokenType);
int nextToken(Token ***, TokenType);
/**@}*/
/**
* \name Parsing functions
*
* Functions for parsing a stream of tokens.
*/
/**@{*/
ConstantNode *parseConstantNode(Token ***);
TypeNode *parseTypeNode(Token ***);
IdentifierNode *parseIdentifierNode(Token ***);
ExprNode *parseExprNode(Token ***);
StmtNode *parseStmtNode(Token ***);
BlockNode *parseBlockNode(Token ***);
MainNode *parseMainNode(Token **);
ExprNode *parseCastExprNode(Token ***);
ExprNode *parseConstantExprNode(Token ***);
ExprNode *parseIdentifierExprNode(Token ***);
ExprNode *parseFuncCallExprNode(Token ***);
ExprNode *parseOpExprNode(Token ***);
StmtNode *parseCastStmtNode(Token ***);
StmtNode *parsePrintStmtNode(Token ***);
StmtNode *parseInputStmtNode(Token ***);
StmtNode *parseAssignmentStmtNode(Token ***);
StmtNode *parseDeclarationStmtNode(Token ***);
StmtNode *parseIfThenElseStmtNode(Token ***);
StmtNode *parseSwitchStmtNode(Token ***);
StmtNode *parseBreakStmtNode(Token ***);
StmtNode *parseReturnStmtNode(Token ***);
StmtNode *parseLoopStmtNode(Token ***);
StmtNode *parseDeallocationStmtNode(Token ***);
StmtNode *parseFuncDefStmtNode(Token ***);
StmtNode *parseAltArrayDefStmtNode(Token ***);
/**@}*/
/**
* \name ConstantNode modifiers
*
* Functions for creating and deleting ConstantNode.
*/
/**@{*/
ConstantNode *createBooleanConstantNode(int);
ConstantNode *createIntegerConstantNode(long long);
ConstantNode *createFloatConstantNode(float);
ConstantNode *createStringConstantNode(char *);
void deleteConstantNode(ConstantNode *);
/**@}*/
#endif /* __PARSER_H__ */