Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
token skip
Browse files Browse the repository at this point in the history
  • Loading branch information
eoussama committed Mar 17, 2024
1 parent bc9b694 commit 416c503
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/frontend/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ export class Parser extends Consumer<TToken> {
const token = this.at();

switch (token.type) {
case TokenType.Dot: {
const node = {
kind: NodeType.Skip,
end: this.at().location,
start: this.at().location
} as ISkipNode;

this.eat();
return node;
}

case TokenType.Identifier: {
const node = {
symbol: token.value,
Expand Down
10 changes: 9 additions & 1 deletion src/runtime/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export class Evaluator {
let lastEvaluated: IRuntimeVal = RuntimeHelper.createNull();

for (const statement of program.body) {
lastEvaluated = this.evaluate(statement, env);
const currVal = this.evaluate(statement, env);

if (currVal.type !== Type.Skip) {
lastEvaluated = currVal;
}
}

return lastEvaluated;
Expand Down Expand Up @@ -190,6 +194,10 @@ export class Evaluator {
return this.evaluateVariableDeclaration(node as IVariableDeclarationNode, env);
}

case NodeType.Skip: {
return RuntimeHelper.createSkip();
}

default: {
env.errorManager?.raise(new UnrecognizedStatementError(node.start));
return RuntimeHelper.createNull();
Expand Down

0 comments on commit 416c503

Please sign in to comment.