diff options
Diffstat (limited to 'conf/confbase.Y')
-rw-r--r-- | conf/confbase.Y | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/conf/confbase.Y b/conf/confbase.Y index b20986a..db6d021 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -30,8 +30,17 @@ CF_DECLS %token <s> SYM %token <t> TEXT +%type <i> expr + +%left '+' '-' +%left '*' '/' '%' + +CF_KEYWORDS(DEFINE) + CF_GRAMMAR +/* Basic config file structure */ + config: conf_entries END { return 0; } @@ -44,6 +53,28 @@ conf_entries: CF_ADDTO(conf, /* EMPTY */) +/* Expressions */ + +expr: + NUM + | expr '+' expr { $$ = $1 + $3; } + | expr '-' expr { $$ = $1 - $3; } + | expr '*' expr { $$ = $1 * $3; } + | expr '/' expr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); } + | expr '%' expr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); } + | '(' expr ')' { $$ = $2; } + | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; } + ; + +CF_ADDTO(conf, definition) +definition: + DEFINE SYM '=' expr { + if ($2->class != SYM_VOID) cf_error("Symbol already defined"); + $2->class = SYM_NUMBER; + $2->aux = $4; + } + ; + CF_CODE CF_END |