flex-lexer

Is there working example of flex + bison with input from string, not file?

被刻印的时光 ゝ 提交于 2019-12-13 04:46:30
问题 Is there working example of flex + bison (bison is necessary) with input from string, not file? I have tried to use YY_BUFFER_STATE ... functions instead of yyin and got error "flex scanner push-back overflow". Flex changes InputString[1] to 0. Several other answers on SO are of little help - actual code will be much more useful. 回答1: The way to scan memory region is described in the Flex manual. Flex modifies the buffer given by yy_scan_buffer . If you need to avoid to be modified, yy_scan

Bison/Flex, reduce/reduce, identifier in different production

隐身守侯 提交于 2019-12-13 04:43:28
问题 I am doing a parser in bison/flex. This is part of my code: I want to implement the assignment production, so the identifier can be both boolean_expr or expr, its type will be checked by a symbol table. So it allows something like: int a = 1; boolean b = true; if(b) ... However, it is reduce/reduce if I include identifier in both term and boolean_expr, any solution to solve this problem? 回答1: Essentially, what you are trying to do is to inject semantic rules (type information) into your

Regex in jFlex with hardcoded exceptions

家住魔仙堡 提交于 2019-12-13 03:19:14
问题 I need a regex in jFlex to match a string literal, containing some characters, followed by a hyphen which is followed by a word. However, there are a few hardcoded exceptions. My jFlex version is 1.6.1 My regexes are: SUFFIXES = labeled|deficient ALPHANUMERIC = [:letter:]|[:digit:] AVOID_SUFFIXES = {SUFFIXES} | !({ALPHANUMERIC}+) WORD = ({ALPHANUMERIC}+([\-\/\.]!{AVOID_SUFFIXES})*) String "MXs12-labeled" should be tokenized into 'MXs12', '-', 'labeled' (hyphen caught by different regex later)

Simulating Booleans in Bison with C

孤街醉人 提交于 2019-12-13 02:16:16
问题 I am trying to make a logic calculator using C and bison, but I'm having trouble because C does not have a boolean type. This is part of my Flex rules: "TRUE" | "T" | "t" {yylval = 1; return TRUE; } "FALSE" | "F" | "f" {yylval = 0; return TRUE; } This is part of my Bison rules: line: EOL | exp EOL {printf("%d %d %d \n"), $1, $2,$$;} ; exp: TRUE | FALSE ; This is the output when I type T followed by EOL (end of line) in my calculator: 10 12 1 10 is ascii for newline, 12 is ascii for carriage

(F) Lex, how do I match negation?

谁都会走 提交于 2019-12-13 02:06:29
问题 Some language grammars use negations in their rules. For example, in the Dart specification the following rule is used: ~('\'|'"'|'$'|NEWLINE) Which means match anything that is not one of the rules inside the parenthesis. Now, I know in flex I can negate character rules (ex: [^ab] , but some of the rules I want to negate could be more complicated than a single character so I don't think I could use character rules for that. For example I may need to negate the sequence '"""' for multiline

How do you compile flex in Visual Studio 2005/2008?

岁酱吖の 提交于 2019-12-12 15:34:16
问题 I can't figure this one out. I can download a win32 binary of flex 2.5.4a from gnuwin32, but I'd like to build the latest version (2.5.35) using Visual Studio 2005. I suppose I could build in in cygwin, but where is the fun in that? 回答1: Note that Flex is seriously out-of-date on Windows when it comes to generating C++ scanners. Recent Flex versions which are able to generate ISO C++ scanners do not support Win32 (MinGW or VS), so you're probably better of trying to generate a C scanner and

Initiating Short circuit rule in Bison for && and || operations

人盡茶涼 提交于 2019-12-12 12:15:50
问题 I'm programming a simple calculator in Bison & Flex , using C/C++ (The logic is done in Bison , and the C/C++ part is responsible for the data structures , e.g. STL and more) . I have the following problem : In my calculator the dollar sign $ means i++ and ++i (both prefix and postfix) , e.g. : int y = 3; -> $y = 4 -> y$ = 4 When the user hits : int_expression1 && int_expression2 , if int_expression1 is evaluated to 0 (i.e. false) , then I don't wan't bison to evaluate int_expression2 ! For

Can't figure out why Bison is throwing “Rules useless in parser due to conflicts”

一个人想着一个人 提交于 2019-12-12 12:11:42
问题 I'm writing a BNF grammar for a very simple programming language and using Flex and Bison to compile. I only have 3 variable and constant types: real, integer, string . My .l file has a token definition for "ID" as follows: DIGIT [0-9] LETTER [a-zA-Z] ID {LETTER}({LETTER}|{DIGIT})* My .y file has a definition for an identifier like this: identifier: ID; Now, I want to use the identifier definition to build variable and constant names. But I also want to limit assignment to data of the same

Compiling and executing the Shakespeare Programming Language translator spl2c on Mac OS X 10.6 results in warnings/errors

六眼飞鱼酱① 提交于 2019-12-12 07:56:40
问题 I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make . The compilation of spl2c executes with a couple warnings: scanner.l:600: warning, rule cannot be matched <stdout>:5808: warning: ‘yyunput’ defined but not used And then when it attempts to compile all the examples everything goes haywire: ../spl/bin/spl2c < fibonacci.spl > fibonacci.c Warning at line 19: equality expected Warning at line 28:

Flex default rule

随声附和 提交于 2019-12-12 07:23:48
问题 How do I customize the default action for flex. I found something like <*> but when I run it it says "flex scanner jammed"? Also the . rule only adds a rule so it does not work either. What I want is comment "/*"[^"*/"]*"*/" %% {comment} return 1; {default} return 0; <<EOF>> return -1; Is it possible to change the behavior of matching longest to match first? If so I would do something like this default (.|\n)* but because this almost always gives a longer match it will hide the comment rule.