flex-lexer

Using $x to grab string from rule

余生颓废 提交于 2020-01-06 04:53:09
问题 I'm trying to do something like this in Bison... loop_for: FOR var_name COLONEQUALS expression TO {printf("%s<=", $2);} expression STEP {printf("%s+=", $2);} expression {printf(")\n");} Code ENDFOR What I'm trying to do is convert a for statement from the fake language's syntax to C's. However, the $2 I've used to grab var_name doesn't seem to work as the program crashes when it reaches there. Is $x supposed to work only for integers? I even tried adding a union and using char* for a new type

Flex not counting lines properly on multiline comments

和自甴很熟 提交于 2020-01-05 09:12:18
问题 I`m using the above regex to identify multiline comments in Flex: [/][*][^*]*[*]+([^*/][^*]*[*]+)*[/] { /* DO NOTHING */ } But seems to me that flex/bison is not returning properly the line counter. For example: Input: 1 ___bqmu7ftc 2 // _qXnFEgQL9Zsyn8Ohtx7zhToLK68xbu3XRrOvRi 3 /* "{ output 6 = <=W if u7 do nN)T!=$||JN,a9vR)7" 4 -758939 5 -31943.6165480 6 // "RND" 7 '_' 8 */ 9 [br _int] Output: 1 TK_IDENT [___bqmu7ftc] 4 [ 4 TK_IDENT [br] 4 TK_IDENT [_int] 4 ] The line should be 9 instead of

gcc giving error on printf while compiling lex output

倾然丶 夕夏残阳落幕 提交于 2020-01-05 08:19:12
问题 For the example.l lex file I get the error below. If I comment out the printf it goes away. I though that the top section of the lex specification could contain any arbitrary C code between the %{ and %} . I need to be able to print some output before lex matches anything. What is wrong with what I have done and how do I fix it? $ cat example.l %{ #include <stdio.h> printf("foobar\n"); %} %% . ECHO; $ lex example.l $ gcc -g -L/usr/lib/flex-2.5.4a -lfl -o example lex.yy.c example.l:3: error:

Problem with using a generated file from flex

℡╲_俬逩灬. 提交于 2020-01-05 03:18:22
问题 I am trying to setup a project that uses flex (fast lex, not the adobe one). I am running on Ubuntu and I installed flex via the apt-get method. I have googled the compile error and I have either found people who just create their own patches around it or a lot of forums where people ask and nobody answers. This is my .ll file %option c++ %% %% It generates a lex.yy.cc file which I include in my main file. #include "lex.yy.cc" int main () { return 0; } The error I get are a lot of "multiple

Problem with using a generated file from flex

别来无恙 提交于 2020-01-05 03:18:21
问题 I am trying to setup a project that uses flex (fast lex, not the adobe one). I am running on Ubuntu and I installed flex via the apt-get method. I have googled the compile error and I have either found people who just create their own patches around it or a lot of forums where people ask and nobody answers. This is my .ll file %option c++ %% %% It generates a lex.yy.cc file which I include in my main file. #include "lex.yy.cc" int main () { return 0; } The error I get are a lot of "multiple

Flex reentrant with start conditions

人盡茶涼 提交于 2020-01-04 09:18:27
问题 I am trying to make a reentrant scanner that relies on start conditions. I was following along something similar to this guys question: Writing re-entrant lexer with Flex And as the one poster mentioned, the scanner will work if you explicitly create the yyscan_t and pass it as an extra argument. However, I still get the yyg undeclared error message when using BEGIN <sc> , etc to manipulate the start condition. Is this a bug? Should I explicity use the yy_push_state and yy_pop_state state

How to integrate flex and bison with Qt project?

删除回忆录丶 提交于 2020-01-02 07:30:33
问题 I am making a GUI program using Qt4, under git source control (Github page). Small part of project requires scanning and parsing. So I want to use flex and bison with the project. I can think of 3 ways- To keep flex and bison files out of project and source control. Generate the C source files and add it to project. Add flex and bison files to project, but run flex and bison commands separately. Integrate properly with IDE (Qt Creator on Ubuntu 12.04) and source control, so that when I build

Simple XML parser in bison/flex

ぐ巨炮叔叔 提交于 2020-01-02 06:15:09
问题 I would like to create simple xml parser using bison/flex. I don't need validation, comments, arguments, only <tag>value</tag> , where value can be number, string or other <tag>value</tag> . So for example: <div> <mul> <num>20</num> <add> <num>1</num> <num>5</num> </add> </mul> <id>test</id> </div> If it helps, I know the names of all tags that may occur. I know how many sub-tag can be hold by given tag. Is it possible to create bison parser that would do something like that: - new Tag("num",

Problems with reentrant Flex and Bison

白昼怎懂夜的黑 提交于 2020-01-01 10:08:33
问题 I'm learning how to use reentrant Bison and Flex together. I already got a simple calculator working without the reentrant capability. However when I activated the reentrant feature and made the necessary modifications, I couldn't get this to work. Here is the code: scanner.l %{ #include <stdio.h> #include "parser.tab.h" %} %option 8bit reentrant bison-bridge %option warn noyywrap nodefault %option header-file="lex.yy.h" DIGIT [0-9] %% "+" { return ADD; } "-" { return SUB; } "*" { return MUL;

Flex, continuous scanning stream (from socket). Did I miss something using yywrap()?

不羁的心 提交于 2020-01-01 03:49:25
问题 Working on a socketbased scanner (continuous stream) using Flex for pattern recognition. Flex doesn't find a match that overlaps 'array bounderies'. So I implemented yywrap() to setup new array content as soon yylex() detects <> (it will call yywrap). No success so far. Basically (for pin-pointing my problem) this is my code: %{ #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUFFERSIZE 26 /* 0123456789012345678901234 */ char cbuf1[BUFFERSIZE] = "Hello everybody, lex is su"