我想尝试使用莎士比亚编程语言,所以我从这里下载并使用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) 我正在学习F#,因为我想写一个词法分析器和解析器.我对这种处理有一点经验,但确实需要正确地学习它和F#.
在学习F#的lexing/parsing功能时,学习lex和yacc是否足够?
或者是否存在一些差异,这意味着lex/yacc的代码将无法与fslex和fsyacc一起使用?
我正在研究新的编程语言,但我总是对每个人都使用yaxx/lex来解析代码感到困惑,但事实并非如此.
我的编译器(已经工作)是用C++/STL手动编码的,我不能说它复杂或占用太多时间.它有某种词法分析器和解析器,但它们不是自动生成的.
早些时候,我用同样的方式编写了一个C编译器(不是完整的规范) - 它能够在1遍中编译程序,所有这些反向引用解析和预处理 - 这对于yacc/lex来说绝对是不可能的.
我无法说服自己废弃所有这些,并开始深入研究yaxx/lex - 这可能需要付出相当大的努力才能实现,并且可能会引入一些语法限制.
不使用yacc/lex时有什么我想念的吗?我做恶事吗?
我正在研究一个解析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)
我怎样才能解决这个问题..?谢谢.
当我的标记属于我定义的类型时,yacc似乎不喜欢.
在块中我的grammar(.y)文件的顶部%{ ... %},我包含一个定义以下结构的头文件:
typedef struct _spim_register {
spim_register_type type; /* This is a simple enumeration, already defined */
int number;
} spim_register;
Run Code Online (Sandbox Code Playgroud)
在我的规则列表之前,我有:
%token AREG
...
%union {
struct _spim_register reg;
}
...
%type <reg> register AREG
Run Code Online (Sandbox Code Playgroud)
我明白了
错误:字段'reg'的类型不完整
在%union尝试编译由bison生成的代码时,在子句中的行.在我的%union陈述中,尝试通过写入声明reg spim_register reg;给出错误:
unknown type name ‘spim_register’
Run Code Online (Sandbox Code Playgroud)
看起来有一些特别之处%union { ... },因为我能够在规则的操作中使用头文件中的数据结构.
嗨,我正在学习Lex和yacc.我创建了以下lex程序.
%{
#include <stdio.h>
%}
%%
[0123456789]+ printf("NUMBER\n");
[a-zA-Z][a-zA-Z0-9]* printf("WORD\n");
%%
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下命令运行它:
还尝试了cc lex.yy.c -o example1 -lfl
当我进入上面的第二个命令表单时,我收到错误:
D:\workdir\flexyacc\Test3>gcc lex.yy.c -o Test -lfl
C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lfl
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我试过谷歌搜索这个错误但到目前为止没有运气.由于我是Lex编程的新手,我不知道如何解决这个问题.任何帮助将不胜感激.非常感谢提前.
.NET有一个很好的yacc/bison类型LALR解析器生成器吗?
我有一个应用程序,我已经有一种语法的解析器,我需要为另一个目的添加第二个不同的语法.
是否有可能有多个?
如果是这样,你如何获得另一个切入点?
谢谢
大卫艾伦芬奇
我正在尝试生成一个编译器,所以我可以在之后传递一个.c文件.
我从http://www.quut.com/c/ANSI-C-grammar-y.html下载了YACC和LEX语法,并将它们命名为clexyacc.l和clexyacc.y
在终端上生成它时我做了:
yacc -d clexyacc.y
lex clexyacc.l
Run Code Online (Sandbox Code Playgroud)
一切都很好.当我继续到最后一部分时,我得到了一些错误.
最后一部分是:cc lex.yy.c y.tab.c -oclexyacc.exe
但我得到这些错误:
Run Code Online (Sandbox Code Playgroud)y.tab.c:2261:16: warning: implicit declaration of function 'yylex' is invalid in C99 [-Wimplicit-function-declaration] yychar = YYLEX; ^ y.tab.c:1617:16: note: expanded from macro 'YYLEX' # define YYLEX yylex () ^ y.tab.c:2379:7: warning: implicit declaration of function 'yyerror' is invalid in C99 [-Wimplicit-function-declaration] yyerror (YY_("syntax error")); ^ clexyacc.y:530:6: error: conflicting types for 'yyerror' void yyerror(const char *s) ^ y.tab.c:2379:7: note: previous implicit declaration is here yyerror (YY_("syntax …