Specialized parsers

From WeBWorK
(Difference between revisions)
Jump to: navigation, search
(Specialized Parser Macro files)
m (Fixed incorrect link)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
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. <code>parserYourModsHere.pl</code>.   
+
<code>parserYourModsHere.pl</code> Modifications to the Parser change the way that student responses are interpreted. By convention files that modify the parser are named starting with "parser" -- e.g. <code>parserYourModsHere.pl</code>.   
 +
test
 +
[[SpecializedContexts]] Describes another advanced method for customizing MathObjects by modifying the context.
  
Examples of modifications are give below.  A description of advanced techniques for modifying the parser are at [[ModifyingParser]] (Advanced).
+
Examples of modifications are give below.   
  
An other advanced method for customizing MathObjects is to modify the context in which the appear. See [[SpecializedContexts]]
+
A description of advanced techniques for customizing the parser are at [[Modifying Contexts (advanced)]].
  
 
=== Specialized Parser Macro files ===
 
=== Specialized Parser Macro files ===
Here is a partial list of the parser modifying files.  
+
Here is a partial list of the parser modifying files.
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.
 +
 
 +
Check the [http://webwork.maa.org/pod/pg_TRUNK/  POD documentation for more examples.]
  
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserAssignment.pl parserAssignment.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserAssignment.pl.html parserAssignment.pl]
 
** checks answers of the form <math>y=3x+5</math> with the LHS of the equation required.
 
** 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.
 
** 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]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserAutoStrings.pl.html parserAutoStrings.pl]
 
** <code>parserAutoStrings.pl</code> - Force String() to accept any string as a potential answer.
 
** <code>parserAutoStrings.pl</code> - Force String() to accept any string as a potential answer.
 
   AutoStrings()
 
   AutoStrings()
Line 20: Line 24:
 
   DefineStrings(qw(string1 string2))  
 
   DefineStrings(qw(string1 string2))  
 
     -- is a quick way to define "legitimate" strings.
 
     -- is a quick way to define "legitimate" strings.
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserCustomization.pl parserCustomization.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserCustomization.pl.html parserCustomization.pl]
 
** Placeholder for site/course-local customization file.
 
** Placeholder for site/course-local customization file.
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserDifferenceQuotient.pl parserDifferenceQuotient.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserDifferenceQuotient.pl.html parserDifferenceQuotient.pl]
 
** An answer checker for difference quotients.
 
** An answer checker for difference quotients.
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFormulaUpToConstant.pl parserFormulaUpToConstant.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserFormulaUpToConstant.pl.html parserFormulaUpToConstant.pl]
 
** implements formulas ``plus a constant''.
 
** implements formulas ``plus a constant''.
 
** Students must include the ``+C'' as part of their answers
 
** Students must include the ``+C'' as part of their answers
*  [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFormulaWithUnits.pl parserFormulaWithUnits.pl]
+
*  [http://webwork.maa.org/pod/pg_TRUNK/macros/parserFormulaWithUnits.pl.html parserFormulaWithUnits.pl]
 
** Implements a formula with units.
 
** Implements a formula with units.
 
** For example:  
 
** For example:  
 
       FormulaWithUnits("3x+1 ft")->cmp
 
       FormulaWithUnits("3x+1 ft")->cmp
 
       FormulaWithUnits($a*$x+1,"ft")->cmp
 
       FormulaWithUnits($a*$x+1,"ft")->cmp
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFunction.pl parserFunction.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserFunction.pl.html parserFunction.pl]
 
** An easy way of adding new functions to the current context.
 
** An easy way of adding new functions to the current context.
 
** <code>parserFunction("f(x)" => "sqrt(x+1)-2");</code>
 
** <code>parserFunction("f(x)" => "sqrt(x+1)-2");</code>
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFunction.pl parserFunction.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserImplicitEquation.pl.html parserImplicitEquation.pl]
 
** An answer checker for implicit equations.
 
** An answer checker for implicit equations.
 
     Context("ImplicitEquation");
 
     Context("ImplicitEquation");
Line 41: Line 45:
 
     $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]);
 
     $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]);
 
     $f = ImplicitEquation("x=1/y",tolerance=>.0001);
 
     $f = ImplicitEquation("x=1/y",tolerance=>.0001);
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserImplicitPlane.pl parserImplicitPlane.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserImplicitPlane.pl.html parserImplicitPlane.pl]
 
