From 97eba132276c0fb391f38b4ab997c719ffdc3f31 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 18 Nov 2023 14:37:17 +0100 Subject: [PATCH] WIP: Expression parsing --- doc/ulas.man | 16 ++++++++++++++++ include/ulas.h | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/ulas.man b/doc/ulas.man index 9efe742..83a566b 100644 --- a/doc/ulas.man +++ b/doc/ulas.man @@ -51,6 +51,22 @@ name ; will be replaced with 'value' .SH ASSEMBLY SYNTAX + +.SH EXPRESSION SYNTAX + +Expressions are written in Reverse Polish Notation style and evaluated based on their expected data type. +For example when an expression expects an int type the expression will assume all values that are pushed to it +are integers. + +.SH ASSEMBLY DIRECTIVES + +During assembly sometimes it is required to set certain parameters of the assembler such as the base address (represented by the $@ symbol in expressions). + +Valid directives: + + \.org + Sets the base address + .SH EXAMPLES .SH SEE ALSO diff --git a/include/ulas.h b/include/ulas.h index f026f2e..1798b3f 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -218,7 +218,7 @@ struct ulas_sym { * -1 denotes a NULL value */ -enum ulas_exprs { ULAS_EXPUNARY, ULAS_EXPBINARY, ULAS_EXPLITERAL }; +enum ulas_exprs { ULAS_EXPUN, ULAS_EXPBIN, ULAS_EXPLIT, ULAS_EXPGRP }; struct ulas_expun { long expr; @@ -235,10 +235,19 @@ struct ulas_explit { long tok; }; +struct ulas_expgrp { + // points to the first expression + // in this group + long expr; + // how many expressions belong to the group + long len; +}; + union ulas_expval { struct ulas_expun un; struct ulas_expbin bin; struct ulas_explit lit; + struct ulas_expgrp grp; }; struct ulas_expr { -- 2.30.2