Purple  0.1
Standard Language Specification
Functions | Variables
parse.h File Reference

Function headers for parsing and operator precedence values. More...

#include "tree.h"
#include "types/number.h"
Include dependency graph for parse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ASTNodeparse_binary_expression (void)
 Convenience wrapper for parse_binary_expression_recursive. More...
 
void match_token (TokenType type)
 Ensure current token is of a given type, and scan the next token if so. More...
 
TokenType match_type (void)
 Ensure current token is a type token, and scan the next token if so. More...
 
void variable_declaration (void)
 Parse a variable declaration statement into an AST. More...
 
ASTNodefunction_declaration (void)
 Parse a function declaration statement into an AST. More...
 
ASTNodefunction_call_expression (void)
 
ASTNodeparse_statements (void)
 Parse a set of statements into ASTs and generate them into an AST. More...
 

Variables

static int operatorPrecedence []
 

Detailed Description

Function headers for parsing and operator precedence values.

Author
Charles Averill
Date
09-Sep-2022

Operator Precedence

This table outlines Purple's operator precedence values. A higher precedence value is computed before a lower precedence value.

Precedence Operator Description Associativity
16 ++ --
()
[]
.
->
(type){list}
Postfix increment/decrement
Function call
Array subscript
Structure and Union member access
Structure and union pointer member access
Compound literal
Left-to-Right
15 **
++ --
-
! ~
(type)
*
&
bytesize
Exponent
Prefix increment/decrement
Unary negative
Logical NOT, bitwise NOT
Cast
Dereference
Address-of
Size in bytes
Right-to-Left
14 * / % Multiplication, division, modulus Left-to-Right
13 + - Addition, Subtraction
12 << >> Bitwise shifts
11 < <=
> >=
"Less than", "Less than or equal to" relational operators
"Greater than", "Greater than or equal to" relational operators
10 == != "Is equal", "Is not equal" relational operators
9 & Bitwise AND
8 ^ Bitwise XOR
7 | Bitwise OR
6 and
nand
Logical AND
Logical NOT-AND
5 xor
xnor
Logical XOR
Logical NOT-XOR
4 or
nor
Logical OR
Logical NOT-OR
3 ? ... : Ternary condition Right-to-Left
2 =
+= -=
*= /= %=
<<= >>=
&= |= ^=
Assignment
Sum, Difference Assignments
Product, Quotient, Modulus Assignments
Bitshift Assignments
Bitwise AND, OR, XOR Assignments
1 , Comma Left-to-Right

Function Documentation

◆ function_call_expression()

ASTNode * function_call_expression ( void  )

◆ function_declaration()

ASTNode * function_declaration ( void  )

Parse a function declaration statement into an AST.

Returns
ASTNode*

◆ 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_type()

TokenType match_type ( void  )

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

Returns
NumberType Type of variable

◆ 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_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

◆ variable_declaration()

void variable_declaration ( void  )

Parse a variable declaration statement into an AST.

Variable Documentation

◆ operatorPrecedence

int operatorPrecedence[]
static
Initial value:
= {
[T_PLUS] = 12, [T_MINUS] = 12, [T_STAR] = 13, [T_SLASH] = 13, [T_EXPONENT] = 15,
[T_EQ] = 9, [T_NEQ] = 9,
[T_LT] = 10, [T_GT] = 10, [T_LE] = 10, [T_GE] = 10,
[T_AND] = 6, [T_OR] = 4, [T_XOR] = 5, [T_NAND] = 6, [T_NOR] = 4, [T_XNOR] = 5,
[T_ASSIGN] = 2,
}
@ T_AND
Definition: scan.h:36
@ T_NAND
Definition: scan.h:39
@ T_XOR
Definition: scan.h:38
@ T_NOR
Definition: scan.h:40
@ T_GE
Definition: scan.h:34
@ T_STAR
Definition: scan.h:25
@ T_LT
Definition: scan.h:31
@ T_LE
Definition: scan.h:33
@ T_SLASH
Definition: scan.h:26
@ T_XNOR
Definition: scan.h:41
@ T_EQ
Definition: scan.h:29
@ T_ASSIGN
Definition: scan.h:59
@ T_GT
Definition: scan.h:32
@ T_PLUS
Definition: scan.h:23
@ T_MINUS
Definition: scan.h:24
@ T_OR
Definition: scan.h:37
@ T_NEQ
Definition: scan.h:30
@ T_EXPONENT
Definition: scan.h:27

Operator precedence values. Precedence ranges from 0-15, 15 being the first to be computed