Difference between revisions of "Specialized parsers"
Jump to navigation
Jump to search
(New page: Using advanced methods one can modify the behavior of MathObjects and the way they interpret student answers by modifying the parser itself. By convention files that modify the parser are...) |
|||
Line 7: | Line 7: | ||
Check the [http://webwork.maa.org/doc/cvs/pg_CURRENT/ POD documentation for more examples.] |
Check the [http://webwork.maa.org/doc/cvs/pg_CURRENT/ POD documentation for more examples.] |
||
Use <code>loadMacros("parserAssignment.pl");</code> to make the parser modifications available for a WeBWorK question. |
Use <code>loadMacros("parserAssignment.pl");</code> to make the parser modifications available for a WeBWorK question. |
||
+ | |||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserAssignment.pl parserAssignment.pl] |
||
+ | ** checks answers of the form <math>y=3x+5</math> with the LHS of the equation required. |
||
+ | ** follow the link above to see the additional statements that must be inserted in the question to use this file. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserAutoStrings.pl parserAutoStrings.pl] |
||
+ | ** <code>parserAutoStrings.pl</code> - Force String() to accept any string as a potential answer. |
||
+ | AutoStrings() |
||
+ | -- all strings are accepted |
||
+ | DefineStrings("string1", "string2") |
||
+ | DefineStrings(qw(string1 string2)) |
||
+ | -- is a quick way to define "legitimate" strings. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserCustomization.pl parserCustomization.pl] |
||
+ | ** Placeholder for site/course-local customization file. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserDifferenceQuotient.pl parserDifferenceQuotient.pl] |
||
+ | ** An answer checker for difference quotients. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFormulaUpToConstant.pl parserFormulaUpToConstant.pl] |
||
+ | ** implements formulas ``plus a constant''. |
||
+ | ** Students must include the ``+C'' as part of their answers |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFormulaWithUnits.pl parserFormulaWithUnits.pl] |
||
+ | ** Implements a formula with units. |
||
+ | ** For example: |
||
+ | FormulaWithUnits("3x+1 ft")->cmp |
||
+ | FormulaWithUnits($a*$x+1,"ft")->cmp |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFunction.pl parserFunction.pl] |
||
+ | ** An easy way of adding new functions to the current context. |
||
+ | ** <code>parserFunction("f(x)" => "sqrt(x+1)-2");</code> |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFunction.pl parserFunction.pl] |
||
+ | ** An answer checker for implicit equations. |
||
+ | Context("ImplicitEquation"); |
||
+ | $f = ImplicitEquation("x^2 = cos(y)"); |
||
+ | $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]); |
||
+ | $f = ImplicitEquation("x=1/y",tolerance=>.0001); |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserImplicitPlane.pl parserImplicitPlane.pl] |
||
+ | ** Implement implicit planes. |
||
+ | $P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); # -x+y+3z = 5 |
||
+ | $P = ImplicitPlane([1,0,2],[-1,1,3]); # -x+y+3z = 5 |
||
+ | $P = ImplicitPlane([1,0,2],4); # x+2z = 4 |
||
+ | $P = ImplicitPlane("x+2y-z=5"); |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserMultiAnswer.pl parserMultiAnswer.pl] |
||
+ | ** Tie several blanks to a single answer checker. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserNumberWithUnits.pl parserNumberWithUnits.pl] |
||
+ | ** Implements a number with units. |
||
+ | ANS(NumberWithUnits("3 ft")->cmp); |
||
+ | ANS(NumberWithUnits("$a*$b ft")->cmp); |
||
+ | ANS(NumberWithUnits($a*$b,"ft")->cmp); |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserParametricLine.pl parserParametricLine.pl] |
||
+ | ** Implements Formulas that represent parametric lines. |
||
+ | * [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserSolutionFor.pl parserSolutionFor.pl] |
||
+ | ** An answer checker that checks if a student's answer satisifies an implicit equation. |
Revision as of 20:02, 5 August 2008
Using advanced methods one can modify the behavior of MathObjects and the way they interpret student answers by modifying the parser itself. By convention files that modify the parser are named starting with "parser" -- e.g. parserYourModsHere.pl
.
Examples of modifications are give below. A description of advanced techniques for modifying the parser are at ModifyingParser (Advanced).
Specialized Parser Macro files
Here is a partial list of the parser modifying files.
Check the POD documentation for more examples.
Use loadMacros("parserAssignment.pl");
to make the parser modifications available for a WeBWorK question.
- parserAssignment.pl
- checks answers of the form [math]y=3x+5[/math] with the LHS of the equation required.
- follow the link above to see the additional statements that must be inserted in the question to use this file.
- parserAutoStrings.pl
parserAutoStrings.pl
- Force String() to accept any string as a potential answer.
AutoStrings() -- all strings are accepted DefineStrings("string1", "string2") DefineStrings(qw(string1 string2)) -- is a quick way to define "legitimate" strings.
- parserCustomization.pl
- Placeholder for site/course-local customization file.
- parserDifferenceQuotient.pl
- An answer checker for difference quotients.
- parserFormulaUpToConstant.pl
- implements formulas ``plus a constant.
- Students must include the ``+C as part of their answers
- parserFormulaWithUnits.pl
- Implements a formula with units.
- For example:
FormulaWithUnits("3x+1 ft")->cmp FormulaWithUnits($a*$x+1,"ft")->cmp
- parserFunction.pl
- An easy way of adding new functions to the current context.
parserFunction("f(x)" => "sqrt(x+1)-2");
- parserFunction.pl
- An answer checker for implicit equations.
Context("ImplicitEquation"); $f = ImplicitEquation("x^2 = cos(y)"); $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]); $f = ImplicitEquation("x=1/y",tolerance=>.0001);
- parserImplicitPlane.pl
- Implement implicit planes.
$P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); # -x+y+3z = 5 $P = ImplicitPlane([1,0,2],[-1,1,3]); # -x+y+3z = 5 $P = ImplicitPlane([1,0,2],4); # x+2z = 4 $P = ImplicitPlane("x+2y-z=5");
- parserMultiAnswer.pl
- Tie several blanks to a single answer checker.
- parserNumberWithUnits.pl
- Implements a number with units.
ANS(NumberWithUnits("3 ft")->cmp); ANS(NumberWithUnits("$a*$b ft")->cmp); ANS(NumberWithUnits($a*$b,"ft")->cmp);
- parserParametricLine.pl
- Implements Formulas that represent parametric lines.
- parserSolutionFor.pl
- An answer checker that checks if a student's answer satisifies an implicit equation.