1 /** 2 * Structures and functions for parsing tokens to a parse tree. The parser 3 * reads through a list of tokens (generated by the tokenizer) and adds semantic 4 * meaning to them by forming them into a parse tree which can then be passed on 5 * to later stages (such as the interpreter). 6 * 7 * \file parser.h 8 * 9 * \author Justin J. Meza 10 * 11 * \date 2010-2012 12 */ 13 14 /** 15 * \page impvar The Implicit Variable 16 * 17 * The implicit variable in LOLCODE is denoted by the keyword \c IT and stores a 18 * copy of the result of the most recently evaluated expression statement (an 19 * expression all by itself on a line). (See 20 * http://lolcode.com/specs/1.2#conditionals for an example.) 21 */ 22 23 /** 24 * \page lolebnf The LOLCODE EBNF 25 * 26 * Presented below is the EBNF (see 27 * http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form) for the 28 * LOLCODE language that \c lci parses. Note that by this stage, the scanner 29 * has: 30 * - already removed any whitespace between tokens, 31 * - added in and truncated newline tokens at logical line breaks, and 32 * - added an end-of-file (\c $) token. 33 * 34 * \section progebnf Program Structure 35 * 36 * These production rules dictate the overall form of the program. 37 * 38 * \par 39 * MainNode ::= \c TT_HAI \a version \c TT_NEWLINE BlockNode \c $ 40 * 41 * \par 42 * BlockNode ::= StmtNode * 43 * 44 * \section typesebnf Types 45 * 46 * These production rules specify some general types of parse structures. 47 * 48 * \par 49 * ConstantNode ::= Boolean | Integer | Float | String 50 * 51 * \par 52 * IdentifierNode ::= Identifier | \c TT_SRS ExprNode 53 * 54 * \par 55 * TypeNode ::= \c TT_NOOB | \c TT_TROOF | \c TT_NUMBR | \c TT_NUMBAR | \c 56 * TT_YARN 57 * 58 * \section stmtebnf Statements 59 * 60 * These production rules specify the types of statements formed. 61 * 62 * \par 63 * StmtNode ::= CastStmtNode | PrintStmtNode | InputStmtNode | 64 * AssignmentStmtNode | DeclarationStmtNode | IfThenElseStmtNode | 65 * SwitchStmtNode | BreakStmt | ReturnStmtNode | LoopStmtNode | 66 * DeallocationStmtNode | FuncDefStmtNode | ExprStmt | AltArrayDefStmtNode 67 * 68 * \par 69 * CastStmtNode ::= IdentifierNode \c TT_ISNOWA TypeNode \c TT_NEWLINE 70 * 71 * \par 72 * PrintStmtNode ::= \c TT_VISIBLE ExprNodeList \c TT_BANG ? \c TT_NEWLINE 73 * 74 * \par 75 * InputStmtNode ::= \c TT_GIMMEH IdentifierNode \c TT_NEWLINE 76 * 77 * \par 78 * AssignmentStmtNode ::= IdentifierNode \c TT_R ExprNode \c TT_NEWLINE 79 * 80 * \par 81 * DeclarationStmtNode ::= IdentifierNode \c TT_HASA IdentifierNode 82 * Initialization ? \c TT_NEWLINE 83 * 84 * \par 85 * Initialization ::= \c TT_ITZ ExprNode | \c TT_ITZA TypeNode | \c TT_ITZLIEKA IdentifierNode 86 * 87 * \par 88 * IfThenElseStmtNode ::= \c TT_ORLY \c TT_NEWLINE \c TT_YARLY \c TT_NEWLINE 89 * BlockNode ElseIf * Else ? \c TT_OIC \c TT_NEWLINE 90 * 91 * \par 92 * ElseIf ::= \c TT_MEBBE ExprNode \c TT_NEWLINE BlockNode 93 * 94 * \par 95 * Else ::= \c TT_NOWAI \c TT_NEWLINE BlockNode 96 * 97 * \par 98 * SwitchStmtNode ::= \c TT_WTF \c TT_NEWLINE Case + DefaultCase ? \c TT_OIC \c 99 * TT_NEWLINE 100 * 101 * \par 102 * Case ::= \c TT_OMG ExprNode \c TT_NEWLINE BlockNode 103 * 104 * \par 105 * DefaultCase ::= \c TT_OMGWTF \c TT_NEWLINE BlockNode 106 * 107 * \par 108 * BreakStmt ::= \c TT_GTFO \c TT_NEWLINE 109 * 110 * \par 111 * ReturnStmtNode ::= \c TT_FOUNDYR ExprNode \c TT_NEWLINE 112 * 113 * \par 114 * LoopStmtNode ::= \c TT_IMINYR IdentifierNode LoopUpdate ? LoopGuard ? \c 115 * TT_NEWLINE BlockNode \c TT_IMOUTTAYR IdentifierNode \c TT_NEWLINE 116 * 117 * \par 118 * LoopUpdate ::= LoopUpdateOp \c TT_YR IdentifierNode 119 * 120 * \par 121 * LoopUpdateOp ::= \c TT_UPPIN | \c TT_NERFIN | UnaryFunction 122 * 123 * \par 124 * UnaryFunction ::= The name of a previously defined unary function. 125 * 126 * \par 127 * LoopGuard ::= \c TT_TIL ExprNode | \c TT_WILE ExprNode 128 * 129 * \par 130 * DeallocationStmtNode ::= IdentifierNode \c TT_RNOOB 131 * 132 * \par 133 * FuncDefStmtNode ::= \c TT_HOWIZ IdentifierNode IdentifierNode FunctionArgs ? 134 * \c TT_NEWLINE BlockNode \c TT_IFUSAYSO \c TT_NEWLINE 135 * 136 * \par 137 * FunctionArgs ::= \c TT_YR IdentifierNode FunctionArg * 138 * 139 * \par 140 * FunctionArg ::= \c TT_ANYR IdentifierNode 141 * 142 * \par 143 * ExprStmt ::= ExprNode \c TT_NEWLINE 144 * 145 * \par 146 * AltArrayDefStmtNode ::= \c TT_OHAIIM IdentifierNode AltArrayInheritance ? \c 147 * TT_NEWLINE BlockNode \c TT_KTHX \c TT_NEWLINE 148 * 149 * \par 150 * AltArrayInheritance ::= \c TT_IMLIEK IdentifierNode 151 * 152 * \section exprebnf Expressions 153 * 154 * These production rules specify the types of expressions formed. 155 * 156 * \par 157 * ExprNode ::= CastExprNode | ConstantNode | IdentifierNode | FuncCallExprNode 158 * | OpExprNode | ImplicitVariable | SystemCommandExprNode 159 * 160 * \par 161 * CastExprNode ::= \c TT_MAEK ExprNode \c TT_A TypeNode 162 * 163 * \par 164 * FuncCallExprNode ::= IdentifierNode \c TT_IZ IdentifierNode FunctionArgs ? 165 * TT_MKAY 166 * 167 * \par 168 * SystemCommandExprNode ::= \c TT_DUZ \c IdentifierNode 169 * 170 * \par 171 * OpExprNode ::= UnaryOp | BinaryOp | NaryOp 172 * 173 * \par 174 * UnaryOp ::= UnaryOpType ExprNode 175 * 176 * \par 177 * UnaryOpType ::= \c TT_NOT 178 * 179 * \par 180 * BinaryOp ::= BinaryOpType ExprNode \c TT_AN ? ExprNode 181 * 182 * \par 183 * BinaryOpType ::= \c TT_SUMOF | \c TT_DIFFOF | \c TT_PRODUKTOF | \c 184 * TT_QUOSHUNTOF | \c TT_MODOF | \c BIGGROF | \c SMALLROF | \c TT_BOTHOF | \c 185 * TT_EITHEROF | \c TT_WONOF 186 * 187 * \par 188 * NaryOp ::= NaryOpType NaryOpArgs \c TT_MKAY 189 * 190 * \par 191 * NaryOpType ::= \c TT_ALLOF | \c TT_ANYOF | \c TT_SMOOSH 192 * 193 * \par 194 * NaryOpArgs ::= ExprNode NaryOpArg + 195 * 196 * \par 197 * NaryOpArg ::= \c TT_AN ? ExprNode 198 * 199 * \par 200 * ImplicitVariable ::= \c TT_IT 201 */ 202 203 #ifndef __PARSER_H__ 204 #define __PARSER_H__ 205 206 #include <stdlib.h> 207 #include <stdio.h> 208 #include <string.h> 209 #include <math.h> 210 #include <float.h> 211 212 #include "tokenizer.h" 213 214 #undef DEBUG 215 216 /** 217 * Represents a statement type. 218 */ 219 typedef enum { 220 ST_CAST, /**< Cast statement. */ 221 ST_PRINT, /**< Print statement. */ 222 ST_INPUT, /**< Input statement. */ 223 ST_ASSIGNMENT, /**< Assignment statement. */ 224 ST_DECLARATION, /**< Declaration statement. */ 225 ST_IFTHENELSE, /**< If/then/else statement. */ 226 ST_SWITCH, /**< Switch statement. */ 227 ST_BREAK, /**< Break statement. */ 228 ST_RETURN, /**< Return statement. */ 229 ST_LOOP, /**< Loop statement. */ 230 ST_DEALLOCATION, /**< Deallocation statement. */ 231 ST_FUNCDEF, /**< Function definition statement. */ 232 ST_EXPR, /**< Expression statement. */ 233 ST_ALTARRAYDEF, /**< Function definition statement. */ 234 ST_BINDING, /**< Binding to external library. */ 235 ST_IMPORT, /**< Library import statement. */ 236 } StmtType; 237 238 /** 239 * Stores statement data. 240 */ 241 typedef struct { 242 StmtType type; /**< The type of statement in \a node. */ 243 void *stmt; /**< The statement. */ 244 } StmtNode; 245 246 /** 247 * Stores a list of statements. 248 */ 249 typedef struct { 250 unsigned int num; /**< The number of statements. */ 251 StmtNode **stmts; /**< The array of statements. */ 252 } StmtNodeList; 253 254 /** 255 * Represents an expression type. 256 */ 257 typedef enum { 258 ET_CAST, /**< Cast expression. */ 259 ET_CONSTANT, /**< Constant expression. */ 260 ET_IDENTIFIER, /**< Identifier expression. */ 261 ET_FUNCCALL, /**< Function call expression. */ 262 ET_OP, /**< Operation expression. */ 263 ET_IMPVAR, /**< \ref impvar "Implicit variable". */ 264 ET_SYSTEMCOMMAND, /**< System command expression. */ 265 } ExprType; 266 267 /** 268 * Stores an expression. 269 */ 270 typedef struct { 271 ExprType type; /**< The type of expression in \a expr. */ 272 void *expr; /**< The expression. */ 273 } ExprNode; 274 275 /** 276 * Stores a list of expressions. 277 */ 278 typedef struct { 279 unsigned int num; /**< The number of expressions. */ 280 ExprNode **exprs; /**< The array of statements. */ 281 } ExprNodeList; 282 283 /** 284 * Represents an identifier type. 285 */ 286 typedef enum { 287 IT_DIRECT, /**< Direct identifier. */ 288 IT_INDIRECT /**< Indirect identifier. */ 289 } IdentifierType; 290 291 /** 292 * Stores an identifier. 293 */ 294 typedef struct identifiernode { 295 IdentifierType type; /**< The type of identifier in \a id. */ 296 void *id; /**< The identifier. */ 297 char *fname; /**< The original file name. */ 298 unsigned int line; /**< The original line number. */ 299 struct identifiernode *slot; /**< The slot to access. */ 300 } IdentifierNode; 301 302 /** 303 * Stores a list of identifiers. 304 */ 305 typedef struct { 306 unsigned int num; /**< The number of identifiers. */ 307 IdentifierNode **ids; /**< The array of identifiers. */ 308 } IdentifierNodeList; 309 310 /** 311 * Stores a code block. 312 */ 313 typedef struct { 314 StmtNodeList *stmts; /**< The list of statements in the block. */ 315 } BlockNode; 316 317 /** 318 * Stores a list of code blocks. 319 */ 320 typedef struct { 321 unsigned int num; /**< The number of code blocks. */ 322 BlockNode **blocks; /**< The array of code blocks. */ 323 } BlockNodeList; 324 325 /** 326 * Represents a constant type. 327 */ 328 typedef enum { 329 CT_INTEGER, /**< Integer constant. */ 330 CT_FLOAT, /**< Decimal constant. */ 331 CT_BOOLEAN, /**< Boolean constant. */ 332 CT_STRING, /**< String constant. */ 333 CT_NIL, /**< Nil constant. */ 334 CT_ARRAY /**< Array constant. */ 335 } ConstantType; 336 337 /** 338 * Stores constant data. 339 */ 340 typedef union { 341 long long i; /**< Integer data. */ 342 float f; /**< Decimal data. */ 343 char *s; /**< String data. */ 344 } ConstantData; 345 346 /** 347 * Stores a constant. 348 */ 349 typedef struct { 350 ConstantType type; /**< The type of constant in \a data. */ 351 ConstantData data; /**< The constant. */ 352 } ConstantNode; 353 354 /** 355 * Stores a function definition statement. 356 */ 357 typedef struct { 358 IdentifierNode *scope; /**< The scope of the function. */ 359 IdentifierNode *name; /**< The name of the function. */ 360 IdentifierNodeList *args; /**< The names of the function arguments. */ 361 BlockNode *body; /**< The body of the function. */ 362 } FuncDefStmtNode; 363 364 /** 365 * Stores an alternate array definition statement. 366 */ 367 typedef struct { 368 IdentifierNode *name; /**< The name of the array. */ 369 BlockNode *body; /**< The body of the array definition. */ 370 IdentifierNode *parent; /**< An optional inherited array. */ 371 } AltArrayDefStmtNode; 372 373 /** 374 * Stores a library import statement. 375 */ 376 typedef struct { 377 IdentifierNode *name; /**< The name of the library to import. */ 378 } ImportStmtNode; 379 380 /** 381 * Stores a binding to a native function. 382 */ 383 struct returnobject; 384 struct scopeobject; 385 typedef struct { 386 struct returnobject *(*binding)(struct scopeobject *); /**< The function that implements the binding. */ 387 } BindingStmtNode; 388 389 /** 390 * Stores the main code block of a program. 391 * 392 * \note This could be represented with just a BlockNode, but it seems 393 * significant enough to merit its own structure. 394 */ 395 typedef struct { 396 BlockNode *block; /**< The first block of code to execute. */ 397 } MainNode; 398 399 /** 400 * Stores a variable type. 401 */ 402 typedef struct { 403 ConstantType type; /**< The type variable. */ 404 } TypeNode; 405 406 /** 407 * Stores a cast statement. This statement changes the type of a variable. 408 */ 409 typedef struct { 410 IdentifierNode *target; /**< The name of the variable to cast. */ 411 TypeNode *newtype; /**< The type to cast \a target to. */ 412 } CastStmtNode; 413 414 /** 415 * Stores a print statement. This statement prints a list of expressions with 416 * an optional newline. 417 */ 418 typedef struct { 419 ExprNodeList *args; /**< The expressions to print. */ 420 int nonl; /**< Whether to print an ending newline. */ 421 } PrintStmtNode; 422 423 /** 424 * Stores an input statement. This statement accepts input from the user and 425 * stores it in a variable. 426 */ 427 typedef struct { 428 IdentifierNode *target; /**< The variable to store the input in. */ 429 } InputStmtNode; 430 431 /** 432 * Stores an assignment statement. This statement stores an evaluated 433 * expression in a variable. 434 */ 435 typedef struct { 436 IdentifierNode *target; /**< The variable to store \a expr in. */ 437 ExprNode *expr; /**< The expression to store. */ 438 } AssignmentStmtNode; 439 440 /** 441 * Stores a declaration statement. This statement creates a new variable in a 442 * given scope and optionally initializes it to an expression. 443 * 444 * \note Either provide \a expr OR \a type. If both are provided, the result is 445 * undefined. 446 */ 447 typedef struct { 448 IdentifierNode *scope; /**< The scope to create the variable in. */ 449 IdentifierNode *target; /**< The name of the variable to create. */ 450 ExprNode *expr; /**< An optional initialization expression. */ 451 TypeNode *type; /**< An optional initialization type. */ 452 IdentifierNode *parent; /**< An optional inherited array. */ 453 } DeclarationStmtNode; 454 455 /** 456 * Stores an if/then/else statement. This statement checks the value of the 457 * \ref impvar "implicit variable" and executes the \c yes block if it can be 458 * cast to true. Else, the \c guards are evaluated and the corresponding code 459 * in one of the \c blocks is executed. Finally, if none of these things occur, 460 * the \c no block is executed. 461 */ 462 typedef struct { 463 BlockNode *yes; /**< The code to execute if \c IT is true. */ 464 BlockNode *no; /**< The code to execute if nothing else does. */ 465 ExprNodeList *guards; /**< The guards for the \c blocks. */ 466 BlockNodeList *blocks; /**< The code to execute if a guard is true. */ 467 } IfThenElseStmtNode; 468 469 /** 470 * Stores a switch statement. This statement compares the value of the \ref 471 * impvar "implicit variable" to each of the \a guards and executes the 472 * respective block of code in \a blocks if they match. If no matches are 473 * found, the optional default block of code, \a def, is executed. 474 */ 475 typedef struct { 476 ExprNodeList *guards; /**< The expressions to evaluate. */ 477 BlockNodeList *blocks; /**< The blocks of code to execute. */ 478 BlockNode *def; /**< An optional default block of code. */ 479 } SwitchStmtNode; 480 481 /** 482 * Stores a return statement. This statement signals that control should be 483 * returned to the caller with a status value. 484 */ 485 typedef struct { 486 ExprNode *value; /**< The value to return. */ 487 } ReturnStmtNode; 488 489 /** 490 * Stores a loop statement. This statement repeatedly executes its \a body 491 * while \a guard evaluates to true, executing \a update at the end of each 492 * cycle. 493 */ 494 typedef struct { 495 IdentifierNode *name; /**< The name of the loop. */ 496 IdentifierNode *var; /**< The variable to be updated. */ 497 ExprNode *guard; /**< The expression to determine continuation. */ 498 ExprNode *update; /**< The expression to update \a var with. */ 499 BlockNode *body; /**< The code to execute at each iteration. */ 500 } LoopStmtNode; 501 502 /** 503 * Stores a deallocation statement. This statement releases the resources used 504 * by a variable. 505 */ 506 typedef struct { 507 IdentifierNode *target; /**< The variable to deallocate. */ 508 } DeallocationStmtNode; 509 510 /** 511 * Stores a cast expression. This expression evaluates an expression and casts 512 * its value to a particular type. 513 */ 514 typedef struct { 515 ExprNode *target; /**< The expression to cast. */ 516 TypeNode *newtype; /**< The type to cast \a target to. */ 517 } CastExprNode; 518 519 /** 520 * Stores a function call expression. This expression calls a named function 521 * and evaluates to the return value of that function. 522 */ 523 typedef struct { 524 IdentifierNode *scope; /**< The scope to call the function in. */ 525 IdentifierNode *name; /**< The name of the function to call. */ 526 ExprNodeList *args; /**< The arguments to supply the function. */ 527 } FuncCallExprNode; 528 529 /** 530 * Stores a system command expression. This expression evaluates an identifier 531 * which contains a system command, and evaluates to the standard output of the 532 * executed system command. 533 */ 534 typedef struct { 535 ExprNode *cmd; /**< The expression containing the command to execute */ 536 } SystemCommandExprNode; 537 538 /** 539 * Represents the type of operation an OpExprNode performs. 540 */ 541 typedef enum { 542 OP_ADD, /**< Addition. */ 543 OP_SUB, /**< Subtraction. */ 544 OP_MULT, /**< Multiplication. */ 545 OP_DIV, /**< Division. */ 546 OP_MOD, /**< Modulo. */ 547 OP_MAX, /**< Maximum. */ 548 OP_MIN, /**< Minimum. */ 549 550 OP_AND, /**< Logical AND. */ 551 OP_OR, /**< Logical OR. */ 552 OP_XOR, /**< Logical XOR. */ 553 OP_NOT, /**< Logical NOT. */ 554 555 OP_EQ, /**< Equality. */ 556 OP_NEQ, /**< Inequality. */ 557 558 OP_CAT /**< String concatenation. */ 559 } OpType; 560 561 /** 562 * Stores an operation expression. This expression applies an operator to its 563 * arguments. 564 */ 565 typedef struct { 566 OpType type; /**< The type of operation to perform. */ 567 ExprNodeList *args; /**< The arguments to perform the operation on. */ 568 } OpExprNode; 569 570 /** 571 * \name MainNode modifiers 572 * 573 * Functions for creating and deleting MainNodes. 574 */ 575 /**@{*/ 576 MainNode *createMainNode(BlockNode *); 577 void deleteMainNode(MainNode *); 578 /**@}*/ 579 580 /** 581 * \name BlockNode modifiers 582 * 583 * Functions for creating and deleting single or multiple BlockNodes. 584 */ 585 /**@{*/ 586 BlockNode *createBlockNode(StmtNodeList *); 587 void deleteBlockNode(BlockNode *); 588 BlockNodeList *createBlockNodeList(void); 589 int addBlockNode(BlockNodeList *, BlockNode *); 590 void deleteBlockNodeList(BlockNodeList *); 591 /**@}*/ 592 593 /** 594 * \name IdentifierNode modifiers 595 * 596 * Functions for creating and deleting single or multiple IdentifierNodes. 597 */ 598 /**@{*/ 599 IdentifierNode *createIdentifierNode(IdentifierType, void *, IdentifierNode *, const char *, unsigned int); 600 void deleteIdentifierNode(IdentifierNode *); 601 IdentifierNodeList *createIdentifierNodeList(void); 602 int addIdentifierNode(IdentifierNodeList *, IdentifierNode *); 603 void deleteIdentifierNodeList(IdentifierNodeList *); 604 605 /**@}*/ 606 607 /** 608 * \name TypeNode modifiers 609 * 610 * Functions for creating and deleting TypeNodes. 611 */ 612 /**@{*/ 613 TypeNode *createTypeNode(ConstantType); 614 void deleteTypeNode(TypeNode *); 615 /**@}*/ 616 617 /** 618 * \name StmtNode modifiers 619 * 620 * Functions for creating and deleting single or multiple of StmtNodes. 621 */ 622 /**@{*/ 623 StmtNode *createStmtNode(StmtType, void *); 624 void deleteStmtNode(StmtNode *); 625 StmtNodeList *createStmtNodeList(void); 626 int addStmtNode(StmtNodeList *, StmtNode *); 627 void deleteStmtNodeList(StmtNodeList *); 628 /**@}*/ 629 630 /** 631 * \name CastStmtNode modifiers 632 * 633 * Functions for creating and deleting CastStmtNodes. 634 */ 635 /**@{*/ 636 CastStmtNode *createCastStmtNode(IdentifierNode *, TypeNode *); 637 void deleteCastStmtNode(CastStmtNode *); 638 /**@}*/ 639 640 /** 641 * \name PrintStmtNode modifiers 642 * 643 * Functions for creating and deleting PrintStmtNodes. 644 */ 645 /**@{*/ 646 PrintStmtNode *createPrintStmtNode(ExprNodeList *, int); 647 void deletePrintStmtNode(PrintStmtNode *); 648 /**@}*/ 649 650 /** 651 * \name InputStmtNode modifiers 652 * 653 * Functions for creating and deleting InputStmtNodes. 654 */ 655 /**@{*/ 656 InputStmtNode *createInputStmtNode(IdentifierNode *); 657 void deleteInputStmtNode(InputStmtNode *); 658 /**@}*/ 659 660 /** 661 * \name AssignmentStmtNode modifiers 662 * 663 * Functions for creating and deleting AssignmentStmtNodes. 664 */ 665 /**@{*/ 666 AssignmentStmtNode *createAssignmentStmtNode(IdentifierNode *, ExprNode *); 667 void deleteAssignmentStmtNode(AssignmentStmtNode *); 668 /**@}*/ 669 670 /** 671 * \name DeclarationStmtNode modifiers 672 * 673 * Functions for creating and deleting DeclarationStmtNodes. 674 */ 675 /**@{*/ 676 DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *, TypeNode *, IdentifierNode *); 677 void deleteDeclarationStmtNode(DeclarationStmtNode *); 678 /**@}*/ 679 680 /** 681 * \name IfThenElseStmtNode modifiers 682 * 683 * Functions for creating and deleting IfThenElseStmtNodes. 684 */ 685 /**@{*/ 686 IfThenElseStmtNode *createIfThenElseStmtNode(BlockNode *, BlockNode *, ExprNodeList *, BlockNodeList *); 687 void deleteIfThenElseStmtNode(IfThenElseStmtNode *); 688 /**@}*/ 689 690 /** 691 * \name SwitchStmtNode modifiers 692 * 693 * Functions for creating and deleting SwitchStmtNodes. 694 */ 695 /**@{*/ 696 SwitchStmtNode *createSwitchStmtNode(ExprNodeList *, BlockNodeList *, BlockNode *); 697 void deleteSwitchStmtNode(SwitchStmtNode *); 698 /**@}*/ 699 700 /** 701 * \name ReturnStmtNode modifiers 702 * 703 * Functions for creating and deleting ReturnStmtNodes. 704 */ 705 /**@{*/ 706 ReturnStmtNode *createReturnStmtNode(ExprNode *); 707 void deleteReturnStmtNode(ReturnStmtNode *); 708 /**@}*/ 709 710 /** 711 * \name LoopStmtNode modifiers 712 * 713 * Functions for creating and deleting LoopStmtNodes. 714 */ 715 /**@{*/ 716 LoopStmtNode *createLoopStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *, ExprNode *, BlockNode *); 717 void deleteLoopStmtNode(LoopStmtNode *); 718 /**@}*/ 719 720 /** 721 * \name DeallocationStmtNode modifiers 722 * 723 * Functions for creating and deleting DeallocationStmtNodes. 724 */ 725 /**@{*/ 726 DeallocationStmtNode *createDeallocationStmtNode(IdentifierNode *); 727 void deleteDeallocationStmtNode(DeallocationStmtNode *); 728 /**@}*/ 729 730 /** 731 * \name FuncDefStmtNode modifiers 732 * 733 * Functions for creating and deleting FuncDefStmtNodes. 734 */ 735 /**@{*/ 736 FuncDefStmtNode *createFuncDefStmtNode(IdentifierNode *, IdentifierNode *, IdentifierNodeList *, BlockNode *); 737 void deleteFuncDefStmtNode(FuncDefStmtNode *); 738 /**@}*/ 739 740 /** 741 * \name AltArrayDefStmtNode modifiers 742 * 743 * Functions for creating and deleting AltArrayDefStmtNodes. 744 */ 745 /**@{*/ 746 AltArrayDefStmtNode *createAltArrayDefStmtNode(IdentifierNode *, BlockNode *, IdentifierNode *); 747 void deleteAltArrayDefStmtNode(AltArrayDefStmtNode *); 748 /**@}*/ 749 750 /** 751 * \name ImportStmtNode modifiers 752 * 753 * Functions for creating and deleting ImportStmtNodes. 754 */ 755 /**@{*/ 756 ImportStmtNode *createImportStmtNode(IdentifierNode *); 757 void deleteImportStmtNode(ImportStmtNode *); 758 /**@}*/ 759 760 /** 761 * \name BindingStmtNode modifiers 762 * 763 * Functions for creating and deleting BindingStmtNodes. 764 */ 765 /**@{*/ 766 struct returnobject; 767 struct scopeobject; 768 BindingStmtNode *createBindingStmtNode(struct returnobject *(*)(struct scopeobject *)); 769 void deleteBindingStmtNode(BindingStmtNode *); 770 /**@}*/ 771 772 /** 773 * \name ExprNode modifiers 774 * 775 * Functions for creating and deleting single or multiple ExprNodes. 776 */ 777 /**@{*/ 778 ExprNode *createExprNode(ExprType, void *); 779 void deleteExprNode(ExprNode *); 780 ExprNodeList *createExprNodeList(void); 781 int addExprNode(ExprNodeList *, ExprNode *); 782 void deleteExprNodeList(ExprNodeList *); 783 /**@}*/ 784 785 /** 786 * \name CastExprNode modifiers 787 * 788 * Functions for creating and deleting CastExprNodes. 789 */ 790 /**@{*/ 791 CastExprNode *createCastExprNode(ExprNode *, TypeNode *); 792 void deleteCastExprNode(CastExprNode *); 793 /**@}*/ 794 795 /** 796 * \name FuncCallExprNode modifiers 797 * 798 * Functions for creating and deleting FuncCallExprNodes. 799 */ 800 /**@{*/ 801 FuncCallExprNode *createFuncCallExprNode(IdentifierNode *, IdentifierNode *, ExprNodeList *); 802 void deleteFuncCallExprNode(FuncCallExprNode *); 803 /**@}*/ 804 805 /** 806 * \name SystemCommandExprNode modifiers 807 * 808 * Functions for creating and deleting SystemCommandExprNode. 809 */ 810 /**@{*/ 811 SystemCommandExprNode *createSystemCommandExprNode(ExprNode *); 812 void deleteSystemCommandExprNode(SystemCommandExprNode *); 813 /**@}*/ 814 815 /** 816 * \name OpExprNode modifiers 817 * 818 * Functions for creating and deleting OpExprNodes. 819 */ 820 /**@{*/ 821 OpExprNode *createOpExprNode(OpType, ExprNodeList *); 822 void deleteOpExprNode(OpExprNode *); 823 /**@}*/ 824 825 /** 826 * \name Utilities 827 * 828 * Functions for performing helper tasks. 829 */ 830 /**@{*/ 831 int acceptToken(Token ***, TokenType); 832 int peekToken(Token ***, TokenType); 833 int nextToken(Token ***, TokenType); 834 /**@}*/ 835 836 /** 837 * \name Parsing functions 838 * 839 * Functions for parsing a stream of tokens. 840 */ 841 /**@{*/ 842 ConstantNode *parseConstantNode(Token ***); 843 TypeNode *parseTypeNode(Token ***); 844 IdentifierNode *parseIdentifierNode(Token ***); 845 ExprNode *parseExprNode(Token ***); 846 StmtNode *parseStmtNode(Token ***); 847 BlockNode *parseBlockNode(Token ***); 848 MainNode *parseMainNode(Token **); 849 ExprNode *parseCastExprNode(Token ***); 850 ExprNode *parseConstantExprNode(Token ***); 851 ExprNode *parseIdentifierExprNode(Token ***); 852 ExprNode *parseFuncCallExprNode(Token ***); 853 ExprNode *parseSystemCommandExprNode(Token ***); 854 ExprNode *parseOpExprNode(Token ***); 855 StmtNode *parseCastStmtNode(Token ***); 856 StmtNode *parsePrintStmtNode(Token ***); 857 StmtNode *parseInputStmtNode(Token ***); 858 StmtNode *parseAssignmentStmtNode(Token ***); 859 StmtNode *parseDeclarationStmtNode(Token ***); 860 StmtNode *parseIfThenElseStmtNode(Token ***); 861 StmtNode *parseSwitchStmtNode(Token ***); 862 StmtNode *parseBreakStmtNode(Token ***); 863 StmtNode *parseReturnStmtNode(Token ***); 864 StmtNode *parseLoopStmtNode(Token ***); 865 StmtNode *parseDeallocationStmtNode(Token ***); 866 StmtNode *parseFuncDefStmtNode(Token ***); 867 StmtNode *parseAltArrayDefStmtNode(Token ***); 868 StmtNode *parseImportStmtNode(Token ***); 869 /**@}*/ 870 871 /** 872 * \name ConstantNode modifiers 873 * 874 * Functions for creating and deleting ConstantNode. 875 */ 876 /**@{*/ 877 ConstantNode *createBooleanConstantNode(int); 878 ConstantNode *createIntegerConstantNode(long long); 879 ConstantNode *createFloatConstantNode(float); 880 ConstantNode *createStringConstantNode(char *); 881 void deleteConstantNode(ConstantNode *); 882 /**@}*/ 883 884 #endif /* __PARSER_H__ */ 885