Purple  0.1
Standard Language Specification
Functions
expression.c File Reference

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

#include "data.h"
#include "parse.h"
Include dependency graph for expression.c:

Functions

static int get_operator_precedence (Token t)
 Get the integer operator precedence value of a Token. More...
 
static ASTNodeparse_terminal_node ()
 Build a terminal AST Node for a given Token, exit if not a valid primary Token. More...
 
ASTNodeprefix_operator_passthrough (void)
 Look for prefix operators, otherwise pass through to parse_terminal_node. More...
 
ASTNodefunction_call_expression (void)
 Parse a function call expression into an AST. More...
 
static ASTNodeparse_binary_expression_recursive (int previous_token_precedence, NumberType *nt_max)
 Recursively parse binary expressions into an AST. More...
 
ASTNodeparse_binary_expression (void)
 Convenience wrapper for parse_binary_expression_recursive. More...
 

Detailed Description

Logic for parsing expressions into an AST.

Author
Charles Averill
Date
09-Sep-2022

Function Documentation

◆ function_call_expression()

ASTNode * function_call_expression ( void  )

Parse a function call expression into an AST.

Returns
ASTNode* AST Node containing function call data

◆ get_operator_precedence()

static int get_operator_precedence ( Token  t)
static

Get the integer operator precedence value of a Token.

Parameters
tToken to check preference of
Returns
int Precedence of Token's type

◆ parse_binary_expression()

ASTNode * parse_binary_expression ( void  )

Convenience wrapper for parse_binary_expression_recursive.

Returns
ASTNode* An AST or AST Subtree of the binary expressions in D_INPUT_FILE

◆ parse_binary_expression_recursive()

static ASTNode * parse_binary_expression_recursive ( int  previous_token_precedence,
NumberType nt_max 
)
static

Recursively parse binary expressions into an AST.

Parameters
previous_token_precedenceThe integer precedence value of the previous Token
nt_maxMaximum NumberType encountered during AST generation
Returns
ASTNode* An AST or AST Subtree of the binary expressions in D_INPUT_FILE

◆ parse_terminal_node()

static ASTNode * parse_terminal_node ( )
static

Build a terminal AST Node for a given Token, exit if not a valid primary Token.

Returns
An AST Node built from the provided Token, or an error if the Token is non-terminal

◆ prefix_operator_passthrough()

ASTNode * prefix_operator_passthrough ( void  )

Look for prefix operators, otherwise pass through to parse_terminal_node.

Returns
ASTNode* An AST Node containing data for a prefix operator, or a terminal AST Node