flex-lexer

What's wrong with strndup?

若如初见. 提交于 2019-12-10 19:44:08
问题 I'm writing a parser using flex. I'm using Mac OS X 10.6.7. I have already include header files like this: #include "string.h" #include "stdlib.h" but it says Undefined symbols for architecture x86_64: "_strndup", referenced from: _yylex in ccl2332A.o ld: symbol(s) not found for architecture x86_64 why? 回答1: AFAIK there is no method strndup in string.h or stdlib.h, try using strdup() which is probably what you want. If you really need to specifiy the length you want allocated you could do it

Flex/Bison EOF propagation from stdin vs a file

痞子三分冷 提交于 2019-12-10 19:28:13
问题 I have a scanner, parser and a main from which I create an executable via bison -d parser.y; flex scanner.l; gcc main.c parer.tab.c lex.yy.c When I run ./a.out it does what I want: If Ctrl+D is pressed an EOF is detected and main can act accordingly. This means: if yyin is stdin then hitting Return ends the parsing of that line and the main loop waits for the next input line. Pressing Ctrl+D ends parsing input with a break in the main loop and exits. If the input comes from a file, e,g,

Remote version of flex misinterprets my rules

若如初见. 提交于 2019-12-10 16:16:10
问题 I've written a little assembler using flex and bison, that builds and runs OK on my machine (ubuntu 10.10). Someone else is now trying to build it on arch linux, and their install of flex produces a different lex.yy.c which is mis-matching rules. Both versions report the same lex 2.5.35 version, but I've already seen differences between mine and another flex on Mac OSX which didn't grok (?i patterns, so I don't trust that version string much. I don't have access to the remote machine, so I'm

Removing nested comments bz lex

半世苍凉 提交于 2019-12-10 14:54:42
问题 How should I do program in lex (or flex) for removing nested comments from text and print just the text which is not in comments? I should probably somehow recognize states when I am in comment and number of starting "tags" of block comment. Lets have rules: 1.block comment /* block comment */ 2. line comment // line comment 3. Comments can be nested. Example 1 show /* comment /* comment */ comment */ show output: show show Example 2 show /* // comment comment */ show output: show show

Bison+Flex segfault no backtrace

最后都变了- 提交于 2019-12-10 12:35:20
问题 I'm trying to debug code generated by Bison + Flex (what a joy!). It segfaults so badly that there isn't even stack information available to gdb . Is there any way to make this combination generate code that's more debuggable? Note that I'm trying to compile a reentrant lexer and parser (which is in itself a huge pain). Below is the program that tries to use the yyparse : int main(int argc, char** argv) { int res; if (argc == 2) { yyscan_t yyscanner; res = yylex_init(&yyscanner); if (res != 0

Simple Java grammar using Flex & Bison

十年热恋 提交于 2019-12-10 11:56:06
问题 I recently started learning basic Flex and Bison because I have to make a parser for simple (but not too simple) grammar. I decided to make a simplified Java language in my grammar. I made the .l and the .y files and everything compiles without error (I'm using gcc to compile). The problem is that every time I run the generated program I get Syntax Error , even with a simple input like: private class Something{} . The only time I do not get a Syntax Error is when I enter an empty line ( \n ).

regular expression for IPv6 addresses

我们两清 提交于 2019-12-10 09:44:22
问题 I have a regular expression for IPv6 addresses as given below IPV4ADDRESS [ \t]*(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))[ \t]* x4 ([[:xdigit:]]{1,4}) xseq ({x4}(:{x4}){0,7}) xpart ({xseq}|({xseq}::({xseq}?))|::{xseq}) IPV6ADDRESS [ \t]*({xpart}(":"{IPV4ADDRESS})?)[ \t]* It is correctly all formats of IPv6 addresses including 1) non-compressed IPv6 addresses 2) compressed IPv6 addresses 3) IPv6 addresses in legacy formats.(supporting IPv4) Ideal examples of IPv6 addresses in legacy formats

How to fix a missing ld library for -lfl while compiling?

你离开我真会死。 提交于 2019-12-10 02:51:57
问题 I am trying to translate my .spl file into a C file (because there is no compiler). I have an example "Hello World" .spl file, and I have downloaded the Shakespeare Programming Language .tar and extracted it, but I have no idea what to do next. I can't seem to find instructions in any documentation. Can anyone help? Edit: When I type make -f "Makefile" , I get the following output: bison --verbose -d grammar.y gcc -O2 -Wall -c grammar.tab.c gcc -O2 -Wall -c makescanner.c gcc makescanner.o -O2

How do I write a non-greedy match in LEX / FLEX?

ぐ巨炮叔叔 提交于 2019-12-10 01:21:42
问题 I'm trying to parse a legacy language (which is similar to 'C') using FLEX and BISON. Everything is working nicely except for matching strings. This rather odd legacy language doesn't support quoting characters in string literals, so the following are all valid string literals: "hello" "" "\" I'm using the following rule to match string literals: \".*\" { yylval.strval = _strdup( yytext ); return LIT_STRING; } Unfortunately this is a greedy match, so it matches code like the following: "hello

Doxygen - Could NOT find FLEX (missing: FLEX_EXECUTABLE)

流过昼夜 提交于 2019-12-08 15:53:56
问题 I know there are very similar worded questions on here, but I could not find an answer to my question there, so here we go: I'm trying to see which of my C++ methods are called by others so I found Doxygen after googling. On their page the installation seems pretty straightforward: If you have the necessary build tools installed (i.e. g++, python, cmake, flex, bison), you should do the following to get the initial copy of the repository: git clone https://github.com/doxygen/doxygen.git cd