From 2f77b3fb5a102224c83db2f1fa093c278db716e5 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Tue, 5 Mar 2024 14:28:28 -0700 Subject: [PATCH] evaluate booleans --- src/interpreter/denotable.ts | 1 - src/interpreter/interpreter.ts | 5 +++++ src/parser/grammar.pegjs | 2 +- src/parser/index.ts | 2 +- src/parser/parser.ts | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/interpreter/denotable.ts b/src/interpreter/denotable.ts index bb520f8..119cccf 100644 --- a/src/interpreter/denotable.ts +++ b/src/interpreter/denotable.ts @@ -1,5 +1,4 @@ import type { Identifier } from '@/parser'; -import { testingLogger } from '@t/logger'; export type UnionDenotableType = | Array diff --git a/src/interpreter/interpreter.ts b/src/interpreter/interpreter.ts index 278e027..7a49f7d 100644 --- a/src/interpreter/interpreter.ts +++ b/src/interpreter/interpreter.ts @@ -29,6 +29,11 @@ const evaluateValue = ( if ('int' in value) { return { type: 'int', value: value.int }; } + + if ('bool' in value) { + return { type: 'bool', value: value.bool }; + } + if ('name' in value) { return env.get(value.name); } diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs index f586dcc..180b87f 100644 --- a/src/parser/grammar.pegjs +++ b/src/parser/grammar.pegjs @@ -234,7 +234,7 @@ IntStatement = INT _ int:Integer { return int; } RealStatement = REAL _ real:Real { return real; } -BoolStatement = BOOL _ bool:Integer { return bool; } +BoolStatement = BOOL _ bool:Integer { return { bool: bool.int }; } StringStatement = STRING _ string:QuotedString { return string; } diff --git a/src/parser/index.ts b/src/parser/index.ts index 7831c8e..366042c 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -2,5 +2,5 @@ export * from './generate'; export * from './parser'; import * as peggy from './parser'; -export const peggyParse = (source: string): peggy.FunctionDefinition[] => +export const peggyParse = (source: string): peggy.ContinuationExpression[] => peggy.parse(source); diff --git a/src/parser/parser.ts b/src/parser/parser.ts index b196866..934f3ff 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -512,7 +512,7 @@ function peg$parse(input, options) { return real; };// @ts-ignore var peg$f18 = function(bool) {// @ts-ignore - return bool; };// @ts-ignore + return { bool: bool.int }; };// @ts-ignore var peg$f19 = function(string) {// @ts-ignore return string; };// @ts-ignore @@ -5395,7 +5395,7 @@ export type VarStatement = Identifier; export type LabelStatement = Identifier; export type IntStatement = Integer; export type RealStatement = Real; -export type BoolStatement = Integer; +export type BoolStatement = { bool: any }; export type StringStatement = QuotedString; export type AccessStatement = OffsetStatement | SelectStatement; export type OffsetStatement = Integer;