Specialized parsers

From WeBWorK
(Difference between revisions)
Jump to: navigation, search
(Specialized Parser Macro files)
(Specialized Parser Macro files)
Line 35: Line 35:
** 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/doc/cvs/pg_CURRENT/macros/parserImplicitEquation.pl parserImplicitEquation.pl]
** An answer checker for implicit equations.
** An answer checker for implicit equations.

Revision as of 20:02, 18 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).

An other advanced method for customizing MathObjects is to modify the context in which the appear. See SpecializedContexts

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 \(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.
    -- all strings are accepted
  DefineStrings("string1", "string2")
  DefineStrings(qw(string1 string2)) 
    -- is a quick way to define "legitimate" strings.
     FormulaWithUnits("3x+1 ft")->cmp
   $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);
follow us