几年前,我在本科学习期间一直在研究Flex,Bison.但是,我现在不记得了.最近,我听说过ANTLR.
我没有收到错误,请你帮帮我,这里是.l和.y文件.谢谢.
%{
#include "ifanw.tab.h"
extern int yylval;
%}
%%
"=" { return EQ; }
"!=" { return NE; }
"<" { return LT; }
"<=" { return LE; }
">" { return GT; }
">=" { return GE; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return MULT; }
"/" { return DIVIDE; }
")" { return RPAREN; }
"(" { return LPAREN; }
":=" { return ASSIGN; }
";" { return SEMICOLON; }
"IF" …Run Code Online (Sandbox Code Playgroud) 我正在使用bison + flex来解析文件.出错时调用yyerror().如何获取违反规则的行号或字符串,并使用错误消息进行打印?
我正在尝试制作一个Bison解析器来处理UTF-8字符.我不希望解析器实际解释Unicode字符值,但我希望它将UTF-8字符串解析为字节序列.
现在,Bison生成以下代码,这是有问题的:
if (yychar <= YYEOF)
{
yychar = yytoken = YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
Run Code Online (Sandbox Code Playgroud)
问题是UTF-8字符串的许多字节将具有负值,并且Bison将负值解释为EOF,并停止.
有没有解决的办法?
我想尝试使用莎士比亚编程语言,所以我从这里下载并使用Makefile执行cd spl-1.2.1 Make.
spl2c带有几个警告的执行汇编:
scanner.l:600: warning, rule cannot be matched
<stdout>:5808: warning: ‘yyunput’ defined but not used
Run Code Online (Sandbox Code Playgroud)
然后当它试图编译所有的例子时,一切都变得混乱:
../spl/bin/spl2c < fibonacci.spl > fibonacci.c
Warning at line 19: equality expected
Warning at line 28: equality expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 32: comment expected
Warning at line 32: comment expected
Warning at …Run Code Online (Sandbox Code Playgroud) 在我的编程项目中,我想使用flex/bison来解析命令行属性.我的程序被调用如下:
./prog -a "(1, 2, 3)(4, 5)(6, 7, 8)" filename
Run Code Online (Sandbox Code Playgroud)
是否可以使用flex/bison解析此字符串而无需将其写入文件并解析该文件?
我正在研究一个解析json字符串的解析器,我想把它变成一个库.问题是,当我使用ld链接我写的库时,会出现一条错误消息:
main.o: In function `main':
main.c:(.text+0x0): multiple definition of `main'
json-parser.o:/build/buildd/flex-2.5.35/libmain.c:29: first defined here
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题..?谢谢.
是否有开放的解析器?另外,我打算用http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf中的语法规则来编写一个.
谢谢.
在LLVM教程中,有如何编写简单JIT编译器的说明.不幸的是,本教程中的词法分析器和解析器是手动编写的.我在想,这样的解决方案有利于学习目的,但它不适合编写复杂的,生产就绪的编译器.看起来GCC和其他一些"大编译器"都是手写的.但我认为,所有这些解析器生成器在编写自己的编译器时都会有很大的提升(特别是当你独自完成它时,没有团队成员).
是否可以将任何现有的解析器生成器(如Bison/Antlr/Packrat/Elkhound等)与LLVM一起使用来创建JIT编译器?我希望能够使用表达式不断地(不是一次开始)"解析"解析器并在运行时编译它们.
另外我发现了很多关于"最好的,现代的"解析器生成器的问题(比如这个:https://stackoverflow.com/questions/428892/what-parser-generator-do-you-recommend).如果可以使用这些工具来创建LLVM JIT编译器,我会感谢任何额外的提示和推荐,在这种特定情况下哪个工具在性能和灵活性方面是最好的.
如何在 Lex 和 Yacc 中发表评论?
到目前为止,我还没有尝试过 Yacc,但在 Lex 中我已经尝试过/* comment */and // comment,但这些都无法编译。我在 Mac 上,使用内置的 Lex 和 Yacc 编译器(或者可能是 X-Code 编译器,我不知道)。Lex 或 Yacc 或最好两者中注释的正确语法是什么?