Purple  0.1
Standard Language Specification
Functions
statement.c File Reference

Logic for parsing statements into an AST. More...

#include "data.h"
#include "parse.h"
#include "translate/llvm.h"
#include "translate/translate.h"
Include dependency graph for statement.c:

Functions

void match_token (TokenType type)
 Ensure current token is of a given type, and scan the next token if so. More...
 
TokenType match_tokens (TokenType types[], int n_types)
 
int match_type (Number *out)
 Matches a valid type in the input stream. More...
 
TokenType check_for_type (void)
 Ensure current token is a type token, and scan the next token if so. More...
 
static ASTNodeprint_statement (void)
 Parse a print statement into an AST. More...
 
static ASTNodeassignment_statement (void)
 Parse an assignment statement into an AST. More...
 
static ASTNodeif_statement (void)
 Parse an if statement into an AST. More...
 
static ASTNodewhile_statement (void)
 Parse a while statement into an AST. More...
 
static ASTNodefor_statement (void)
 Parse a for statement into an AST. More...
 
static ASTNodereturn_statement (void)
 
ASTNodeparse_statements (void)
 Parse a set of statements into ASTs and generate them into an AST. More...
 

Detailed Description

Logic for parsing statements into an AST.

Author
Charles Averill
Date
14-Sep-2022

Function Documentation

◆ assignment_statement()

static ASTNode * assignment_statement ( void  )
static

Parse an assignment statement into an AST.

Returns
ASTNode* AST for assignment

◆ check_for_type()

TokenType check_for_type ( void  )

Ensure current token is a type token, and scan the next token if so.

Returns
NumberType Type of variable

◆ for_statement()

static ASTNode * for_statement ( void  )
static

Parse a for statement into an AST.

Returns
ASTNode* AST for for statement

◆ if_statement()

static ASTNode * if_statement ( void  )
static

Parse an if statement into an AST.

Returns
ASTNode* AST for if statement

◆ match_token()

void match_token ( TokenType  type)

Ensure current token is of a given type, and scan the next token if so.

Parameters
typeTokenType to ensure

◆ match_tokens()

TokenType match_tokens ( TokenType  types[],
int  n_types 
)

◆ match_type()

int match_type ( Number out)

Matches a valid type in the input stream.

Parameters
outPointer to Number struct to fill with parsed data
Returns
int 0 if out is filled properly, 1 if the scanned type is "void"

◆ parse_statements()

ASTNode * parse_statements ( void  )

Parse a set of statements into ASTs and generate them into an AST.

Returns
AST for a group of statements

◆ print_statement()

static ASTNode * print_statement ( void  )
static

Parse a print statement into an AST.

Returns
ASTNode* AST for print statement

◆ return_statement()

static ASTNode * return_statement ( void  )
static

◆ while_statement()

static ASTNode * while_statement ( void  )
static

Parse a while statement into an AST.

Returns
ASTNode* AST for while statement