Created
January 31, 2020 02:12
-
-
Save cosinekitty/08272d1ee1e452c410d7754125004ccb to your computer and use it in GitHub Desktop.
Derived class Expression_Function handles function nodes in the parse tree.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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