flex-lexer

Undefined Reference To yywrap

一曲冷凌霜 提交于 2019-12-17 17:33:59
问题 I have a simple "language" that I'm using Flex(Lexical Analyzer), it's like this: /* Just like UNIX wc */ %{ int chars = 0; int words = 0; int lines = 0; %} %% [a-zA-Z]+ { words++; chars += strlen(yytext); } \n { chars++; lines++; } . { chars++; } %% int main() { yylex(); printf("%8d%8d%8d\n", lines, words, chars); } The I run a flex count.l , all goes ok without errors or warnings, then when I try to do a cc lex.yy.c I got this errors: ubuntu@eeepc:~/Desktop$ cc lex.yy.c /tmp/ccwwkhvq.o: In

#error “Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h”

╄→гoц情女王★ 提交于 2019-12-17 16:34:12
问题 I have been trying to follow the tutorial at http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/5/ (using flex, bison and llvm) but when typing the line g++ -o parser parser.cpp tokens.cpp main.cpp I get the following errors: In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0, from /usr/local/include/llvm/ADT/PointerIntPair.h:17, from /usr/local/include/llvm/IR/Use.h:28, from /usr/local/include/llvm/IR/Value.h:17, from node.h:3, from parser.y:2: /usr

checking unfinished comments in flex

早过忘川 提交于 2019-12-14 02:42:21
问题 I am a new to flex. I have just written a sample code to detect multi line comments using a flex program. Now I want to improve the code. I want to detect unfinished and ill formed comments in the code. for example: a comment beginning with /* without an ending */ is an unfinished comment and by ill formed comment I mean the comment is not properly formed, say, an EOF appears inside the comment etc. What I have to add in my code to check these things? My sample code is as follows: %x COMMENT

Flex++ Bisonc++ parser

不羁岁月 提交于 2019-12-14 00:22:14
问题 I'm trying to use flex and bison in my project to generate a parser code for a file structure. Main programming language is C++ and project is on an OO design mainly running in parallel. I heard that flex and bison generated parsers are C codes and they're not reenterant. Googling, I found flex++ and bisonc++ . Unfortunately there is no simple tutorial to get started. Most examples are based on bison/flex . Some people somehow integrated bison/flex parsers in their C++ code. They supposed to

How to list lex/yacc or flex/bison patterns?

久未见 提交于 2019-12-13 23:56:41
问题 I would like to extract all patterns from a flex/bison file to look at them altogether. I am not interested in the rules applying to the patterns for now. Surely someone has written a flex/bison file for this already? :) 回答1: If you give it the -v command-line option, bison will output a nicely formatted version of the grammar (and all the states) to a file with extension .output . You can specify the precise file name to write to with --report-file=PATH and a list of things to report on with

A weird situation about matching in flex

折月煮酒 提交于 2019-12-13 23:50:23
问题 I am writing a scanner in flex, and I have the following two definitions: %% "int" printf("JUST_INT"); "int"[ \t\n]+"matrix" printf("MATRIX_INT"); [A-Za-z][A-Za-z0-9]* printf("IDENTIFIER"); %% When the input to the scanner is int matrixM = 3; the output is MATRIX_INT IDENTIFIER . It sees the input as int matrix M=3 . But actually, this is not a matrix , the name of identifier is matrixM . Output should be JUST_INT IDENTIFIER . Why is this happening? Is that because of my definitions? 回答1: It

Why my rules of bison don't work

余生颓废 提交于 2019-12-13 18:41:26
问题 Every time I run my parser, it will appear "syntax error in line 1 near <>" (Because there is a subroutine yyerror(char *s)). I think that's because there is something wrong with my rules in bison. The file (c17.isc) I want to parse. *c17 iscas example (to test conversion program only) *--------------------------------------------------- * * * total number of lines in the netlist .............. 17 * simplistically reduced equivalent fault set size = 22 * lines from primary input gates .......

How to write the following regex in Flex?

对着背影说爱祢 提交于 2019-12-13 10:16:38
问题 I'm trying to define a rule in flex that will capture a "multiline string". A multiline string is a string that starts with three apostrophes: ''' , ends with three apostrophes, and can span over multiple lines. For example: '''This is an example of a multiline string''' So my attempt at this was this: %{ #include<iostream> using std::cout; using std::endl; %} MULTI_LN_STR '''(.|\n)*''' %% {MULTI_LN_STR} {cout<<"GotIt!";} %% int main(int argc, char* argv[]) { yyin=fopen("test.txt", "r"); if (

Is the bug in the grammar or in the code?

时光怂恿深爱的人放手 提交于 2019-12-13 07:14:11
问题 I'm not sure if this grammar is correct for a shell command language that should also be able to execute single-quotes and double-quotes. It seems that non-trivial commands work e.g. ls -al | sort | wc -l but the simple one does not work with single-quotes: echo 'foo bar' does not work. %{ #include "shellparser.h" %} %option reentrant %option noyywrap %x SINGLE_QUOTED %x DOUBLE_QUOTED %% "|" { return PIPE; } [ \t\r] { } [\n] { return EOL; } [a-zA-Z0-9_\.\-]+ { return FILENAME; } ['] { BEGIN

Flex ‘r/s’ in ANTLv4

左心房为你撑大大i 提交于 2019-12-13 06:57:06
问题 Flex: ‘r/s’ an ‘r’ but only if it is followed by an ‘s’. The text matched by ‘s’ is included when determining whether this rule is the longest match, but is then returned to the input before the action is executed. So the action only sees the text matched by ‘r’. This type of pattern is called trailing context. (There are some combinations of ‘r/s’ that flex cannot match correctly. See Limitations, regarding dangerous trailing context.) How do this in ANTLRv4 ? 回答1: There are two primary ways