Span text

Ian's Javascript Expression Compiler Beta Demo Page
(update 17/10/25 view source links now all work correctly.)
(Version 7.37 6/2/19 ? works mostly ok. )
(The development of this program/demo was rather halted due to having to spend time to do with an elderly relative.
This version is not 100% debugged, but I thought I would put it up anyway.)

About

If you aren't familiar with compilers, look at the compile and run and graph equation box lower down the page.


Bugs are:-
String literal expressions will compile but not run.
Arithmetic operators of same priority probably associate right to left not left to right at the moment.
Arity on functions is not checked so if you type in the wrong number of paramaters to a function it will
create a stack error at run time.
I think there is a bug in parsing function parameter lists, the cure is probably to use brackets to avoid
ambiguity.
Good luck!

Back to Index Page

Compiler Help and Technical Glossary

View Source Code
:
View file: comp_exp_tst1.html
View file: orgsite.css
View file: ai_demo_compiler_parser_upm_1.css
View file: ai_demo_ajax_interface_upm_7.js
View file: ai_demo_comp_pars_txt_edit_upm_7.js
View file: comp_opcodes1_upm_js7.js
View file: comp_runtime1_two_vers_05_upm_js7.js
View file: comp_equations1_upm_js7.js
View file: comp_buttons1_upm_js7.js
View file: ai_demo_cmp_exp_dsp_tree_1.js
View file: ai_demo_label_extensions_upm_1.js
View file: ai_demo_comp_expcomp_upm_1.js
View file: orgsite.js


What is a compiler? Look at Wikipedia entry

What is an expression compiler? It is a small compiler than parses/compiles an arithmetic expression only
(not a whole proper program), then creates some kind of computer friendly intermediate code, which, if run,
will compute the value of the arithmetic expression.

Buttons Help: Click on the for help on the button to the left. Click here for help about this.

To Choose, Compile and Run and Graph an
equation, do the following.

Select an equation using the button. Then compile, run and graph it using the button.
(You will then have to close the graph window using the close graph window button.)
You can view and edit the text in the Compiler Input Text Box (see lower down the page) and try to compile and run it again.
You can also view the parse tree
output (displayed lower down the page) using the button.
Or you can also view the output intermediate object code (displayed lower down the page (see Program Output) using the button.





Compiler Input Text Box Gptr text

Old Test Buttons (These are a bit out of date at the moment, see lower down for the right buttons to use.)
Click the buttons to run the tests if you want, or see the help.

buttons text




Buttons you want to use. (Not out of date test buttons.)
To compile and run a program or graph a function, first enter your text into the input box either by typing or editing it manually, or by using the :


To compile and run your expression you have a choice of the following:
which will attempt to
compile your expression and generate and display a parse tree. (Lower down page.)
which will attempt to compile your
expression to a parse tree and then if that is successful, attempt to generate intermediat code from it and then display it.
which will attempt to do a complete compile
then if that is successful, run the intermediate code as a program which will yield a displayed result if successful.
For graphing equations. This will attempt to do a complete compile
then if that is successful, run the intermediate code as a program to plot the curve graphically.
Use this option if the expression is intended to be for a graph.

Related Buttons
These two buttons will run the intermediate code if it has aleady been compiled without recompiling it.
This runs the program and displays the result if successful. Use for expressions that are not intended to be for graphs.
This runs the program and graphs the result if successful. Use for expressions that are intended to be for graphs.
Code Display Buttons
Displays the parse tree (lower down the page) if it exists.
Displays the parse tree (lower down the page) if it exists.


Alternatively you can reset/single step through the intermediate code (without graphing anything) using these buttons:
The stack and Program counter position are displayed at each step.
This resets the program counter to the start of the program and clears the program stack.
This single steps through the intermediate code program display the stack as it does.




Parse Error Report:
Pars Error span text

Error Report:
Error span text






Program Output

id1 p text

,

Gptr text

stack text

id1 div text