From a4d7fb2da6a8390b818dae8d07391c7d76e365e9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 15 Nov 2023 11:59:15 +0100 Subject: parser: hande const declarations Only symbols are produced, no bytecode is emitted. The constant expressions are evaluated at compile time using the stdlib package go/constant. The parser handles implicit repetition of the last non-empty expression list. The iota symbol is reset to 0 and incremented for each line of a const block. To be done in a next commit: type conversions. --- lang/token.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lang') diff --git a/lang/token.go b/lang/token.go index af2fc26..37ac557 100644 --- a/lang/token.go +++ b/lang/token.go @@ -6,10 +6,12 @@ const ( Illegal = iota Comment Ident - Int + + // Literal values + Char Float Imag - Char + Int String // Binary operators (except indicated) @@ -114,6 +116,7 @@ const ( ) func (t TokenId) IsKeyword() bool { return t >= Break && t <= Var } +func (t TokenId) IsLiteral() bool { return t >= Char && t <= String } func (t TokenId) IsOperator() bool { return t >= Add && t <= Tilde } func (t TokenId) IsBlock() bool { return t >= ParenBlock && t <= BraceBlock } func (t TokenId) IsBoolOp() bool { return t >= Equal && t <= NotEqual || t == Not } -- cgit v1.2.3