flex-lexer

Character Position from starting of a line

偶尔善良 提交于 2019-12-25 03:01:44
问题 In flex, what's the way to get character position from the starting of a line? I've got a post regarding position from start of a file but i want it from the start of a line. Also it should handle case like this: /** this is a comment */int x,y; output: Here position of "int"=3 Please give me some hints to implement this. 回答1: I presume that the "post regarding position from start of a file" is this one, or something similar. The following is based on that answer. To track the current column

Trouble with printf in Bison Rule

主宰稳场 提交于 2019-12-25 00:36:10
问题 I have tried something like this in my Bison file... ReturnS: RETURN expression {printf(";")} ...but the semicolon gets printed AFTER the next token, past this rule, instead of right after the expression. This rule was made as we're required to convert the input file to a c-like form and the original language doesn't require a semicolon after the expression in the return statement, but C does, so I thought I'd add it manually to the output with printf. That doesn't seem to work, as the

Regex matching string

孤街醉人 提交于 2019-12-24 19:33:44
问题 I am implementing a compiler and one thing I'd like to do is the string concatenation using '+', eg: str_cnct = "hi" + "dear" So the value now is "hidear". The problem is that my regex in flex captures all of it directly as a string giving "hi + dear". My current regex is: \".*\" {string} { yylval.struct_val.val.chain = (char *)malloc(sizeof(char)*yyleng); strncpy(yylval.struct_val.val.chain,yytext,yyleng); remove_char(yylval.struct_val.val.chain); yylval.struct_val.length = yyleng; yylval

Coding PHP Code browser: is Bison/Flex a choice?

醉酒当歌 提交于 2019-12-24 09:38:57
问题 I am planning to make Source code browser. Previously I wanted to use ctags but unfortunately, I found ctags is very limited as it cannot tell which class the method belongs to. I decided to check with another alternative. Reading the internet I have found many talking of using Bison/Flex. I have never used bison/flex so before I jumped in I wanted to know if it Bison/Flex is a right choice for my task. Thanks 回答1: Knowing that flex and bison(or lex and yacc) are parsing solution.you can use

How to write a working cmake file for flex & bison?

ⅰ亾dé卋堺 提交于 2019-12-24 07:27:44
问题 I am writing a small parser, but have problems of using cmake. My purpose is: flex F.l => F.cc, bison B.y => B.cc, my_program.cc + F.cc + B.cc => library My first attempt: FIND_PACKAGE(FLEX REQUIRED) if (FLEX_FOUND) ADD_CUSTOM_TARGET( flex_target COMMAND ${FLEX_EXECUTABLE} --header-file=${CMAKE_CURRENT_SOURCE_DIR}/F.h --outfile=${CMAKE_CURRENT_SOURCE_DIR}/F.cc ${CMAKE_CURRENT_SOURCE_DIR}/F.l COMMENT "Generating F.cc" ) endif(FLEX_FOUND) FIND_PACKAGE(BISON REQUIRED) if (BISON_FOUND) ADD_CUSTOM

Efficient matching of text messages against thousands of regular expressions

三世轮回 提交于 2019-12-24 01:08:48
问题 I am solving a problem where I have text message to match with thousands of regular expressions of the form <some string> {0 or 300 chars} <some string> {0 or 300 chars} e.g. "on"[ \t\r]*(.){0,300}"."[ \t\r]*(.){0,300}"from" or a real example can be "Dear"[ \t\r]*"Customer,"[ \t\r]*"Your"[ \t\r]*"package"[ \t\r]*(.){0,80}[ \t\r]*"is"[ \t\r]*"out"[ \t\r]*"for"[ \t\r]*"delivery"[ \t\r]*"via"(.){0,80}[ \t\r]*"Courier,"[ \t\r]*(.){0,80}[ \t\r]*"on"(.){0,80}"."[ \t\r]*"Delivery"[ \t\r]*"will"[ \t

How do I generate different yyparse functions from lex/yacc for use in the same program?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 18:55:42
问题 I want to generate two separate parsing functions from lex/yacc. Normally yacc gives you a function yyparse() that you can call when you need to do some parsing, but I need to have several different yyparses each associated with different lexers and grammars. The man page seems to suggest the -p (prefix) flag, but this didn't work for me. I got errors from gcc that indicated that yylval was not properly being relabeled (i.e. it claims that several different tokens are not defined). Does

Unit test of flex bison scanner parse, how to drive the test case

纵饮孤独 提交于 2019-12-23 12:24:12
问题 I have a question about how to "drive" a flex bison based parser scanner in a unit test. The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin. Right now my focus is on getting a unit test running for the command parser. I would like to be able to provide a "const string" to the parser (a command) and then test that the corresponding command is invoked in the application (in a application stub). I do not

Bison does not appear to recognize C string literals appropriately

杀马特。学长 韩版系。学妹 提交于 2019-12-23 02:46:09
问题 My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly interpreting the string literals that I feed it. Here's my code: 130 insertexpr : "INSERT" expr '(' expr ')' 131 132 { 133 $$ = new QLInsert( $2, $4 ); 134 } 135 ; And

Cyclic Dependency in reentrant flex / bison headers with union YYSTYPE

戏子无情 提交于 2019-12-23 02:34:38
问题 I have a problem where I believe there is a cyclic dependency between the headers generated by flex and bison . The type yyscan_t is defined in the lex header and needed in the yacc header. The macro YYSTYPE is defined in the yacc header and needed in the lex header. No matter which order I import the two headers, the other will not be happy. reentrant.lex: %{ #include "reentrant.yacc.h" %} %option reentrant bison-bridge %% [0-9]+ { yylval->int_value = atoi(yytext); return INT_TERM; } [a-zA-Z