fbb-git / flexcpp Goto Github PK
View Code? Open in Web Editor NEWFlexc++ is a scanner generator like flex, but it generates C++ code
Flexc++ is a scanner generator like flex, but it generates C++ code
The specification example given in the flexc++input man page no longer compiles.
Presumably because the mini-scanners are now in a strongly typed enum. Hence if I am not mistaken
"/*" begin(comment);
<comment>.|\n // ignore
<comment>"*/" begin(INITIAL);
needs to become
"/*" begin(StartCondition__::comment);
<comment>.|\n // ignore
<comment>"*/" begin(StartCondition__::INITIAL);
Which is quite ugly, but that is another topic.
How about adding a function to get the column number of a line? We now have a function to get the line number, how about the column number?
Building flexcpp with clang results in:
./parser/parserbase.h:296:14: error: reference to non-static member function must be called; did you mean to call it with no arguments?
The full log can be found here:
http://clang.debian.net/logs/2016-08-30/flexc++_2.05.00-1_unstable_clang.log
Hi,
I created a simple program that uses flexc++ to generate a lexer (along with bisonc++ for a parser), and compiled it with -fsanitize=leak
.
I got a memory leak from the lexer code generated by flexc++ :
Direct leak of 280 byte(s) in 1 object(s) allocated from:
#0 0x7f399f313be8 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/liblsan.so.0+0xbbe8)
#1 0x4055b1 in ScannerBase::ScannerBase(std::istream&, std::ostream&) ../src/parse/lex.cc:797
It seems that the skeleton file https://github.com/fbb-git/flexcpp/blob/master/flexc%2B%2B/skeletons/flexc%2B%2B.cc does not properly manage the memory for the input/output streams.
The Lexer implementation generated by flexcpp uses the [[fallthrough]]
attribute in a wrong way. It should be followed by a semicolon, see e.g. here and here.
E.g. currently, I have this:
size_t ScannerBase::Input::get()
{
switch(size_t ch = next()) // get the next input char
{
case '\n':
++d_lineNr;
[[fallthrough]]
default:
return ch;
}
}
in my lex.cc
, where it should be
size_t ScannerBase::Input::get()
{
switch(size_t ch = next()) // get the next input char
{
case '\n':
++d_lineNr;
[[fallthrough]]; // Semicolon needed!
default:
return ch;
}
}
The Code is thus not conforming to the C++-17 standard. g++ ignores this, but Visual Studio won't compile this Code.
From the current man page:
By now, the project has evolved to a level that we feel it's defensible to publish the program, although we still tend to consider the program in its experimental stage; it will remain that way until we decide to move its version from the 0.9x.xx series to the 1.xx.xx series.
https://github.com/fbb-git/flexcpp/blob/master/flexc%2B%2B/documentation/man/flexc%2B%2B.yo
Since flexc++ is now production ready (right?), this sentence should definitely be replaced.
I have problems when using nested namespaces :)
This is my configuration:
%filenames = "MyParser"
%namespace = "my::nested::ns"
%class-name = "MyParser"
%baseclass-header = "MyParserBase.hpp"
%lex-source = "MyParserBase.cpp"
%class-header = "MyParser.hpp"
%implementation-header = "MyParserImpl.hpp"
%%
[ \t]+ // skip white space chars.
[0-9]+ return NUMBER;
[[:alpha:]_][[:alpha:][:digit:]_]* return IDENTIFIER;
[][] return SIGNAL;
. return matched()[0];
\n begin(StartCondition__::INITIAL);
Here is the error:
In file included from parsing/flex/MyParserBase.cpp:9:
In file included from parsing/flex/MyParserImpl.hpp:4:
parsing/flex/MyParser.hpp:3:11: warning: extra tokens at end of #ifndef directive [-Wextra-tokens]
#ifndef my::nested::nsMyParser_H_INCLUDED_
^
//
parsing/flex/MyParser.hpp:4:11: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions]
#define my::nested::nsMyParser_H_INCLUDED_
^
In file included from parsing/flex/MyParserBase.cpp:9:
In file included from parsing/flex/MyParserImpl.hpp:4:
In file included from parsing/flex/MyParser.hpp:7:
flex/MyParserBase.hpp:3:11: warning: extra tokens at end of #ifndef directive [-Wextra-tokens]
#ifndef my::nested::nsMyParserBASE_H_INCLUDED
^
//
In file included from parsing/flex/MyParserBase.cpp:9:
In file included from parsing/flex/MyParserImpl.hpp:4:
parsing/flex/MyParser.hpp:10:11: error: expected identifier or '{'
namespace my::nested::ns
^
parsing/flex/MyParser.hpp:4:11: note: expanded from macro 'my'
#define my::nested::nsMyParser_H_INCLUDED_
^
parsing/flex/MyParser.hpp:10:11: error: no member named 'nested' in the global namespace
namespace my::nested::ns
^~
parsing/flex/MyParser.hpp:4:13: note: expanded from macro 'my'
#define my::nested::nsMyParser_H_INCLUDED_
~~^
parsing/flex/MyParserBase.cpp:12:11: error: expected identifier or '{'
namespace my::nested::ns
^
parsing/flex/MyParser.hpp:4:11: note: expanded from macro 'my'
#define my::nested::nsMyParser_H_INCLUDED_
^
parsing/flex/MyParserBase.cpp:12:11: error: no member named 'nested' in the global namespace
namespace my::nested::ns
^~
parsing/flex/MyParser.hpp:4:13: note: expanded from macro 'my'
#define my::nested::nsMyParser_H_INCLUDED_
When I replace %namespace = "my::nested::ns"
whith %namespace = "mynestedns"
everything works as expected. :)
I think that I'm using C++ feature for which flexc++ is not ready yet :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.