yacc

Ignoring errors in yacc/lex

梦想与她 提交于 2019-12-02 09:04:04
I'm new to yacc/lex and I'm working on a parser that was written by someone else. I notice that when an undefined token is found, the parser returns an error and stops. Is there a simple way to just make it ignore completely lines that it cannot parse and just move on to the next one? just add a rule that looks like . { // do nothing } at the bottom of all of your rules, and it will just ignore everything it comes across that doesn't fit any of the previous rules. Edit: if you have multiple states, then a catch-all that works in any state would then look like: <*>. { } 来源: https:/

Make bison reduce to start symbol only if EOF is found

时光怂恿深爱的人放手 提交于 2019-12-02 08:59:02
I am using Bison with Flex. I have the following rule in my Yacc input file: program : PROGRAM m2 declarations m0 block {cout << "Success\n"} ; The problem is that if I have a program that is partially correct, but then there is some "garbage" before EOF, it will reduce according to the previous rule, report "success" and only then report an error. I want to include EOF at the end of the rule above, but then, Flex would have to return EOF when it read <<EOF>> , and how would Bison know when to end the program? Now, I have this in Flex: <<EOF>> {return 0;} Here is an example that would do that:

flex / bison : how can I switch two lexers on same input file

ⅰ亾dé卋堺 提交于 2019-12-02 08:41:24
问题 How can I handover an open file e.g. read by another scanner to the next scanner - and give it to the parser ? 回答1: Flex buffers cannot easily be transferred from one scanner to another. Many details are private to the scanner and would need to be reverse-engineered, with the consequent loss of maintainability. However, it is not difficult to combine two (or more) scanner definitions into a single scanner, provided that the semantic types are compatible. It is simply necessary to give them

BISON + FLEX grammar - why tokens are being concatenated together

那年仲夏 提交于 2019-12-02 07:59:32
I would like to understand why BISON is concatenating two tokens on the following rule stmt: declaration { ... } | assignment { ... } | exp { ... } | ID ';' <-- this rule { ... fprintf(stderr, "\n my id is '%s'", $1); ... if you check the output will get what I mean. I run my parser and I input the characters ab; to the program. According to my bison grammar this should be parsed as an ID followed by a ; . And at some extent it is what happens. However, when I try to use the $1 variable of the rule ID ';' the program outputs ab; to me instead of ab . running the program ab; <-- this my input

解决Qt5 Creator无法切换输入法(fcitx),Ubuntu中不能使用搜狗输入法录入汉字问题

大兔子大兔子 提交于 2019-12-02 06:39:16
本文档2019年1月23日修正,Ubuntu18.10,Qt5.12.0测试通过 本文档2017年6月1日修正,Ubuntu16.04,Qt5.9.0测试通过 2016年6月8日修正,ubuntu 16.04 Qt5.7.0 以及 Qt5.6.1均测试通过 在Qt5.3之前,我发布过解决办法 解决Qt5 Creator无法切换输入法(fcitx),不能录入汉字问题 ,Qt5.4以及Qt5.5,旧办法失效,原因是Qt5.4后对之前Qt5版本不再二进制兼容,libfcitxplatforminputcontextplugin.so 需要编译最新的fcitx-qt5。如果你懒得自己编译,可以下载我编译的 libfcitxplatforminputcontextplugin.so 看fcitx-qt5项目的更新日志,是在1.0.3版本时解决的这个问题,写本篇博客时,我git clone到的是1.0.4版本。 编译fcitx-qt需要cmake,安装cmake命令,如果已经安装,请略过。 sudo apt-get install cmake 安装 fcitx-libs-dev sudo apt-get install fcitx-libs-dev 设置qmake的环境变量: export PATH="/home/lieefu/Qt5.12.0/5.12.0/gcc_64/bin":$PATH

flex / bison : how can I switch two lexers on same input file

独自空忆成欢 提交于 2019-12-02 04:24:36
How can I handover an open file e.g. read by another scanner to the next scanner - and give it to the parser ? Flex buffers cannot easily be transferred from one scanner to another. Many details are private to the scanner and would need to be reverse-engineered, with the consequent loss of maintainability. However, it is not difficult to combine two (or more) scanner definitions into a single scanner, provided that the semantic types are compatible. It is simply necessary to give them different start conditions. Since the start condition can be set even outside of a scanner action, it is

Flex/Lex - How to know if a variable was declared

有些话、适合烂在心里 提交于 2019-12-01 21:17:12
My grammar allows: C → id := E // assign a value/expression to a variable (VAR) C → print(id) // print variables(VAR) values To get it done, my lex file is: [a-z]{ yylval.var_index=get_var_index(yytext); return VAR; } get_var_index returns the index of the variable in the list, if it does not exist then it creates one. It is working! The problem is: Everytime a variable is matched on lex file it creates a index to that variable. I have to report if 'print(a)' is called and 'a' was not declared, and that will never happen since print(a) always creates an index to 'a'.* How can I solve it? Piece

Flex and Yacc - Cannot find - lfl?

旧巷老猫 提交于 2019-12-01 16:21:02
Hi I'm learing Lex and yacc. I created the following lex program. %{ #include <stdio.h> %} %% [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% I'm trying to run it using the following commands: lex example1.l cc lex.yy.c -o example1 -ll also tried cc lex.yy.c -o example1 -lfl When I enter the second command form above, I get error: 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 I tried googling this error but no luck so far. Since I'm new

Flex and Yacc - Cannot find - lfl?

泄露秘密 提交于 2019-12-01 15:14:10
问题 Hi I'm learing Lex and yacc. I created the following lex program. %{ #include <stdio.h> %} %% [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% I'm trying to run it using the following commands: lex example1.l cc lex.yy.c -o example1 -ll also tried cc lex.yy.c -o example1 -lfl When I enter the second command form above, I get error: 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

Thread-safe / reentrant bison + flex

瘦欲@ 提交于 2019-12-01 14:57:00
I would really prefer a working example to any explanation. Whatever I read so far on Bison's documentation site contradicts whatever Flex says. One says to declare yylex as int yylex (yyscan_t yyscanner); another one wants it to be: int yylex(YYSTYPE *lvalp, YYLTYPE *llocp); What I really need is the location information. I'm not sure as of yet if I need YYSTYPE (I don't have a use for this information right now, but maybe in the future I will). Unrelated to the above, and as a bonus, I'd be interesting to know why this infrastructure is so bad. It seems like such a straight-forward thing to