我有两个String类型的arraylists,一个操作数和一个操作符
ArrayList<String> operands = new ArrayList<String>();
ArrayList<String> operators = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
它们就像这样填充
operands = { "\"symbol\": \"CHKP%\"", "\"price\": {$gt: 23.72\" };
operators = { "and"};
Run Code Online (Sandbox Code Playgroud)
理想情况下,我会将其转换为一个像这样填充的ArrayList
ArrayList<String> polishNotation = { "and",
"\"symbol\": \"CHKP%\"",
"\"price\": {$gt: 23.72\" };
Run Code Online (Sandbox Code Playgroud)
将波兰表示法硬编码为三个元素很容易,但我有不同数量的运算符和操作数(最多四个操作数和三个运算符).此代码用于将SQL select语句转换为MongoDB.find()语句.任何关于如何以波兰表示法(前缀波兰表示法)实现ArrayList合并的指针都将非常感激.
[编辑2]下面是一个带有3个运算符("like","和","<")和三个操作数('FLIR%',"price","price")的SQL语句的示例,它与MongoDB等效.我认为使用波兰表示法可以帮助我将SQL的查询顺序转换为Mongo排序的查询
在SQL中
SELECT * FROM STOCK WHERE symbol like 'FLIR%' and price > 24.04 and price < 24.39;
Run Code Online (Sandbox Code Playgroud)
在MongoDB中
db.STOCK.find({
"symbol": "FLIR%",
"price": {
"$gt": 24.04,
"$lt": 24.39
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个如下表达式.MIN(MAX(AVG(AVG(4,2),2,3),SUM(1,2)))我已经实现了分流码算法,将中缀转换为反向波兰符号.我用两个参数添加函数MAX,MIN和AVG.但是假设我想要实现变量参数,那么我必须知道每个函数在中缀表达式中有多少个参数.有人能告诉我如何修改分流码算法以包含否.将中缀转换为rpn时每个函数的参数?
通过使用我的意思是它在许多计算器如HP35-中使用
我的猜测(和混淆)是 -
可以问这个问题的另一种方式是后缀表示法优于前缀的优点是什么?
任何人都可以开导我吗?
我正在学习连接语言的基础知识,其最初的想法是函数名称连接与函数组合相同,而不是像Haskell中那样是函数应用程序.
Joy,Forth或Factor是postfix,这意味着基于堆栈,但也有一些前缀连接语言,如Om.
我想知道Haskell变体理论上是否可以通过将组合优先级(现在为9)与函数应用程序优先级(现在为10)进行交换(甚至等于)来进行连接语言.
如果Haskell中的值只是零参数函数,为什么函数应用程序与函数组合不同?,函数应用程序与零参数函数组合相同吗?
是否有可能以简单的方式创建一个解释器或预编译器,它通过定义具有不同优先级的新组合和应用程序运算符将连接语法转换为Haskell语法,并假设没有括号的简单连接是组合?我认为这只是一个语法问题,我错了吗?它会避免许多我们必须在Haskell中使用括号或$运算符的情况.或者它是一个更基本的问题,而不仅仅是语法和优先级?
提示:假设Haskell中的每个函数和运算符都是前缀,我们可以忘记这个关于中缀符号和各种"语法糖"的练习.
haskell operator-precedence concatenative-language polish-notation
有人可以将以下波兰表示法转换为其SQL对应物:
['|', '&', ('is_company','=', True),('parent_id', '=', False),('company_name', '!=', False),('company_name', '!=', '')]
我的猜测是:
is_company = True OR parent_id = False AND company_name <> False AND company_name <> ''
无论我多么努力地理解它,我都无法得到这种符号的概念.请帮忙.
UPDATE
我试图将上述表示法扩展为:
((is_company = True AND parent_id = False) OR company_name <> False) AND company_name <> '' AND customer_type_id <> False
我有这个功能:
def req_splitter(req_string):
req = {}
if " AND " in req_string:
cond = "AND"
req_splitted = req_string.split(" AND ")
elif " OR " in req_string:
cond = "OR"
req_splitted = req_string.split(" OR ")
else:
cond = "AND"
req_splitted = [req_string]
if len(req_splitted) > 1:
for sub_req in req_splitted:
sub_req_splitted = req_splitter(sub_req)
req[cond] = list()#new_req
req[cond].append(sub_req_splitted)
else:
req[cond] = req_splitted
return req
Run Code Online (Sandbox Code Playgroud)
它旨在将像这样的字符串转换为json逻辑条件:
Barracks AND Tech Lab
Lair OR Hive
Hatchery OR Lair OR Hive
Cybernetics Core AND Gateway OR …Run Code Online (Sandbox Code Playgroud) 当我输入字符串运算符时,无论是加法(+),减法( - ),乘法(*),除法(/)还是模块(%),即使输入有效输入,它仍会进入while循环.我不知道问题是什么,因为while循环工作正常,我必须为变量num2输入一个int值.
import java.util.Scanner;
public class PolishNotationCalc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1;
int num2;
String operator;
System.out.println("Polish notation calculator");
System.out.print("Please enter an operation(+, -, *, /, %) ");
operator = input.nextLine();
while (!operator.equals("+") || !operator.equals("-") || !operator.equals("*") || !operator.equals("/") || !operator.equals("%")) {
System.out.println("Please enter a valid operation ");
operator = input.nextLine();
if (operator.equals("+") || operator.equals("-") || operator.equals("*") || operator.equals("/") || operator.equals("%"))
break;
}
System.out.print("");
System.out.print("Please enter the first number "); …Run Code Online (Sandbox Code Playgroud) algorithm ×2
java ×2
python ×2
arraylist ×1
calculator ×1
haskell ×1
if-statement ×1
json ×1
logic ×1
mongodb ×1
odoo ×1
odoo-10 ×1
recursion ×1
while-loop ×1
xml ×1