36 lines
497 B
TypeScript
36 lines
497 B
TypeScript
|
|
type Token = number | '+' | '-' | '*' | '/' | '(' | ')';
|
|
|
|
|
|
|
|
type ASTNode = {
|
|
type: string,
|
|
}
|
|
|
|
type OperatorNode = {
|
|
type: 'operator',
|
|
value: '+' | '-' | '*' | '/',
|
|
left: ASTNode,
|
|
right: ASTNode,
|
|
}
|
|
|
|
type NumberNode = {
|
|
type: 'number',
|
|
value: number,
|
|
}
|
|
|
|
type GroupNode = {
|
|
type: 'group',
|
|
value: ASTNode,
|
|
}
|
|
|
|
type NegationNode = {
|
|
type: 'negation',
|
|
value: ASTNode,
|
|
}
|
|
|
|
export function calc(expression: string): number {
|
|
// evaluate `expression` and return result
|
|
return 0;
|
|
}
|