- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用可重入 lex 和 yacc 编写一个简单的计算器应用程序。在这里我希望创建两个线程(解析器)来解析输入文件中提供的输入。输入文件中要解析的行被分成两个线程..
我的简单计算器 lex 代码是
%option reentrant bison-bridge
%option noyywrap
%{
#include<stdio.h>
void yyerror(char *);
#include "y.tab.h"
%}
%%
[0-9]+ {
yylval=atoi(yytext);
return INTEGER;
}
[-+\n] return *yytext;
[ \t] ;/* Skip whitespaces*/
. ;
%%
我的简单计算器(可重入)的 yacc 文件是
%pure-parser
%lex-param {void * scanner}
%parse-param {void * scanner}
%{
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include <stdlib.h>
int f[2];
pthread_mutex_t lock;
int cnt=0;
void* scanfunc(void * );
%}
%token INTEGER
%%
program: program expr '\n' {printf("%d\n", $2);}
|
;
expr: INTEGER {$$=$1;}
|expr '+' expr {$$=$1+$3;}
|expr '-' expr {$$=$1-$3;}
;
%%
void yyerror(char *s){
fprintf(stderr,"%s\n",s);
}
int main(int argc, char *argv[]){
pthread_t threads[2];
int n=2,i;//Number of threads to be created
//set_file_ptr();
if(argc!=2){
printf("Insufficient nos. of arguments\n");
exit(0);
}
for(i=0;i<n;i++){
f[i]=open(argv[1],O_RDONLY);
lseek(f[i],i*30,SEEK_SET);
}
printf("File pointer set\n");
pthread_mutex_init(&lock,NULL);
for(i=0;i<n;i++){
pthread_create(&threads[i], NULL, (void *)scanfunc, (void *)&i);
}
//join all threads
for(i=0;i<n;i++){
pthread_join(threads[i],NULL);
}
pthread_mutex_destroy(&lock);
//yyparse();
return 0;
}
void* scanfunc(void * i)
{
void * scanner;
// printf("Value of i is %d\n",*(int *)i);
printf("Starting thread %d...\n", *(int *)i);
yylex_init(&scanner);
printf("Done scanner init\n");
pthread_mutex_lock(&lock);
printf("Thread with id %d obtained lock\n",cnt);
yyset_in(f[cnt],scanner);
cnt++;
pthread_mutex_unlock(&lock);
yyparse(scanner);
yylex_destroy(scanner);
}
我的输入文件是
12+12
14-12
23-11
12-12
23-45
67+45
11+23
45-12
67-12
90-34
56-56
90-45
当我编译并运行这个程序时,我得到以下输出
File pointer set
Starting thread 0...
Starting thread 0...
Done scanner init
Thread with id 0 obtained lock
Done scanner init
Thread with id 1 obtained lock
Segmentation fault (core dumped)
当我使用 gdb 调试这个程序时,它说程序接收到信号 SIGSEGV,下面一行出现段错误。
yyparse(scanner);
我不知道如何调试这个程序。在这方面的帮助表示赞赏。谢谢
最佳答案
解决了 Warning : assignment makes pointer from integer without a cast yylval=atoi(yytext); 的问题
引用Making bison/flex parser reentrant with integral YYSTYPE发布以了解我必须对代码进行以下更改才能消除警告。
*yylval=atoi(yytex)
谢谢
关于bison - 警告 : assignment makes pointer from integer without a cast yylval=atoi(yytext);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35459610/
我正在尝试执行 JavaPairRDD 和 JavaPairRDD 的 leftOuterJoin> 并且函数签名返回类型是 JavaPairRDD>>> 这里可选的是 com.google.comm
我正在尝试按元素的频率对元素进行排序 import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt
这个问题已经有答案了: Is List a subclass of List? Why are Java generics not implicitly polymorphic? (19 个回答) 已
编辑:问题已解决:请参阅 Karim SNOUSSI 的答案和我在下面的评论。 这是我在堆栈溢出时遇到的第一个问题,所以我可能不会一开始就把所有事情都做对。对此感到抱歉。此外,我对 Java 和一般
#include #include using namespace std; class Integer { public: int i; Integer (int ll
我不明白: ArrayList list = new ArrayList(); Collection list1 = new ArrayList(); 类 ArrayList扩展实现接口(interf
我编写了:。它成功了。我不知道为什么?
我编写了:。它成功了。我不知道为什么
我编写了:。它成功了。我不知道为什么?
Collectors.counting()返回 long此方法中每个键的值: private static Map countDuplicates(HashSet cards) { retur
我正在尝试通过搜索旧元素并将其替换为新元素来更新节点的元素。但是有一个我不明白的错误。是什么导致我的代码出现该错误,我该如何解决?错误; The method update(Integer, Inte
我有一个称为 client 的表,其中有一列称为created_time ,所以实际上我想绘制一个 map ,以便我可以知道在哪一年和哪一个月添加了多少客户?现在的要求是假设在 2018 年 11 月
这个问题已经有答案了: Is Java "pass-by-reference" or "pass-by-value"? (91 个回答) 已关闭 8 年前。 我对 ArrayList Collecti
我意识到下面的代码是正确的 Integer.MIN_VALUE == -Integer.MIN_VALUE == Math.abs(Integer.MIN_VALUE) 这是因为当我们取反-21474
我有以下类 AccountWebappGridRow,它扩展了 AccountGridRow: public class AccountWebappGridRow extends AccountGri
我正在学习 Haskell 并看到了函数组合。 尝试复合 map和 foldl mapd = (map.foldl) 比 test = (mapd (\x y -> x + y ) [1,2,3,4]
我有两个相同大小的数组和两个方法。 public class Client { private static int[] ints; private static final int
我喜欢 Java 8 中的 Streams 概念。现在我想借助 Java Streams 将 Java 中的 Map 转换为排序列表。我只想显示列表而不将其存储在任何地方。我希望在结果列表中有这个输出
我有一个数据库表,其中包含电视节目类型列表和关联的 ARGB 颜色值,用于在显示电视指南时突出显示 Android ListView 中的电视节目。流派表看起来像这样... id genre
我有一个 Integer 类,它应该模拟一个整数 mod n。因此,它具有如下构造函数: Integer::Integer(int x) : m(x), n(0) { } Integer::I
我是一名优秀的程序员,十分优秀!