first stable parser

This commit is contained in:
Lauchmelder 2021-11-27 22:30:20 +01:00
parent d01cf5790b
commit 79c54f3c0d
5 changed files with 149 additions and 19 deletions

View file

@ -1,3 +1,5 @@
/// <reference path="../vector.ts" />
enum InstructionType
{
Point,
@ -5,7 +7,7 @@ enum InstructionType
Circle
}
class Instruction
abstract class Instruction
{
public fn: InstructionType;
public params :Parameter[];
@ -15,4 +17,35 @@ class Instruction
this.fn = type;
this.params = [];
}
abstract eval();
}
class PointInstruction extends Instruction
{
constructor()
{
super(InstructionType.Point);
}
eval()
{
return new Vector2D(this.params[0].eval(), this.params[1].eval());
}
}
class LineInstruction extends Instruction
{
constructor()
{
super(InstructionType.Line);
}
eval()
{
return [
this.params[0].eval(),
this.params[1].eval()
];
}
}