lex 相关问题

Lex是一个生成词法分析器(“扫描仪”或“词法分析器”)的计算机程序。 Lex通常与yacc解析器生成器一起使用。有关Amazon Lex的问题,请使用标签amazon-lex。

为什么 lex 中定义的 main 函数被 cc 报告为重复符号?

我正在运行“Lex & Yacc”(John R. Levine、Tony Mason 和 Doug Brown)中的示例: $ 猫 ch2-04.l %{ 无符号详细; 字符*程序名; %} %% -h ...

回答 1 投票 0

如何用Jflex在Bison中表达语法规则

我一直在尝试制作一个从词法分析器(jflex)获取标记的解析器,并且我使用 Java 和 bison 作为解析器。这是到目前为止我的解析器代码: %define api.prefix {示例} %定义API。

回答 1 投票 0

如何在 yacc 中合并 ++ 运算符

在经典的 Kernighan & Pike 书籍(UNIX 编程环境)的第 8 章中,将 hoc1 作为使用 yacc 的简单计算器的示例进行介绍。 本书建议改进源代码...

回答 1 投票 0

如何识别与模式不匹配的数据

所以我使用匹配器类并使用它来识别我在枚举中定义的标记。 公共静态枚举TokenType { // 接受的标记的定义 IF(“如果”),WHILE(“同时”),...

回答 1 投票 0

如何在 Windows 命令行上运行/编译 lex 程序

我在这里看到过类似的问题。这个在 Linux 上工作得很好,但在 Windows 上就不行了。

lex
回答 2 投票 0

lex.yy.c 未与外部函数链接

我正在编写一个 SQL 解析器。 SQLSelectParser.l 是使用 lex 编译器成功生成 lex.yy.c 文件的 lex 文件。在 SQLSelectParser.l 文件中,我调用 Ast.h/c 中定义的外部函数...

回答 1 投票 0

解决解析带有可选参数的AgeSQL子句时的reduce/reduce冲突

我正在开发一个项目,以在 Postgres psql 上添加对 Cypher 子句的支持。我正在尝试提高解析器性能,解决规则之间的冲突。我创建了一个最小的示例

回答 1 投票 0

在 Lex 和 Yacc 之间传递指针

我的 .l 文件中有正则表达式,用于获取变量名。我通过一个函数运行该名称以获取它的指针,然后尝试返回该指针。在 lex 和 yacc 之间的转换中,

回答 0 投票 0

Flex中yylex()为什么不跳出调用它的函数?

yylex()不会看到EOF,所以不会跳出调用它的函数。 我是词法分析的新手,正在尝试为给定的语法制作分析器。我已经准备好了一切和语法......

回答 0 投票 0

如何解决无法识别的规则和致命的解析错误

我对 lex 很陌生,并尝试制作扫描仪。这是我的代码: 定义与规则部分 标识符 ([A-Za-z][0-9A-Za-z]*) 数字 ([0-9]) 整数 ...

回答 1 投票 0

In function ‘int yylex()’: not declared in this scope errors

这是定义部分。 标识符 ([A-Za-z][0-9A-Za-z]*) 数字 ([0-9]) 整数({digit}+) 浮动 ({整数}"."[0-9]+)

回答 0 投票 0

Yacc 文件中字符串库的使用

我正在尝试使用 lax 和 Yacc 编写编译器。我首先通过添加任何关联的操作来定义标记和语法树,但是当我编译它时,我遇到了一些错误。 词法分析器: %{ #包括...

回答 2 投票 0

Strtok 无法正常读取多行字符串

所以,我正在使用词法分析器,在所有 flex 恶作剧之后我得到了这个文本: ISEP 1252“地址” “Name1”1253“信息” “名称 2”1254“样板 1&q...

c lex
回答 1 投票 0

yacc 的输出有延迟

我在 bas.l 和 bas.y 中有以下 lex 和 yacc 代码。我正在尝试构建一个仅包含加法 (+)、减法 (-)、乘法 (*) 和除法 (/) 的简单计算器。 我想要它...

回答 1 投票 0

'int'之前的预期不合格ID

我在任何声明中都遇到了这个错误,比如 $$ = 新向量 例如: parser.y:109:29: 错误:'int' 之前应有不合格的 id 109 | stmts : stmt TSEMIC {$$ = 新向量 我在任何声明中都遇到了这个错误 $$ = new vector<int> 如: parser.y:109:29: error: expected unqualified-id before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ^~~ parser.y:109:29: error: expected ‘)’ before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ~ ^~~ | ) parser.y:109:61: error: expected unqualified-id before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ^ parser.y:109:61: error: expected ‘)’ before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | 编译后找不到原因,这里是 .y 文件,只有语法部分会产生错误。 %define parse.error verbose %{ #include <stdio.h> #include <iostream> #include <vector> #include <string> using namespace std; extern int yylex(); extern int yylineno; extern char *yytext; extern int yyerrornum; void yyerror (const char *msg) { cout << "line " << yylineno <<": " << msg << " at token " << yytext << endl ; yyerrornum++; } #include "Codigo.hpp" #include "Exp.hpp" expresionstruct makecomparison(std::string &s1, std::string &s2, std::string &s3) ; expresionstruct makearithmetic(std::string &s1, std::string &s2, std::string &s3) ; // Añado la declaración de la función unir. Si la hacéis diferente, debéis cambiar esta declaración. vector<int> unir(vector<int> lis1, vector<int> lis2); Codigo codigo; %} /* qué atributos tienen los símbolos */ %union { string *str ; vector<string> *list ; expresionstruct *expr ; int number ; vector<int> *numlist; } /* declaración de tokens. Esto debe coincidir con tokens.l */ %token <str> TIDENTIFIER TINTEGER TDOUBLE %token <str> TCEQ TCNE TCLT TCLE TCGT TCGE TEQUAL %token <str> TLPAREN TRPAREN TLBRACE TRBRACE TCOMMA TDOT %token <str> TPLUS TMINUS TMUL TDIV %token <str> TCOLON TSEMIC TASSIG %token <str> RPROGRAM RIS RBEGIN RENDPROGRAM RVAR RINTEGER RFLOAT RENDPROCEDURE RPROCEDURE RIN ROUT RIF RTHEN RELSE RENDIF RGET RPUT_LINE RDO RWHILE RENDWHILE REXIT /* declaración de símbolos no terminales con atributos */ %type <str> ident %type <str> numeric %type <expr> expr %type <number> M %type <numlist> N %type <int> stmt %type <int> stmts //Falta declarar stmt stmts %left TASSIG %left TCEQ TCNE TCLT TCLE TCGT TCGE TEQUAL %left TPLUS TMINUS %left TMUL TDIV %start program %% program : RPROGRAM { codigo.anadirInstruccion("prog" ) ;} ident RIS decls RBEGIN stmts RENDPROGRAM TSEMIC { codigo.anadirInstruccion("halt"); codigo.escribir() ; } ; decls : RVAR list TCOLON type TSEMIC decls |%empty ; type : RFLOAT | RINTEGER ; list : ident | list TCOMMA ident ; stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | stmts stmt TSEMIC {$$ = new vector<int>; *$$ = unir($1,$2);} ; vector<int> unir(vector<int> lis1, vector<int> lis2){ vector<int> res; res = lis1; res.insert(res.end(), lis2.begin(), lis2.end()); return res; } 这是 .cpp 部分: #include "Codigo.hpp" using namespace std; /****************/ /* Constructora */ /****************/ Codigo::Codigo() { siguienteId = 1; } /***********/ /* nuevoId */ /***********/ string Codigo::nuevoId() { string nId("__t"); nId += to_string(siguienteId++); return nId; } /*********************/ /* anadirInstruccion */ /*********************/ void Codigo::anadirInstruccion(const string &instruccion) { string cadena; cadena = to_string(obtenRef()) + ": " + instruccion; instrucciones.push_back(cadena); } /***********************/ /* anadirDeclaraciones */ /***********************/ void Codigo::anadirDeclaraciones(const vector<string> &idNombres, const string &tipoNombre) { vector<string>::const_iterator iter; for (iter=idNombres.begin(); iter!=idNombres.end(); iter++) { anadirInstruccion(tipoNombre + " " + *iter ); } } /*********************/ /* anadirParametros */ /*********************/ void Codigo::anadirParametros(const vector<string> &idNombres, const string &tipoNombre) { vector<string>::const_iterator iter; for (iter=idNombres.begin(); iter!=idNombres.end(); iter++) { anadirInstruccion("param_" + tipoNombre + " " + *iter ); } } /**************************/ /* completarInstrucciones */ /**************************/ void Codigo::completarInstrucciones(vector<int> &numInstrucciones, const int valor) { string referencia = " " + to_string(valor) ; vector<int>::iterator iter; for (iter = numInstrucciones.begin(); iter != numInstrucciones.end(); iter++) { instrucciones[*iter-1].append(referencia); } } /************/ /* escribir */ /************/ void Codigo::escribir() const { vector<string>::const_iterator iter; for (iter = instrucciones.begin(); iter != instrucciones.end(); iter++) { cout << *iter << " ;" << endl; } } /************/ /* obtenRef */ /************/ int Codigo::obtenRef() const { return instrucciones.size() + 1; } 还有.hpp #ifndef CODIGO_HPP_ #define CODIGO_HPP_ #include <iostream> #include <sstream> #include <fstream> #include <set> #include <vector> /* Estructura de datos para el código generado. El código, en vez de escribirlo directamente, * se guarda en esta estructura y, al final, se escribirán en un fichero. */ class Codigo { private: /**************************/ /* REPRESENTACION INTERNA */ /**************************/ /* Instrucciones que forman el código. */ std::vector<std::string> instrucciones; /* Clave para generar identificaciones nuevos. Cada vez que se crea un idse incrementa. */ int siguienteId; public: /************************************/ /* METODOS PARA GESTIONAR EL CODIGO */ /************************************/ /* Constructora */ Codigo(); /* Crea un nuevo identificador del tipo "__t1, __t2, ...", siempre diferente. */ std::string nuevoId() ; /* Añade una nueva instrucción a la estructura. */ void anadirInstruccion(const std::string &instruccion); /* Dada una lista de variables y su tipo, crea y añade las instrucciones de declaración */ void anadirDeclaraciones(const std::vector<std::string> &idNombres, const std::string &tipoNombre); /* Dada una lista de parámetros y su tipo, crea y añade las instrucciones de declaración */ void anadirParametros(const std::vector<std::string> &idNombres, const std::string &tipoNombre) ; /* Añade a las instrucciones que se especifican la referencia que les falta. * Por ejemplo: "goto" => "goto 20;" */ void completarInstrucciones(std::vector<int> &numInstrucciones, const int valor); /* Escribe las instrucciones acumuladas en la estructura en el fichero de salida. */ void escribir() const; /* Devuelve el número de la siguiente instrucción. */ int obtenRef() const; }; #endif /* CODIGO_HPP_ */ 所有定义都在这段代码中,令牌、函数定义在其他档案中,在那里找不到任何问题,我猜是一些错误的声明,但这是我第一次在使用相同的声明编译代码后得到这个错误没有出现这个错误。 因为我是新用户,我不能写评论。 但是,最后一个语法规则和附加代码之间缺少%% 应该是这样的: stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | stmts stmt TSEMIC {$$ = new vector<int>; *$$ = unir($1,$2);} ; %% vector<int> unir(vector<int> lis1, vector<int> lis2){ vector<int> res; res = lis1; res.insert(res.end(), lis2.begin(), lis2.end()); return res; }

回答 1 投票 0

How to parse a function with ply in python?

我试图在 python 中使用 PLY 解析自定义编程语言,我有点困惑 所以例如,我想解析 创建时: modifyProp 相对宽度 => 11 modifyProp 高度 =>...

回答 1 投票 0

Bison 和 Flex 在编译和执行过程中的语法问题

我目前正在从事一个项目,该项目包括使用 Bison 和 Flex 解析代表机票的文本文件的内容。我创建了两个文件,ticket.y 和 ticket.l,来定义 g...

回答 1 投票 0

How to implement lex web ui chatbot to iframe by using snippet

我创建了 lex-web-ui 聊天机器人并与 cloudforamtion 集成。 聊天机器人在 WebAppUrl 中运行良好:[https://dynvpe5vhgxa5.cloudfront.net/iframe-snippet.html][1] 我试着在我的 ...

回答 0 投票 0

如何从 Visual Studio Code 访问 flex 和 bison?

我目前正在从事一个编程语言项目,我希望能够编写一个 lex 文件(example.l)我在我的计算机上使用 Windows,所以我安装了 WSL,默认情况下,Ubuntu。 我也安装...

回答 0 投票 0

规则在 Flex (LEX) 中不匹配

我有以下匹配时间的正则表达式:(1[012]|0\d):[0-5]\d[ap]\.m\。以 12 小时的格式。 我在这个网站上测试了它并确保它有效。 但它在我的 lex 文件中不起作用: %{ #定义

回答 0 投票 0

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