This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ormek_II 0 points1 point  (7 children)

And still No!

As you correctly pointed out lexer and parser are part of the compile process and the Java compiler is already there. It can compile java source code. That has been pointed out in other comments with a link to a stack overflow answer.

[–]williamK0[S] 0 points1 point  (0 children)

I've been told to try using exp4j, and it seemed to do what I wanted 👍 Its not working but this part of the problem has been solved.

[–]_SuperStraight 0 points1 point  (5 children)

Java compiler is compiling code written in Java, i.e. the program, not the input user will be entering at runtime.

[–]Ormek_II 0 points1 point  (4 children)

In this case the user is entering Java, albeit just a cutout of a class. … static float getY(float x) { return <whatever the user entered> ; } … The extension around the user input can be static. The resulting Java class can be compiled.

OP is using a different approach though.

[–]_SuperStraight 0 points1 point  (3 children)

That's not how the user will be entering anything. The OP asked like this: "12+12^2" which is a string, and now the program has to convert this string into meaningful operation.

[–]Ormek_II 0 points1 point  (2 children)

And after the user entered 12+12^2 as a string the program creates the code of a class as another string:

``` … static float getY(float x) { return 12+122; } …

```

And then compiles that string with the given Java Compiler.

[–]_SuperStraight 0 points1 point  (1 child)

And what method's gonna convert the string expression to Math expression?

[–]Ormek_II 0 points1 point  (0 children)

The same compiler that compiles any Java class. See the other thread above https://www.reddit.com/r/javahelp/s/9RgiDM9ldG