相关疑难解决方法(0)

在没有全局或静态变量的情况下配置Bison和Flex

我在一个小语言/ IDE工作.我需要知道如何配置flex和bison以协同工作,但不使用任何全局或静态变量.我需要传递给我的AST指针.我也需要野牛通过我的AST来弯曲.这是一个线程环境,但我不需要任何线程同步.我需要为每个yyparse()调用一个separete yylineno变量.我读到了%define api.pure,%parse-param和%option reentrant.但我不知道如何让他们一起工作......先提前......

我试过这个:

scanner.l:

%{

#include <iostream>
#include <sstream>
#include "parser.tab.h"
#define YY_DECL extern "C" int yylex(YYSTYPE * lvalp, yyscan_t scanner)
extern void yyerror(yyscan_t scanner, NBloco * bloco, const char *s);

%}

%option noyywrap
%option yylineno
%option reentrant 
%option bison-bridge

%%
//...scanner code
Run Code Online (Sandbox Code Playgroud)

parser.y:

%{
#include <iostream>
#include "AST.h"

#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif

extern "C" int yylex(YYSTYPE * lvalp, yyscan_t scanner);
extern "C" FILE *yyin;
extern int yylineno;
void yyerror(yyscan_t scanner, NBloco * …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading bison flex-lexer

10
推荐指数
1
解决办法
4156
查看次数

用Flex编写重入词法分析器

我是弯曲的新手.我正在尝试用flex编写一个简单的重入词法分析器/扫描器.词法分析器的定义如下.我遇到编译错误,如下所示(yyg问题):

reentrant.l:

/* Definitions */

digit           [0-9]
letter          [a-zA-Z]
alphanum        [a-zA-Z0-9]
identifier      [a-zA-Z_][a-zA-Z0-9_]+
integer         [0-9]+
natural         [0-9]*[1-9][0-9]*
decimal         ([0-9]+\.|\.[0-9]+|[0-9]+\.[0-9]+)

%{
    #include <stdio.h>

    #define ECHO fwrite(yytext, yyleng, 1, yyout)

    int totalNums = 0;
%}

%option reentrant
%option prefix="simpleit_"

%%

^(.*)\r?\n     printf("%d\t%s", yylineno++, yytext);

%%
/* Routines */

int yywrap(yyscan_t yyscanner)
{
    return 1;
}

int main(int argc, char* argv[])
{
    yyscan_t yyscanner;

    if(argc < 2) {
        printf("Usage: %s fileName\n", argv[0]);
        return -1;
    }

    yyin = fopen(argv[1], "rb");

    yylex(yyscanner);

    return 0;
} …
Run Code Online (Sandbox Code Playgroud)

lexical-analysis thread-safety reentrancy flex-lexer

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