flex-lexer

YAML parsing - lex or hand-rolled?

本秂侑毒 提交于 2020-01-01 03:16:10
问题 I am trying to write a simple YAML parser, I read the spec from yaml.org, before I start, I was wondering if it is better to write a hand-rolled parser, or use lex ( flex/bison ). I looked at the libyaml (C library) - doesn't seem to use lex/yacc . YAML (excluding the flow styles ), seems to be more line-oriented, so, is it easier to write a hand-rolled parser, or use flex/bison Thanks. 回答1: This answer is basically an answer to the question: "Should I roll my own parser or use parser

Configuring Bison and Flex without global or static variable

∥☆過路亽.° 提交于 2019-12-31 13:49:11
问题 i am working in a small language/IDE. And I need to know how to configure flex and bison to work together but without using any global or static variable. I need to pass to bison my AST pointer. I also need that bison pass my AST to flex as well. It's a thread environment but i dont need any thread sync. And I need a separete yylineno variable for each yyparse() call. I read about %define api.pure , %parse-param and %option reentrant. But i don't know how to put them to work together... thx

how to handle nested comment in flex

做~自己de王妃 提交于 2019-12-31 03:45:11
问题 I am working on writing a flex scanner for a language supporting nested comment like this: /* /**/ */ I use to work on ocaml/ocamllex that support recursive calling lex scanner very elegent. But I am now switching to c++/flex, how to handle such nested comment? 回答1: Assuming that only comments can be nested in comments, a stack is a very expensive solution for what could be achieved with a simple counter. For example: %x SC_COMMENT %% int comment_nesting = 0; /* Line 4 */ "/*" { BEGIN(SC

Trouble linking against LLVM with project including Flex and Bison

主宰稳场 提交于 2019-12-30 09:39:07
问题 I've been working through a tutorial on writing compilers with Flex, Bison, and LLVM (http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/), and attempting to compile the final binary fails with many of the following "undefined reference" errors: g++ -o parser `llvm-config --libs core jit native --cxxflags --ldflags` *.cpp /tmp/ccl0CSyi.o: In function `NBinaryOperator::codeGen(CodeGenContext&)': codegen.cpp:(.text+0x2ce): undefined reference to `llvm::BinaryOperator::Create(llvm:

Most effective way to parse C-like definition strings?

三世轮回 提交于 2019-12-30 09:32:35
问题 I've got a set of function definitions written in a C-like language with some additional keywords that can be put before some arguments(the same way as "unsigned" or "register", for example) and I need to analyze these lines as well as some function stubs and generate actual C code from them. Is that correct that Flex/Yacc are the most proper way to do it? Will it be slower than writing a Shell or Python script using regexps(which may become big pain, as I suppose, if the number of additional

REPL for interpreter using Flex/Bison

断了今生、忘了曾经 提交于 2019-12-30 03:11:46
问题 I've written an interpreter for a C-like language, using Flex and Bison for the scanner/parser. It's working fine when executing full program files. Now I'm trying implement a REPL in the interpreter for interactive use. I want it to work like the command line interpreters in Ruby or ML: Show a prompt Accept one or more statements on the line If the expression is incomplete display a continuation prompt allow the user to continue entering lines When the line ends with a complete expression

loading external files flex bison - yyin?

老子叫甜甜 提交于 2019-12-29 08:23:15
问题 I am writing a basic language in flex + bison for my own personal research / to run simple scripts for fun. It takes user input via the command line, parses it, and executes the desired result. I would like to add functionality load files. for example, when the "load file 'somefile.src'" the file is loaded and automatically parsed, then the parser switches back to waiting for command line inputs. I haven't been able to make sense of the documentation and am pretty lost. It doesn't help that I

flex+bison output in a glib's hash container

倾然丶 夕夏残阳落幕 提交于 2019-12-25 05:05:24
问题 I have managed considerable progress in parsing the bib file, but the next step is quite tough for my present level of understanding. I have created bison and flex code, that parses the bib file above correctly: %{ #include <stdio.h> %} // Symbols. %union { char *sval; }; %token <sval> VALUE %token <sval> KEY %token OBRACE %token EBRACE %token QUOTE %token SEMICOLON %start Input %% Input: /* empty */ | Input Entry ; /* input is zero or more entires */ Entry: '@' KEY '{' KEY ','{ printf("=====

flex+bison output in a glib's hash container

假装没事ソ 提交于 2019-12-25 05:05:05
问题 I have managed considerable progress in parsing the bib file, but the next step is quite tough for my present level of understanding. I have created bison and flex code, that parses the bib file above correctly: %{ #include <stdio.h> %} // Symbols. %union { char *sval; }; %token <sval> VALUE %token <sval> KEY %token OBRACE %token EBRACE %token QUOTE %token SEMICOLON %start Input %% Input: /* empty */ | Input Entry ; /* input is zero or more entires */ Entry: '@' KEY '{' KEY ','{ printf("=====

Project on flex and bison

旧城冷巷雨未停 提交于 2019-12-25 03:36:24
问题 I have used flex and bison in order to make a lexical analyzer and a parser for an EBNF grammar . This work is done! I mean, when i put a file with a program I write, I can see if the program has mistakes. If it doesn't, I can see the whole program in my screen based on the grammar i have used. I have no problem in this. Now, I want to use loop handling and loop unrolling. Which part should I change? The lexical analyzer? The parser? Or the main after the parser? And how? 回答1: Introduction As