537 questions
0
votes
1
answer
47
views
How to detect starting parenthesis '(' using Koltin infix function
I am building SQL where clause like expression in pure Kotlin.
I am facing problem in detecting if user has used starting parenthesis in their code or not.
I have created a working and replicable ...
1
vote
1
answer
88
views
Why parser return ParseException with wrong message?
I'm working on implementing a parser that is supposed to process the input string, extracting its components, validating them, and then creating a SQL Alchemy query from it. At the moment, I'm working ...
1
vote
1
answer
72
views
Infix operators with 3 parameters ocaml
Is it possible in ocaml to define an operator like the array set function which can be written a.(n)<-v?
The OCaml manual explains how to define 2-parameters infix operators but not 3-parameters ...
-1
votes
2
answers
240
views
Algorithm for converting infix to postfix with Python
I am attempting to write up the following algorithm (provided in ordinary English) in Python for converting simple mathematical expressions from infix form to postfix form:
Create a new empty list, '...
0
votes
0
answers
34
views
Input precedence value and stack precedence value
There is some eror in input precedence value and stack precedence value for conversion of infix expression to prefix expression(in the table).
Please provide the corrected value:
|Symbol| Stack | ...
0
votes
0
answers
51
views
Infix to Postfix sending out an operator incorrectly
I am doing a project where i take in an infix expression and change it to a postfix expression using a string array. I have passed several of the test cases and am having a hard time understanding ...
1
vote
1
answer
222
views
Convert prefix to infix with minimum number of parentheses
Right now this is my code:
precedence = {
"+": 1,
"-": 1,
"*": 2,
"/": 2,
"": 0
}
def is_operator(token):
ope = set(['+', '-',...
0
votes
2
answers
120
views
Is it possible to do infix function composition in python without wrapping your functions in some decorator? [duplicate]
Title says it all. Seen lots of answers where folks have implemented f @ g, but this requires wrapping f, g in some infix decorator or class. Is it possible to get this to work? Maybe by patching some ...
1
vote
1
answer
537
views
Infix to postfix in c
I am trying to convert a given infix expression to prefix expression in c. But i am encountering a problem in it. The value in postfix is not getting updated. Please help me understand what the issue ...
1
vote
0
answers
103
views
Ruby infix to postfix math expression converter (to RPN)
First of all, I started learning Ruby only 2 weeks ago, so please do not judge too harshly.
I wrote a script that does not work correctly with mathematical expressions containing parentheses. The ...
9
votes
1
answer
130
views
How does the scope effect EVAL of an infix:<> sub?
This code works as expected:
sub infix:<mean>(*@a) {
@a.sum / @a.elems
}
sub Mean (*@a) {
@a.sum / @a.elems
}
say EVAL 'Mean 2, 6, 4'; # Output: 4
say EVAL '2 mean 6 mean 4'; # ...
0
votes
2
answers
75
views
How to use integer methods using `method`, not their infix form, in Ruby
I am looking to programmatically apply a typically infixed operation (eg: +, -, *, /) on two integers, where the operation is specified via a string. I have had success accessing the method itself ...
1
vote
1
answer
177
views
Postfix to Infix notation conversion in C
I am having a problem converting from postfix to infix in C.
I know where the problem is, but I don't know how to fix it.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
...
3
votes
3
answers
919
views
How do you use a function as an infix operator?
To use an infix operator as a prefix function in OCaml, you can put parenthesis around it. for example, 1 + 2 is equivalent to (+) 1 2.
How do you do the opposite?
For example, in Haskell, a prefix ...
0
votes
0
answers
96
views
Infix to postfix assignment
I've been stuck on this program for about a week and I can't see what I'm doing wrong. I can't get the operands and operators to print in the proper spot and the '(' ')' won't delete. Here's what I ...
1
vote
1
answer
483
views
pyparsing infix notation with non-grouping parentheses
I'm working on a billing application where users can enter arbitrary mathematical expressions. For example, a line item might be defined as (a + b) * c.
pyparsing handles the order of operations well ...
0
votes
0
answers
106
views
How to wrap Scala Infix expressions within long lines in IntellijIDEA?
I am using the .editorconfig file in order to configure my IntellijIDEA IDE to reformat Scala code in a specific way.
I specified a right margin, and specified for it not to be exceeded, however, this ...
-1
votes
1
answer
228
views
Infix -> postfix translator in antlr4
I need to define the semantic actions required to translate infix notation to postfix notation by embedding semantic actions as Java code in the g4 grammar file.
For example, when I try to input "...
-2
votes
1
answer
62
views
A program which evaluates a mathematical expression by first converting it into RPN and evaluating the result using precedence of operators
#include <stdio.h>
char infix[200];
char stack[200];
char queue[200];
int count_stack = 0;
int count_queue = 0;
int precedence(char x)
{
switch (x)
{
case '^':
return 2;
...
0
votes
0
answers
139
views
Made an infix to postfix converter and calculator using an array based stack in c++. The calculations don't work. Only returns the top of the stack
My problem is that my evaluatePostfix() function is not calculating operands. It only returns the top of the stack in the converted postfix expression.
So for example, my output is:
Enter a infix ...
0
votes
0
answers
2k
views
Python Program Infix to Postfix and Prefix Conversion
I was hoping you will be free and could help me solve my codes. I'm entirely new to python programming so I'm at the phase of learning on my own or self-study. So bare with me if my code seems really ...
3
votes
1
answer
1k
views
Whats "infix" in Haskell?
I have seen Haskell code like this:
infix 4 ~=
(~=) :: Double -> Double -> Bool
x ~= y = abs (x-y) < epsilon
where epsilon = 1 / 1000
Despite that I know what this code is doing, I would ...
-1
votes
1
answer
616
views
I have written this code to convert an infix expression to a postfix expression using Stacks in CPP
#include<bits/stdc++.h>
using namespace std;
int prec(char c){
if(c=='^'){
return 3;
}else if(c=='*' || c=='/'){
return 2;
}else if(c=='+' || c=='-'){
return ...
1
vote
1
answer
282
views
Android Studio Java infix to postfix calculations decimal point gives crash
I was trying to make a calculator for my university homework. to calculate the results I use infix to postfix convention. but this code doesn't take only decimal point (.) as a result, it crashes ...
0
votes
4
answers
676
views
Kotlin infix function with generics
Try to write a simple Kotlin infix function for plus operation. What's wrong with generic type?
infix fun <T : Number> T.myPlus(that: T): T = this + that
1
vote
1
answer
113
views
How Can I convert infix expression containing ++ or -- to a normal infix expression
Basically, I'm trying to get rid of ++ or -- from an infix expression by incrementing the value that's applied to it, but the code gives a weird output. I also used a shifting function to delete the ++...
1
vote
0
answers
60
views
What can I leverage (from R) to convert expressions with nested fractions from infix-notation to LaTeX?
I'd like something to convert pretty basic math expressions, having nested parentheses and fractions, to LaTeX notation. Like mathquill, but a function (or even the building blocks of one).
There seem ...
1
vote
1
answer
232
views
How do you stop infix_notation from matching the base expression when there are no operations (pyparsing)?
I am trying to parse expressions with pyparsing, and can do that with infix_notation, but the problem is that it matches lines that have no operations, and just match the base_expr argument. This is a ...
1
vote
1
answer
99
views
I am trying to make a function to convert from prefix to infix implementation in C
I am trying to make a function to convert from prefix to infix implementation in C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define type ...
1
vote
0
answers
392
views
Convert infix to postfix which make use of user defined functions
What would be a good algorithm to convert infix to postfix of an expression which uses user-defined functions:
For example:
def get_random_integer(a, b, c):
import random
return random.choice([...
-3
votes
1
answer
301
views
Postfix to Infix conversion in C++. "Process returned -1073740940 (0xC0000374) execution time : 5.538 s". No clue why [closed]
The question is to convert a postfix expression to an infix expression using stacks and without stack library.
Im getting a statement after i run it and enter my postfix expression saying : "...
1
vote
1
answer
270
views
Scala call single parameter method using space in anonymous class body
In scala, how can I call a single parameter method using space in the body of the anonymous class?
add "Answer3" below is not working
trait Question {
def add(answer:String):Unit = {
...
2
votes
1
answer
145
views
Can someone explain this function and how to type it in Haskell (infix, :-:)
infixr 5 :-:
data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
we just wrote a :-: (List a) instead of Cons a (List a). Now, we can write out lists in our list type like so:
...
1
vote
1
answer
231
views
infix to postfix conversion using stack shows an infinite loop
below is the code of infix to postfix conversion using stack.The code executes an infinite loop printing stack underflow in one of the pop function ,i have tried commenting pop function call in right ...
2
votes
2
answers
104
views
Non type-variable argument in the constraint error, while using with infix
Unfortunately I have been facing a strange error. It happens while using infix with data constructor.
I am new to Haskell. Can any one help me in this regard ?
Prelude> data L a = Cons a (L a) | ...
0
votes
1
answer
84
views
How to check if an equation has numbers with multiple digits
We are making a program to convert an input from infix to postfix. This is my code:
import javax.swing.*;
import java.util.Stack;
public class InfixToPostfix
{
public static int Precedence(char c)...
1
vote
0
answers
121
views
Converting infix to postfix not showing proper symbols
I was trying to write a code to convert infix expression into postfix expression , I have the source code here and when I compile and give the input say 'a+b' it returns 'ab?' as the answer it does ...
-1
votes
1
answer
538
views
Data Structures: Infix to Prefix LinkedList(LL)
My code is able to compile and run, however the process returns -1. I have drawn out various test cases manually and believes it works, so I am not sure which part of my logic is wrong.
I ask the user ...
0
votes
0
answers
1k
views
Infix to postfix conversion using linked list in c
Can anyone please help me with this code? I'm trying to convert from infix to postfix using a linked list. With an array, I can easily solve this, that solution is also similar to this one. But I'm ...
1
vote
0
answers
339
views
How to convert from infix to postfix without using any methods
We are supposed to write a program using the stack class that converts a string from infix to postfix using JOptionPane as the input method. We are supposed to do it all in one big for loop and one ...
0
votes
1
answer
146
views
type mismatch when create a kotlin infix notation to nest a function to another
I am trying to create a infix notation as a extension function of (Int) -> Int function which is used to nest a function to another.
For example:
class Entry {
companion object {
...
0
votes
0
answers
47
views
Better approach for this function that calculates a mathematical expression from a string? [duplicate]
The problematic to resolve:
Given a string that contains a mathematical expression, I need a function on C# language that receives that string and returns its decimal result that respects the ...
0
votes
0
answers
77
views
Segmentation fault in the code to convert infix expression to postfix
#include<iostream>
using namespace std;
struct stackint{
int top;
int size;
int a[50];
void push(int x){
if(top==size-1){
cout<<"stack is full"...
0
votes
1
answer
144
views
Postfix evaluating incorrectly
-2^2 (infix notation) should translate to -2 2 ^ (postfix notation). It does as expected however when evaluating that postfix it evaluates to 4 not -4 which is what is expected.
I'm using Lua and here'...
1
vote
1
answer
924
views
How to use infix notation in Android properly (Kotlin language)?
I have read Kotlin docs as well as the wikipedia links (https://en.wikipedia.org/wiki/Infix_notation#:~:text=Infix%20notation%20is%20the%20notation,plus%20sign%20in%202%20%2B%202), but unfortunately I ...
4
votes
0
answers
82
views
Parameters with infix operator name?
In Haskell, we can use an infix operator as a parameter name, e.g.:
f :: (Int -> Int -> Int) -> Int
f (|+|) = 3 |+| 4
Is it possible to do something similar in Idris 2? I tried the following:...
1
vote
1
answer
98
views
Couldn't match expected type when folding binary trees
data BB a = L | K (BB a) a (BB a) deriving (Show)
foldrpBB :: (a -> b -> b) -> b -> BB a -> b
foldrpBB f b L = b
foldrpBB f b (K l r a) = foldrpBB f (f r (foldrpBB f b a)) l
foldrprBB ...
7
votes
1
answer
294
views
Why is exporting fixity declarations a "bad idea"?
According to David MacQueen in his Reflections on Standard ML report1,
Lexically-scoped infix directives were an ill-advised legacy from Pop-2. They complicate parsing and they do not work well with ...
0
votes
1
answer
279
views
What would this postfix expression be in infix?
First time here, anyone know what this postfix expression would be in infix?
s s * x y z * * sqrt s t - / s t * +
Where sqrt is square rooting.
My current guess is:
(sqrt ((s * s) (x * y * z))) / (s - ...
0
votes
0
answers
500
views
Infix notation to expression tree, recursive method
I'm trying to do a expression tree from a infix string with recursive approach but when Parser threw an nullpointerexception but idk why, so if someone can help me, i will thank u.
Every operator with ...