Moodle
  1. Moodle
  2. MDL-7198

New grammar analyzer for Calculated question with pluginable packages of functions.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.4
    • Fix Version/s: None
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      New exptession's grammar analyzer let you use any your private functions. You can put theirs in package and attach to calculated question type. Also you can create wrappers for standard PHP functions.
      Features:
      1. Real grammar analyzer.
      2. Checking accuracy of expression without reloading question's editing page.
      3. Pluginable packages of functions (you can use any private functions).
      4. Using arrays as parameters of functions.

      Also included package of EGM Mathematical Finance class created by Enrique Garc?a M. (2003-2004) and distributed under GNU GPL.

      Note: Package should named as 'package.php' and puted in individual folder. Names of functions should start from folder name.
      For example:
      All standard functions were moved in package 'math', so now their names have prefix 'math_' (math_sin, math_abs etc.)

      Grammar of expressions:
      <Expr>::=<Term>

      {<OperationLP><Term>}

      <OperationLP>::='+'|'-'
      <Term>::=<Factor>

      {<OperationHP><Factor>}

      <OperationHP>::='*'|'/'
      <Factor>::=<UnaryOp><Factor>|<Base>
      <UnaryOp>::='+'|'-'
      <Base>::=<Variable>|<Function>|<Number>|'('<Expr>')'
      <Function>::=<Letter>

      {<Letter>|<Digit>|'_'}'('<Parameter>{','<Parameter>}')'
      <Parameter>::=<Boolean>|<Expr>
      <Boolean>::='true'|'false'
      <Variable>::='{'<Letter>{<Letter>|<Digit>|'_'}

      '}'
      <Letter>::='A'|...|'Z'|'a'|...|'z'|'_'
      <Number>::=<Digit>

      {<Digit>}['.'<Digit>{<Digit>}

      ][('E'|'e')['+'|'-']<Digit>

      {<Digit>}

      ]
      <Digit>::='0'|...|'9'

        Gliffy Diagrams

        1. folder.PNG
          8 kB
        2. grammar.PNG
          18 kB

          Issue Links

            Activity

            Hide
            Dmitry Pupinin added a comment -

            Tim, what are you think about it?

            Show
            Dmitry Pupinin added a comment - Tim, what are you think about it?
            Hide
            Tim Hunt added a comment -

            This looks really interesting, but to be honest, I don't have time to give it the attention it deserves right now.

            Can I suggest that you post about it in the quiz forum http://moodle.org/mod/forum/view.php?f=121. That way lots of people will be able to try it out and give feedback.

            Show
            Tim Hunt added a comment - This looks really interesting, but to be honest, I don't have time to give it the attention it deserves right now. Can I suggest that you post about it in the quiz forum http://moodle.org/mod/forum/view.php?f=121 . That way lots of people will be able to try it out and give feedback.
            Hide
            Pierre Pichet added a comment -

            This grammar analyser seems better than the actual code and a first version using only the standard php math functions will be implemented.
            However the usual math functions will retain their PHP name and not math_name as suggested by Dmitry.

            Show
            Pierre Pichet added a comment - This grammar analyser seems better than the actual code and a first version using only the standard php math functions will be implemented. However the usual math functions will retain their PHP name and not math_name as suggested by Dmitry.
            Hide
            Pierre Pichet added a comment -

            The proposed grammr does not allow usual php functions which have to be maintained.
            Looking closley at the code there is no verification of number of parameters as every functions are real normal PHP functions with no limits in the number of parameters.
            for example.
            function math_cos($number)

            { return cos($number); }

            So if the user put more than one parameter in math_cos() , cos($number) will use only the first one.
            I have to figure how to integrate the normal math PHP functions in the proposed grammar analyser process.
            I will explore also if we could not use the Excel functions and the Parser.php already on moodle as they are more "universal".

            Show
            Pierre Pichet added a comment - The proposed grammr does not allow usual php functions which have to be maintained. Looking closley at the code there is no verification of number of parameters as every functions are real normal PHP functions with no limits in the number of parameters. for example. function math_cos($number) { return cos($number); } So if the user put more than one parameter in math_cos() , cos($number) will use only the first one. I have to figure how to integrate the normal math PHP functions in the proposed grammar analyser process. I will explore also if we could not use the Excel functions and the Parser.php already on moodle as they are more "universal".
            Hide
            Dmitry Pupinin added a comment -

            I have made new version of Calculated question for Moodle 1.8.
            I have removed math package and does this functions native. Native
            functions moved out from general code and now simple for modify/add.
            New forms library supporting.

            PS: In next release I will add checking inline formulas in question
            text.

            Show
            Dmitry Pupinin added a comment - I have made new version of Calculated question for Moodle 1.8. I have removed math package and does this functions native. Native functions moved out from general code and now simple for modify/add. New forms library supporting. PS: In next release I will add checking inline formulas in question text.
            Hide
            Anthony Borrow added a comment -

            Dmitry/Tim - Should we move this issue to CONTRIB and add the code there? I received a Moodle message from Dmitry which I took to be requesting that. Let me know how I can be of help. Peace - Anthony

            Show
            Anthony Borrow added a comment - Dmitry/Tim - Should we move this issue to CONTRIB and add the code there? I received a Moodle message from Dmitry which I took to be requesting that. Let me know how I can be of help. Peace - Anthony
            Hide
            Tim Hunt added a comment -

            Moving to contrib seems like a good idea at this stage.

            Show
            Tim Hunt added a comment - Moving to contrib seems like a good idea at this stage.
            Hide
            Dmitry Pupinin added a comment -

            Anthony, I has added request as you ask.
            CONTRIB-887

            Show
            Dmitry Pupinin added a comment - Anthony, I has added request as you ask. CONTRIB-887
            Hide
            Pierre Pichet added a comment -

            This appears a very good solution to continue the development of this library...
            The library that Dmitri posted last year contains useful financial functions.
            Implementing such a library as official moodle code needs a lot of testing and the contrib status will allow this.
            If Dmitry could extend his work to other general useful functions like those of Excel or similar software, this will be appreciated.

            Show
            Pierre Pichet added a comment - This appears a very good solution to continue the development of this library... The library that Dmitri posted last year contains useful financial functions. Implementing such a library as official moodle code needs a lot of testing and the contrib status will allow this. If Dmitry could extend his work to other general useful functions like those of Excel or similar software, this will be appreciated.
            Hide
            Dmitry Pupinin added a comment -

            Possibility to add own functions allow to users improve functionality of this question type.
            I think is not reasonable to add some special function because its may be unneeded. Functions can be added by users or on request.
            In any case this place is good point to start:
            http://www.phpclasses.org/

            Show
            Dmitry Pupinin added a comment - Possibility to add own functions allow to users improve functionality of this question type. I think is not reasonable to add some special function because its may be unneeded. Functions can be added by users or on request. In any case this place is good point to start: http://www.phpclasses.org/
            Hide
            Anthony Borrow added a comment -

            linking to CONTRIB-887

            Show
            Anthony Borrow added a comment - linking to CONTRIB-887
            Hide
            Dmitry Pupinin added a comment -

            Version for Moodle 1.9.x also available in CVS CONTRIB
            contrib/patches/question_calculated_extended

            Show
            Dmitry Pupinin added a comment - Version for Moodle 1.9.x also available in CVS CONTRIB contrib/patches/question_calculated_extended

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: