-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite the parser #62
base: master
Are you sure you want to change the base?
Conversation
Finally found some time to take this a step further. Tokenizer is fully functional. It is still work in progress, many things are missing and implementations are likely to change. Next steps:
|
de0df5f
to
0902aa3
Compare
Parser is now more or less finished. There's some refactoring and some fine tuning left and there will probably be a few bugs. Next step: evaluation. Currently, there is virtually no evaluation in the code, because everything is sent to |
Update: Evaluation of expressions is basically working, with a few things left to be done, namely all the variable stuff (replace variable by its content at the right time and assign new values to variables). Also, evaluation (not parsing!) of for loops is not done yet. These are the next steps. |
Variables are now basically working. What remains to be done:
|
Almost all functions are now available and working. Here's what remains to be done (implemented/written or tested):
|
I have started the integration of the new parser. That's going to take a while. Please note: From now on, some tests will be failingSome tests depend on legacy code that might have been removed or changed. These tests will have to be updated once the integration is done. Until then, they will fail. |
It is now possible for teachers to "deactivate" built-in functions for the student's response by overwriting them as variables. As the teacher can still access those overwritten functions by using the PREFIX operator, they can use them in their model answers, but students cannot. Example: Question asking the student to give an equivalent of For the docs: Teachers SHOULD NOT use the prefix operator in the model answer for an algebraic formula, because the model answer is used for the "The correct answer is …" feedback and when the student clicks "Fill in correct responses". Using the prefix in the model answer will then show an answer that the student cannot successfully submit. This is not a problem for the other answer types, because the result will be numerically evaluated.In the example above, the teacher should thus not write |
Thinking of it again, I will make sure that using the PREFIX in an algebraic formula's model answer will give an appropriate error message, I think it is not good to have the docs say that one should not do something, but allow them to do it anyway… |
The current parser goes back to the very first version. It is entirely based on regular expressions. However, these can only partially parse languages. This has several consequences:
sin
. But let's say a Spanish speaking user defines a variablesen
(to store some sine value). This will work, because there is no such function at the moment. Now, if we add the functionsen
in a month, the question will stop working because of the conflicting name.eval()
which is considered bad practice, even if it's done very cautiously.The aim of this PR is to completely rewrite the existing parser. In the end, we should be able to
eval()
✓pi
orπ
instead ofpi()
; the old syntax will remain valid for backwards compatibility ✓(a == b ? "yes" : "no")
as an easier and more readable alternative topick()
✓+
to concatenate (join) strings as a short alternative tojoin()
✓==
comparison for strings ✓Also, the new parser should make it easier to locate possible syntax errors in a definition, e.g. better indicate the row and column number.