** Implement implicit planes.
 
** Implement implicit planes.
 
     $P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); #  -x+y+3z = 5
 
     $P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); #  -x+y+3z = 5
Line 47: Line 51:
 
     $P = ImplicitPlane([1,0,2],4);                  #  x+2z = 4
 
     $P = ImplicitPlane([1,0,2],4);                  #  x+2z = 4
 
     $P = ImplicitPlane("x+2y-z=5");
 
     $P = ImplicitPlane("x+2y-z=5");
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserMultiAnswer.pl parserMultiAnswer.pl]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserMultiAnswer.pl.html parserMultiAnswer.pl]
 
** Tie several blanks to a single answer checker.
 
** Tie several blanks to a single answer checker.
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserNumberWithUnits.pl parserNumberWithUnits.pl]  
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserNumberWithUnits.pl.html parserNumberWithUnits.pl]  
 
** Implements a number with units.
 
** Implements a number with units.
 
     ANS(NumberWithUnits("3 ft")->cmp);
 
     ANS(NumberWithUnits("3 ft")->cmp);
 
     ANS(NumberWithUnits("$a*$b ft")->cmp);
 
     ANS(NumberWithUnits("$a*$b 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]
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserParametricLine.pl.html parserParametricLine.pl]
 
** Implements Formulas that represent parametric lines.
 
** Implements Formulas that represent parametric lines.
* [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserSolutionFor.pl parserSolutionFor.pl]   
+
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserPopUp.pl.html parserPopUp.pl]
** An answer checker that checks if a student's answer satisifies an implicit equation.
+
** Pop-up menus compatible with Value objects.
 +
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserPrime.pl.html parserPrime.pl]
 +
** Defines <code> f'(x)</code> so that students and authors can use the prime notation in defining equations.
 +
** After loading file use perl command <code>parser::Prime->Enable;</code> to enable the feature.
 +
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserRadioButtons.pl.html parserRadioButtons.pl]
 +
** Radio buttons compatible with Value objects, specifically MultiAnswer objects.
 +
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserSolutionFor.pl.html parserSolutionFor.pl]   
 +
** An answer checker that checks if a student's answer satisifies a (possibly non-linear) implicit equation.
 +
* [http://webwork.maa.org/pod/pg_TRUNK/macros/parserVectorUtils.pl.html parserVectorUtils.pl]
 +
** Utility macros that are useful in vector problems.
 +
 
 +
[[Category:Contexts]]
 
[[Category:MathObjects]]
 
[[Category:MathObjects]]
 +
[[Category:Reference Tables]]

Latest revision as of 08:38, 26 May 2013

parserYourModsHere.pl Modifications to the Parser change the way that student responses are interpreted. By convention files that modify the parser are named starting with "parser" -- e.g. parserYourModsHere.pl. test SpecializedContexts Describes another advanced method for customizing MathObjects by modifying the context.

Examples of modifications are give below.

A description of advanced techniques for customizing the parser are at Modifying Contexts (advanced).

Specialized Parser Macro files

Here is a partial list of the parser modifying files.

Use loadMacros("parserAssignment.pl"); to make the parser modifications available for a WeBWorK question.

Check the POD documentation for more examples.

  • parserAssignment.pl
    • checks answers of the form \(y=3x+5\) 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.
     FormulaWithUnits("3x+1 ft")->cmp
     FormulaWithUnits($a*$x+1,"ft")->cmp
   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);
   $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");
   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.
  • parserPopUp.pl
    • Pop-up menus compatible with Value objects.
  • parserPrime.pl
    • Defines f'(x) so that students and authors can use the prime notation in defining equations.
    • After loading file use perl command parser::Prime->Enable; to enable the feature.
  • parserRadioButtons.pl
    • Radio buttons compatible with Value objects, specifically MultiAnswer objects.
  • parserSolutionFor.pl
    • An answer checker that checks if a student's answer satisifies a (possibly non-linear) implicit equation.
  • parserVectorUtils.pl
    • Utility macros that are useful in vector problems.
follow us