interpreter 相关问题

解释器是执行(即执行)用编程语言编写的指令的程序。标签[翻译]应适用于有关口译员编程的问题或有关口译员详细内部工作的问题。使用[interpreter-pattern](可能带有此标签)来解决有关Gang of Four设计模式的问题。

Vs 代码中的 Pylance(ReportMissingImport)

在 venv 中安装 numpy 和 matplotlib 后,我在 vs code 上遇到 python 问题,并且环境已激活,当我在 cmd 中运行 pip list 时列出了所有依赖项, 我已经创建了...

回答 1 投票 0

如何在网站上嵌入Python解释器

我正在尝试建立一个教育编码网站,类似于Codecademy,但坦白说我不知道应该采取什么步骤。我能否指出正确的方向,甚至包括

回答 5 投票 0

ModuleNotFoundError:没有名为 openai 的模块

导入请求 从 bs4 导入 BeautifulSoup 导入openai #将nuclear.txt的每一行写入一个列表 将 open('nuclear.txt', 'r') 作为 f: 行= f.readlines() #删除换行符...

回答 5 投票 0

Haskell [解析错误,可能是缩进不正确或括号不匹配)解析器

我正在尝试按照本文在 Haskell 中创建一个解析器。我使用了 Pragma {-# Language NoImplicitPrelude #-}。这是为了让我能够毫无困惑地开发 Monad 类...

回答 1 投票 0

VSCode 输出引用不同的 Python 版本到解释器版本

我正在尝试在 Python 3.9.18 上运行代码,我从虚拟环境中选择了它作为我选择的解释器。我想我安装了很多不同版本的Python,因为当我运行时......

回答 1 投票 0

如何在 Jupyter Notebook 中使用我的 PyCharm Python 解释器?

是否可以在 Jupyter Notebook 中使用我在 PyCharm 中使用的 Python 解释器?我不想创建一个全新的虚拟环境,因为我已经尝试过并遇到了&q...

回答 2 投票 0

如何对这款口译员进行分类

目前,我正在开发 DSL 的解释器(?)。但我很难找到如何准确地对其进行分类。我什至不确定你是否可以称其为口译员。 我尝试过搜索abo...

回答 1 投票 0

PyCharm:如何完全删除旧的[无效]解释器

我整天都在玩PyCharm,现在我已经从文件系统中删除了所有项目,尽管如此,我仍然得到旧的解释器[无效],我无法删除,在某些地方提到...

回答 2 投票 0

如何让解释器存储变量

我一直在尝试制作一种编程语言,但我不知道如何让我的解释器存储和调用变量 #包括 #包括 #包括 我一直在尝试制作一种小编程语言,但我不知道如何让我的解释器存储和调用变量 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_VARIABLES 10 // Structure to store variables struct Variable { char name[50]; char value[256]; }; // Array to store variables struct Variable variables[MAX_VARIABLES]; int variableCount = 0; // Function to find a variable by name struct Variable* findVariable(const char* name) { for (int i = 0; i < variableCount; ++i) { if (strcmp(variables[i].name, name) == 0) { return &variables[i]; } } return NULL; // Variable not found } // Function to interpret commands void interpretCommand(const char* command) { if (strncmp(command, "console:write->", 15) == 0) { // Extract the message within double quotes const char* messageStart = strchr(command, '"'); const char* messageEnd = strrchr(command, '"'); if (messageStart != NULL && messageEnd != NULL && messageStart < messageEnd) { // Print the message, replacing variables if present for (const char* p = messageStart + 1; p < messageEnd; ++p) { if (*p == '*') { ++p; // Move past '*' const char* varStart = p; while (*p != '*' && p < messageEnd) { ++p; } char varName[50]; strncpy(varName, varStart, p - varStart); varName[p - varStart] = '\0'; struct Variable* variable = findVariable(varName); if (variable != NULL) { printf("%s", variable->value); } else { printf("Undefined variable: %s", varName); } } else { putchar(*p); } } putchar('\n'); } else { printf("Invalid message format\n"); } } else if (strncmp(command, "console:read->", 14) == 0) { // Extract the prompt within double quotes const char* promptStart = strchr(command, '"'); const char* promptEnd = strrchr(command, '"'); if (promptStart != NULL && promptEnd != NULL && promptStart < promptEnd) { // Print the prompt and read user input printf("%.*s", (int)(promptEnd - promptStart - 1), promptStart + 1); // Read user input char userInput[256]; // Adjust size as needed fgets(userInput, sizeof(userInput), stdin); } else { printf("Invalid prompt format\n"); } } else { // Check if the command starts with "variableName->" char* arrow = strstr(command, "->"); if (arrow != NULL) { *arrow = '\0'; // Separate variable name and value // Find or create a variable with the given name struct Variable* variable = findVariable(command); if (variable == NULL) { if (variableCount < MAX_VARIABLES) { strcpy(variables[variableCount].name, command); variable = &variables[variableCount++]; } else { printf("Maximum number of variables reached\n"); return; } } // Copy the value to the variable strcpy(variable->value, arrow + 2); } else { printf("Unknown command\n"); } } } int main() { // Open the file FILE* file = fopen("King.roar", "r"); if (file == NULL) { perror("Error opening file"); return 1; } char line[256]; // Assuming a maximum line length of 255 characters // Read and interpret each line from the file while (fgets(line, sizeof(line), file) != NULL) { // Remove newline character if present size_t len = strlen(line); if (len > 0 && line[len - 1] == '\n') { line[len - 1] = '\0'; } // Interpret the command interpretCommand(line); } // Close the file fclose(file); return 0; } 这是我存储在 King.roar 中的示例代码 console:read->"Enter your name: "->name console:read->"Enter your age: "->age console:write->"Hello *name*!" console:write->"You are *age* years old!" 由于某种原因,我只得到未定义的变量,我不知道数据是否未存储,或者调用不起作用 我尝试在互联网上查找,但没有找到任何相关内容。感谢您的帮助! (免责声明:我没有尝试过)。 根据您的代码,您正在通过检查来检查变量 (变量名)-> (寻找 -> 并在箭头处将名字剪掉)。但是您的示例代码使用 ->(变量名) (->name, ->age),因此在箭头处截断将导致使用空字符串作为变量名称。尝试打印出您最终用于存储的变量的名称,并用 * 和 * 包围 - 我认为您最终会得到 **!

回答 1 投票 0

V8的ignition是编译器还是逐行解释器?

我尝试查看一些 V8 博客来理解这一点,但它们似乎可以互换使用编译器和解释器。我想知道ignition是否转换/编译为字节码然后它

回答 1 投票 0

解释器解析 get/put 方法仅解析对字段的第一次访问

我正在尝试记录对我正在构建的分析工具的字段/静态变量的每次访问,到目前为止我已经找到了这个解释器 rt 函数, void InterpreterRuntime::resolve_get_put(JavaThre...

回答 1 投票 0

如何用Python构建一个Brainfuck解释器?

我一直在研究 BF 解释器,试图确保它不使用外部库,并且在单个函数中工作。 我遇到的问题是有些程序运行得很好,而且......

回答 2 投票 0

编译器和解释器在作用域方面有什么区别?

我们说编译器的作用域是静态的,而解释器的作用域是动态的,那么这里“作用域”这个词的意义是什么?为什么在编译器的情况下它是静态的,而在

回答 2 投票 0

为什么在不使用任何`torch`模块的情况下`import torch`需要长达5秒的时间?

我意识到,每当我在任何 python 文件中导入 torch 时,导入都会滞后,即需要长达 5 或 6 秒的时间,即使我只打印 hello world 并且不使用任何模块...

回答 1 投票 0

变量存储 EQUALS 而不是字符串 |基于Python的解释器

我一直在用Python制作一个解释器,但遇到了一个问题,它识别字符串、变量、数字和表达式。在测试 .lang 文件时,我注意到它输出了 {'$var': 'EQUA...

回答 1 投票 0

Python - 语法错误和缩进错误[重复]

我知道python是一种解释器语言,这意味着它在运行时解释代码,那么为什么该代码会给我IndentationError呢? 定义函数(x): 如果x: 它检查所有...

回答 5 投票 0

Ruby 方法的测量和基准时间

我如何测量 Ruby 中某个方法以及该方法中各个语句所花费的时间。如果您看到下面的方法,我想测量该方法所花费的总时间以及所花费的时间...

回答 6 投票 0

有没有任何应用程序或网站可以识别我的Python语言错误并为我提供相同的替代正确答案?

错误! 文件“”,第 25 行 除害提醒者(自我): ^ 语法错误:语法无效 在解释时,我在第 25 行遇到错误: 错误! 文件“”,第 25 行 除害提醒者(自我): ^ 输入...

回答 1 投票 0

不知道是什么导致了我的解释器(python)中的这个错误

在python中制作语言解释器但遇到了这个错误,它只显示2个字符串然后显示错误。这是为什么? 在打印所有 NUM 和 EXPR 之前它工作正常,问题似乎...

回答 1 投票 0

Brainfuck JavaScript 编译器

我用javascript编写了一个brainfuck编译器,它与以下代码一起工作得很好: ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.++++ ++...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.