All Projects → ezaquarii → bison-flex-cpp-example

ezaquarii / bison-flex-cpp-example

Licence: MIT license
GNU Bison and GNU Flex C++ example

Programming Languages

C++
36643 projects - #6 most used programming language
Yacc
648 projects
Lex
420 projects
Makefile
30231 projects

Projects that are alternatives of or similar to bison-flex-cpp-example

simpPRU
Intuitive language for PRU which compiles down to PRU C
Stars: ✭ 54 (-62.76%)
Mutual labels:  flex, bison-grammar
kaec-app
An Apache Flex mobile app that uses the Youtube V3 API, Foursquare API, Flickr API and RSS feeds.
Stars: ✭ 12 (-91.72%)
Mutual labels:  flex
language-grammars
Syntax highlighting for ABNF/BNF/EBNF, Yacc, and other language-related languages.
Stars: ✭ 14 (-90.34%)
Mutual labels:  flex
vue-layout-system
A pack of Vue components that solve daily layout problems
Stars: ✭ 31 (-78.62%)
Mutual labels:  flex
react-styled-flexbox
A Flexbox React component harnessing the power of styled-components
Stars: ✭ 30 (-79.31%)
Mutual labels:  flex
compiler
Implementing a complete Compiler for a simple C-like language using the C-tools Flex and Bison
Stars: ✭ 106 (-26.9%)
Mutual labels:  flex
Flex-AntiCheat
Flex AntiCheat - Optimized Configs For Multiple AntiCheats
Stars: ✭ 37 (-74.48%)
Mutual labels:  flex
TinyCompiler
c compiler based on flex(lex), bison(yacc) and LLVM, supports LLVM IR and obj code generation. 基于flex,bison以及LLVM,使用c++11实现的类C语法编译器, 支持生成中间代码及可执行文件.
Stars: ✭ 162 (+11.72%)
Mutual labels:  flex
fis-postprocessor-px2rem
fis3 plugins for px2rem when we use rem for mobile flexbox
Stars: ✭ 22 (-84.83%)
Mutual labels:  flex
NatLang
NatLang is an English parser with an extensible grammar
Stars: ✭ 20 (-86.21%)
Mutual labels:  flex
icon-generator
Generate icons and launch screens for your Adobe AIR projects.
Stars: ✭ 24 (-83.45%)
Mutual labels:  flex
flexui
A light UI for C++ with XML and CSS support
Stars: ✭ 21 (-85.52%)
Mutual labels:  flex
alipay-vue
蚂蚁金服小程序(alipay hybrid) 基于 vuejs 的 template
Stars: ✭ 13 (-91.03%)
Mutual labels:  flex
flex-bison-indentation
An example of how to correctly parse python-like indentation-scoped files using flex (and bison).
Stars: ✭ 32 (-77.93%)
Mutual labels:  flex
sqlfun
Modern SQL parser using Bison (Yacc) and Flex
Stars: ✭ 63 (-56.55%)
Mutual labels:  flex
sass-flexbox
Manage Flexbox in Sass easily.
Stars: ✭ 40 (-72.41%)
Mutual labels:  flex
vue-flex-waterfall
🌊 A horizontal sorting waterfall layout component for Vue.js, realized by flex layout
Stars: ✭ 27 (-81.38%)
Mutual labels:  flex
fs-make
Make a folder structure from its description
Stars: ✭ 14 (-90.34%)
Mutual labels:  flex
FWDebug
iOS调试库,支持iOS11+,无需添加任何代码,方便iOS开发和测试。 iOS debugging library, support for iOS11 +, without adding any code to facilitate iOS development and testing.
Stars: ✭ 49 (-66.21%)
Mutual labels:  flex
chirp
Interpreter in C for rockstar programing language
Stars: ✭ 20 (-86.21%)
Mutual labels:  flex

#Flex & Bison LALR C++ example#

What?

This is a not-so-crude example showing how to deploy Flex and GNU Bison in modern C++ programs. Example program provides simple commandline that parses function calls with list of arguments (unsigned ints only) and builds AST. AST is printed when parsing completes. See code comments for more details.

Features:

  • Compatible with the good, old C++03 for maximum portability.
  • Fully reentrant parser and lexer, C++ implementation.
  • Parser and lexer are in a customized namespace with custom class names.
  • Flex base class has a customized name; multiple different flex scanners in the binary are possible without a name conflict. Believe it or not, but even in the 21st century it is still a bit tricky with Flex.
  • Parser and scanner enclosed in a "driver" class (Interpreter)
  • Uses Bison 3.0 token variant API (yay!).
  • Location tracking. Not perfect, but the core is there.

Once we overcome the abovementioned obstacles, the Flex/GNU Bison pair becomes quite pleasant to use in day to day work.

Disclaimer

Haven't tested it on MS Windows. Please tell me if it works there... Do not forget to turn off unistd.h in options.

Why bother?

Official GNU Bison example features C++ parser connected to primitive C-style lexer, which is probably not what you want most of the time. There is currently (2014) no easy way to find a true C++ example of elegant Flex/Bison3 deployment. I really do not understand why a serious project like Bison provides such a poor user-experience for beginners.

##Yea, but still, why bother with old Flex/Bison?##

ANTLR4 has been released without C++ support nor any estimation (last checked September 2014). The Java generator is premium quality though.

ANTRL3 explicitly states that C++ support is total garbage and the mailing lists didn't make my impression any better.

Flexc++ and Bisonc++ are not that popular. I wasn't sure about portability either.

Flex and GNU Bison don't pull any dependencies and the code is (or at least is claimed to be) portable. By "portable" I mean it works in Unix universe and Windows, because the latter one is the only platform on the planet being notorious for catastrophically imbecilic design decisions (cmd.exe, http:\\www.microsoft.com\backslash\fetish, etc), causing endless, epic portability issues and developer's nightmares.

Source organization

The main function creates the Interpreter object and calls parse(). Scanner and Parser are encapsulated in the Interpreter. By default the Scanner reads the standard input, but you can switch it using the provided Interpreter API and feed it with an arbitrary stream, such as std::stringstream.

Building

Crude Makefile is provided - not much...

make

./a.out

make clean

Legal mumbo-jumbo

The example code is MIT-licensed. The code generated by Flex and Bison has a separate license: Modified, non-viral GPL, which is safe to use. See the source code files.

TODO

  • some kind of template to deploy a complete scanner/parser stub in a project with an IDE wizard
  • namespace defined with preprocessor?

Special thanks

  • My girl - for late coffees and feeding me during deep coding sessions
  • Flex and GNU Bison folks - for focus on portability and years of maintenance
  • MIT folks - for MIT License
  • Me - for assembling this example

Enjoy!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].