小编gni*_*moo的帖子

使用SDL2渲染平铺地图的最快方法

我正在寻找一种非常快速的方法来渲染带有SDL2三层的平铺地图.我正在使用SDL_RenderCopy,但它很慢......

c++ sdl-2

6
推荐指数
1
解决办法
3900
查看次数

Flex/Bison:令牌管理不好?

我的词法分析器和解析器中存在问题.

首先,在我的词法分析器中,我有这样一句话:

"if"    beginScope(stOTHER); return IF;
Run Code Online (Sandbox Code Playgroud)

在我的解析器中:

stmt: IF '(' exp ')' stmts
...
stmts: stmt
       | '{' stmt_list '}'
       | '{' '}'
Run Code Online (Sandbox Code Playgroud)

在这样的代码中:

if(sth) {
    dosth;
}

if(other) {
    doothersth;
}
Run Code Online (Sandbox Code Playgroud)

beginScope将被调用两次,因为(我认为)Bison不知道if语句的结尾在哪里,所以当它找到IF令牌时,他将其作为if语句的结尾,并再次读取它开始另一个if声明......

请帮我...

c++ parsing lex bison flex-lexer

5
推荐指数
1
解决办法
278
查看次数

只获得C/C++中的简单数字

我有这样的功能stoi:

static int *stoi(const char *c) {
    int *r = new int[2];
    r[1] = sscanf(c, "%d", &r[0]);
    return r;
}
Run Code Online (Sandbox Code Playgroud)

c = "a5"例如,当我举出时,它不起作用.

当我付出时c = "543336535",它有效.

但是当我给c = "45sdfff-sdbsdf esg5sq4f"它它将返回时r[0] = 45,我不希望这样,因为...之后有一些非数字字符45...

我只希望我的函数读取一个只有数字的字符串.

c stdio

3
推荐指数
1
解决办法
281
查看次数

标签 统计

c++ ×2

bison ×1

c ×1

flex-lexer ×1

lex ×1

parsing ×1

sdl-2 ×1

stdio ×1