Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created January 31, 2020 02:12
Show Gist options
  • Save cosinekitty/08272d1ee1e452c410d7754125004ccb to your computer and use it in GitHub Desktop.
Save cosinekitty/08272d1ee1e452c410d7754125004ccb to your computer and use it in GitHub Desktop.
Derived class Expression_Function handles function nodes in the parse tree.
class Expression_Function extends Expression {
constructor(token, arglist) {
super(9, token, arglist);
}
PrettyMath() {
switch (this.optoken.text) {
case 'sqrt':
return '\\sqrt{' + this.PrettyMath_SingleArg() + '}';
case 'abs':
return '\\left|' + this.PrettyMath_SingleArg() + '\\right|';
case 'cos':
case 'sin':
return '\\' + this.optoken.text + '\\left(' + this.PrettyMath_SingleArg() + '\\right)';
default:
throw {
name: 'FormatError',
message: 'Unknown function "' + this.optoken.text + '"',
token: this.optoken
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment