[system] / trunk / pg / lib / Parser.pm Repository:
ViewVC logotype

Log of /trunk/pg/lib/Parser.pm

Parent Directory Parent Directory


Links to HEAD: (view) (download) (as text) (annotate)
Sticky Revision:

Revision 5961 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Jan 11 19:51:51 2009 UTC (11 years ago) by dpvc
File length: 26862 byte(s)
Diff to previous 5938
When a parentheses have been removed, mark the enclosed item so that
we can tell later, if we need to know about the missing parens.

Revision 5938 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Oct 14 12:37:45 2008 UTC (11 years, 3 months ago) by dpvc
File length: 26819 byte(s)
Diff to previous 5927
The copy() method now does not copy values listed by the noinherit()
method (e.g., correct_ans, test_values, etc). This resolves bug #1528.

Revision 5927 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Oct 3 12:36:29 2008 UTC (11 years, 3 months ago) by dpvc
File length: 26745 byte(s)
Diff to previous 5701
Allow the perlFunction method to produce functions that return
formulas when not all the variables are used as arguments.

For example:

    Formula("x+y")->perlFunction('f',['x']);
    $f = f(2);

would produce the equivalent of

    $f = Formula("2+y");

Using the substitute method is more efficient, but this now does the
right thing rather than generate error messages.

Revision 5701 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Jun 15 12:25:41 2008 UTC (11 years, 7 months ago) by dpvc
File length: 26545 byte(s)
Diff to previous 5696
Remove cached perlFunction when a substitution or reduction is made.

Revision 5696 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Jun 14 12:14:21 2008 UTC (11 years, 7 months ago) by dpvc
File length: 26503 byte(s)
Diff to previous 5454
Added

	 no strict "refs"

to try to avoid new error checking in Perl 5.10.

Revision 5454 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 30 02:38:07 2007 UTC (12 years, 5 months ago) by dpvc
File length: 26485 byte(s)
Diff to previous 5453
Disassemble Formula's properly when used with multiple variables in
substitute(), etc.  For example:

    $f->substitute(['x','y'] => Formula("xy,x^2-y^2"));

Revision 5453 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 30 02:20:06 2007 UTC (12 years, 5 months ago) by dpvc
File length: 26347 byte(s)
Diff to previous 5410
Allow specification of values for multiple variables a once for
eval(), substitute() and so on.  You can use

    $f->eval(['x','y'] => Point(1,2));
or
    $f->eval(['x','y'] => [1,2]);
or
    $P = Point(1,2);
    $f->eval(['x','y'] => $P);

to do the equivalent of

    $f->eval(x=>1,y=>2);

Note that you must use quotes for the variable names and that they
must be enclosed in square brackets, not parentheses, when you supply
more than one variable.  You can combine single with multiple
variables, as in

     $f->eval(['x','y']=>Point(1,2),z=>3);

Revision 5410 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 24 03:05:07 2007 UTC (12 years, 5 months ago) by dpvc
File length: 26077 byte(s)
Diff to previous 5396
Use the original when determining what structures to copy.

Revision 5396 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 20 06:35:54 2007 UTC (12 years, 5 months ago) by dpvc
File length: 26077 byte(s)
Diff to previous 5383
Make sure copy() creates new variables and values hash references (and
any other hash or array refs in the formula).

Revision 5383 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 19 18:07:19 2007 UTC (12 years, 5 months ago) by dpvc
File length: 25895 byte(s)
Diff to previous 5364
The copy method was not copying all the values from the original
(since it was making a new object from scratch).  We now copy the
complete hash and recursively copy the parse tree.

Revision 5364 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 18 23:34:09 2007 UTC (12 years, 5 months ago) by dpvc
File length: 25807 byte(s)
Diff to previous 5241
Handle promotion of Parser::Items better when they have been
subclassed, and be sure to initialize the {variables} field.

Revision 5241 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Aug 7 04:35:32 2007 UTC (12 years, 5 months ago) by dpvc
File length: 25800 byte(s)
Diff to previous 5130
Make perlFunction() maintain the context properly when the function is
evaluated.  (Still need to make it set the {equation} field?)

Also set the {equation} field for values returned by eval().

Revision 5130 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Jul 9 12:45:06 2007 UTC (12 years, 6 months ago) by dpvc
File length: 25532 byte(s)
Diff to previous 5117
Added new flags to error checking of operands and function arguments.
This is so that a context can be developed that is more forgiving
about what can be put next to what.  Such a context can NOT be used
for evaluation or answer checking, but can be used to generate TeX
output in more sophisticated situations.

Revision 5117 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Jul 4 01:17:56 2007 UTC (12 years, 6 months ago) by dpvc
File length: 24781 byte(s)
Diff to previous 5116
Use a precedence lower than the lowest allowed precedence when closing
the formula as a whole (to force ALL the operators to be performed).

Revision 5116 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 3 10:44:30 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24780 byte(s)
Diff to previous 5016
Modified the method used to tokenize a formula to use one large
pattern that includes all the token types rather than individual
patterns for variables, strings, operators, and so on.  This allows
the Parser to handle the situation where a token of one type is a
prefix of a token of another type (e.g., < as a parenthesis but <- as
an operator) without worrying about which one is checked first.  The
new mtheod is also more flexible about having additional patterns
(like quoted strings, or arbitrary variable names) and about
specifying the order in which they are applied.

Revision 5016 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Jun 22 02:39:24 2007 UTC (12 years, 7 months ago) by dpvc
File length: 25018 byte(s)
Diff to previous 5001
Handle ans_array() correctly again (context issues, and allow parser
to create a formula from an existing subtree).

Revision 5001 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jun 12 04:05:56 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24998 byte(s)
Diff to previous 4994
More fixes for creating items in the corret context.  Also added a
method for looking up the package associated with a particular Parser
class (for consistency with the Value->Package call).

Revision 4994 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Jun 10 01:17:29 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24847 byte(s)
Diff to previous 4991
Update to handle the fact that the Value package now includes the
context with all MathObjects.  (This may still need some work.)

Revision 4991 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Jun 8 02:09:21 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24630 byte(s)
Diff to previous 4979
Update new() and make() methods to accept a context as the first
parameter (making it easier to create objects in a given context
without having to resort to a separate call to coerce them to the
given context after the fact).

Revision 4979 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Jun 7 11:59:05 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24564 byte(s)
Diff to previous 4975
More updates for marking MathObjects with the context in which they
were created, so they should now work like the Formula objects in that
respect.  As they are combined via overloaded operators, they should
pass on their contexts correctly.

Also normalized the use of getFlag() to obtain flags from the
MathObject's context rather than looking in the context directly.
This allows the math object to override the flag by setting the flag
value in the object's hash (e.g., $f->{tolerance} = .001).  I've also
added the ability to override context flags via the answerHash (e.g.,
$f->cmp(tolerance => .001)), though some filtering may need to be
added to this at some point.  Note that ONLY the context flags can be
overridden, not other parts of the context.

Revision 4975 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Jun 6 21:44:05 2007 UTC (12 years, 7 months ago) by dpvc
File length: 24565 byte(s)
Diff to previous 4382
This begins some major updates to the Parser and Value libraries.
This may make the MathObjects unstable as things shake down, but I'll
try to keep that to a minimum.

This update reorganizes how the overloading of operations are
implemented.  The base Value class is now overloaded rather than the
individual Value classes.  This makes it easier to make subclasses
that take advantage of the overloading.

The code that handles promoting one MathObject to another has been
updated as a part of this.  This should also make subclassing the
existing MathObjects more flexible.

In the past, Formula objects included a pointer to the Context in
which the object was created, but other MathObject did not.  This
update is the first round of updates to include the context in the
other MathObjects, but more work needs to be done.

The changes here should not affect existing problems; it is possible
that some macro files will need to be updated, but none of the
standard ones in pg/macros seem to need it at the moment.

Revision 4382 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Aug 16 01:37:28 2006 UTC (13 years, 5 months ago) by dpvc
File length: 25024 byte(s)
Diff to previous 3652
Fixed a bug where substituting values into a Formula object would not
be cleaned up properly (so later actions could incorrectly include the
same substitution).

Revision 3652 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Sep 24 00:47:30 2005 UTC (14 years, 4 months ago) by dpvc
File length: 24762 byte(s)
Diff to previous 3612
Added ability to have answers that are empty strings.  String("") now
will produce a valid string object regardless of the Context's defined
string values.  (You can prevent this using

       Context()->flags->set(allowEmptyStrings=>0);

if you wish).  String("")->cmp will produce an answer checker for an
empty string (it removes the blank checker that WW installs).

Revision 3612 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Sep 12 20:26:01 2005 UTC (14 years, 4 months ago) by dpvc
File length: 24612 byte(s)
Diff to previous 3515
Avoid undefined value of $name.

Revision 3515 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 13 20:55:35 2005 UTC (14 years, 5 months ago) by dpvc
File length: 24590 byte(s)
Diff to previous 3467
Make formulas that produce lists get default open and close parens,
and have them retained in Formula() results.

Revision 3467 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 11 14:20:31 2005 UTC (14 years, 5 months ago) by dpvc
File length: 24523 byte(s)
Diff to previous 3374
Properly maintain open and close parens in emtpy lists.

Revision 3374 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Jul 13 01:46:49 2005 UTC (14 years, 6 months ago) by dpvc
File length: 24487 byte(s)
Diff to previous 3370
Wrong correction in the previous commit.  Use CODE::push

Revision 3370 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 12 22:29:53 2005 UTC (14 years, 6 months ago) by dpvc
File length: 24482 byte(s)
Diff to previous 3369
A first pass at making parser error messages localizable.  The
Context()->{error}{msg} hash can be used to specify translations of
the standard messages.  For example,

    Context()->{error}{msg}{'Division by zero'} = "Don't divide by zero, dude!";
    Context()->{error}{msg}{'Function '%s' has too many inputs'} =
        "You passed too many arguments to '%s'";

(I didn't translate into another language, here, but you could do
that, too.)

The msg hash could also be used within answer checkers to make certain
answer messages more appropriate for the given type of expected answer.

Revision 3369 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 12 21:05:37 2005 UTC (14 years, 6 months ago) by dpvc
File length: 24389 byte(s)
Diff to previous 3352
Fixed various perl compiler warnings (due to extra "my", and so on).

Revision 3352 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 5 01:38:19 2005 UTC (14 years, 6 months ago) by dpvc
File length: 24388 byte(s)
Diff to previous 2985
Modified the perl() method to make calles to Value:: directly rather
than to the main:: stubs for creating Value objects.  This will make
it work better from within packages or when Parser.pl hasn't been
loaded.

A few things still won't work in this case; e.g., calls to Closed()
for intervals (these could be handled better using ->with()) and to
functions like Factorial and log10 that are defined in Parser.pl.

Finally, there should be better object-based control over what
routines are called to create these objects, so that subclasses of the
Value objects will be able to be generated correctly.

Revision 2985 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Nov 3 22:39:21 2004 UTC (15 years, 2 months ago) by dpvc
File length: 24377 byte(s)
Diff to previous 2969
Fixed a bug in processing absolute values with implicit
multiplication.

Revision 2969 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Nov 2 01:55:21 2004 UTC (15 years, 3 months ago) by dpvc
File length: 24197 byte(s)
Diff to previous 2823
Fixed typo in a comment.

Revision 2823 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Sep 23 21:09:14 2004 UTC (15 years, 4 months ago) by dpvc
File length: 24196 byte(s)
Diff to previous 2803
Fixed Parser so that you can replace the Formula class as well as the
other object types.

Revision 2803 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Sep 19 15:11:08 2004 UTC (15 years, 4 months ago) by dpvc
File length: 24161 byte(s)
Diff to previous 2798
The $Parser::class variable was being handled after the "use"
statements at the end, so had to put a BEGIN around it.

Revision 2798 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Sep 19 11:29:06 2004 UTC (15 years, 4 months ago) by dpvc
File length: 24131 byte(s)
Diff to previous 2796
Make Formula()->eval return a Real (ie, aValue::Real object) rather
than a perl number.  That way, you can use $f->eval->cmp rather than
needing Real($f->eval)->cmp, and so on.

Also make Formula()->perl do the same, for consistency.

(This could have been accomplished by having the Parser::Number class
evaluate to a Real, but for efficiency during computation, we put
off making the Real object until the end.  It probably doesn't make
that big a difference, but every little bit helps.)

Revision 2796 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Sep 19 01:15:03 2004 UTC (15 years, 4 months ago) by dpvc
File length: 24034 byte(s)
Diff to previous 2682
Added flags that control the reductions performed by
Formula()->reduce.  Each reduction operation can be individually
enabled or disabled in the context, and in the reduce() call itself.

More complex reductions need to be developed.

Revision 2682 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Aug 24 03:36:54 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23971 byte(s)
Diff to previous 2678
Fixed a bug with  sin^2 x  that introduced when I adjusted the
error report for implied multiplication.

Revision 2678 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 23 23:55:37 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23898 byte(s)
Diff to previous 2676
Modified the parser so that the classes for the various object
constructors are stored in the context table rather than hard-coded
into the parser.  That way, you can override the default classes with
your own.  This gives you even more complete control to modify the
parser.  (You had been able to replace the definitions of operators,
functions and list-like objects, but could not override the behaviour
of numbers, strings, variables, and so on.  Now you can.)

This effects most of the files, but only by changing the name of the
calls that create the various objects.

There are also a couple of other minor fixes.

Revision 2676 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 23 05:00:16 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23569 byte(s)
Diff to previous 2673
Better highlighting for syntax error involving implied
multiplication.  (No highlighted had been done in the past.)

Revision 2673 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 23 01:21:27 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23376 byte(s)
Diff to previous 2664
Moved WW-specific routines from Parser.pm to WeBWorK.pm.
Changed error reporting when the error message was not generated by
the parser directly.  (The stack trace and line number references are
removed before the error is reported.)

Revision 2664 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 21 22:02:14 2004 UTC (15 years, 5 months ago) by dpvc
File length: 24219 byte(s)
Diff to previous 2660
Added a file to perform WeBWorK-specific modifications to the
Parser/Value packages.  (I've tried to make these independent of
WeBWorK, so you can use them in other perl code if you want to.)

The parameters for fuzzy reals and some of the other parameters now
are taken from the pg->{ansEvalDefaults} values (as defined in
global.conf or course.conf).  More still needs to be done with this,
however.

Revision 2660 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 20 15:52:32 2004 UTC (15 years, 5 months ago) by dpvc
File length: 24242 byte(s)
Diff to previous 2657
A number of adjustments to get negative infinities to work better.
They used to be stored as separate Parser strings, but now they are
flagged versions of a single string.

All of the problems are really due to the fact that there is no
Infinity class in the Parser (only a Value version).  That should be
changed, but will require some work, and can be put off for now.

It would be best if the classes within the two packages would match up
nearly 1-to-1, but for historical reasons, they don't.  Since the
introduction of Real, String and Infinity classes to the Value
package, The Infinity class is the one main difference between the
two, and once that is fixed, everything needs to be looked over to
check for unnecessary complications due to the historical lack of classes
in one or the other package.

Revision 2657 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 20 11:13:51 2004 UTC (15 years, 5 months ago) by dpvc
File length: 24150 byte(s)
Diff to previous 2650
Handle trapped error messages that are not produced by the parser
error reporter (i.e., by bugs within the parser itself).  Also added
an error if implied multiplication is attempted when the operator for
it is not defined in the current context.

Revision 2650 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 19 14:23:00 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23865 byte(s)
Diff to previous 2628
Added Parser::Number::NoDecimals() function that causes the parser to
give an error message when the student types a decimal number.  This
means the student must enter fractions as fractions, or values like
sqrt(2) or pi/4 symbolically not numerically.

Revision 2628 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 16 21:41:05 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23726 byte(s)
Diff to previous 2611
Allow parser "constants" to be (in reality) formulas.  That way, for
example, you can defined T, N and B to be the formulas for the unit
tangent, normal and binormal of a space curve (as functions of "t")
and the student can write anwers in terms of T, N and B (without
having to compute them).

You could have created FUNCTIONS T(t), N(t) and B(t), and added them
to the parser to get almost the same effect, but the students would
have had to include the "(t)".  (If you want that, go ahead and do it
that way.)

Revision 2611 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 14 15:59:35 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23828 byte(s)
Diff to previous 2609
Fixed a typo in one of the parser answer checkers.  Added a line that
was incorrecctly removed in the parser.

Revision 2609 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 14 13:54:52 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23722 byte(s)
Diff to previous 2605
Added a String type to the Value package.  Mostly this is to make it
possible to generate an answer checker for it that uses the parser.
It also makes it more consistent for handling things like stringify,
especially when they are recursively called internally.

Added new default strings "NONE" and "DNE", since these get used a
lot.

Modified how the default parameters are set up for the answer
checkers, and how the answer checker reports the expected answer type
in type mismatch error messages.

Revision 2605 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 14 02:50:18 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23742 byte(s)
Diff to previous 2592
Incorporated infinities into Parser package better.  They have been
stored as String objects (with extra data) in the parser, and I've
left it that way, but now they convert to/from Vallue::Infinity
objects correctly, and these are used for generating the output.

Also added the Infinity answer checker, and adjusted the error
messages produces by type mismatches in the answer checkers and
elsewhere.

Revision 2592 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 12 16:40:47 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23860 byte(s)
Diff to previous 2579
A number of small fixes.  Most were to fix minor bugs in string and
TeX output, particulary for the various list-based objects (like
vectors, intervals, etc.).  There were also some bug fixes in the
comparison routines.  Some additional checks were added for valid
intervals when the coordinates are formulas.

Revision 2579 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 9 21:38:01 2004 UTC (15 years, 5 months ago) by dpvc
File length: 23043 byte(s)
Diff to previous 2576
Significant update to new parser.

New features include:

  Better control over format of vector output (you can now
    specify ijk-format rather than <...> format)

  "Fuzzy" reals, where the relations like == return true when the
    two values are "close enough".  (This is controlable using
    parameters similar to those used in NUM_CMP).

  The fuzzy reals are now used in vectors/points/matrices/complexes/intervals
    and so on so that their relations will also be fuzzy.  E.g.,
    (1E-13,2) == (0,3) will be true, and norm(Vector(0,1E-13)) will
    equal 0.

  The two main portions of the parser (the Parser and Value packages)
    now share a common context object for configuration purposes.

Revision 2576 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Aug 4 20:52:28 2004 UTC (15 years, 5 months ago) by dpvc
File length: 22971 byte(s)
Diff to previous 2558
Make Parser work with PGauxiliaryFunctions.pl, and add the macro files
needed to initialize the parser.

Revision 2558 - (view) (download) (as text) (annotate) - [select for diffs]
Added Wed Jul 28 20:32:33 2004 UTC (15 years, 6 months ago) by sh002i
File length: 22708 byte(s)
merged changes from rel-2-1-a1 -- stop using that branch.

This form allows you to request diffs between any two revisions of this file. For each of the two "sides" of the diff, enter a numeric revision.

  Diffs between and
  Type of Diff should be a

Sort log by:

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9