8000 GitHub - airween/flextest: A Flex example for file inclusion
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

airween/flextest

Repository files navigation

Flex example for file inclusion

A simple test project to demonstrate how flex (part of GNU bison) works.

Description

The lex file (mylexer.l) contains a very simple lexical analyzer. It capable to recognize comments, "ConfKey1" and "Confkey2" directives (the list is extendable), and the "include" directive with an argument (filename). If the lexer founds an "include" line, it opens the file and continue the analysis from that point. The parser (myparser.y) contains the minimal grammar.

Getting Started

Dependencies

To compile and test you need:

  • GNU Bison (flex at least)
  • GCC - or another C compiler, just replace it in Makefile
  • make

Installing

  • download the source
  • type a single make command

This will generate the lex.yy.c, myparser.tab.c C source (and the parser header), and the myparser binary.

Executing program

The source tree contains some configs, you can check the different behaviors.

  • first, just run this progam: ./myparser config1.conf. In the result, you can see the operations with a "->" prefix, and the recognized tokens
    $ cat config1.conf
    # file: config1.conf
    # this is a config
    
    ConfKey1  foo
    
    $ ./myparser config1.conf
    -> Opening file: config1.conf
    Comment: # file: config1.conf
    Comment: # this is a config
    Directive: ConfKey1
    Directive argument: foo
    -> Got EOF, stack_ptr: 0
    -> Closing file: config1.conf
    
  • then run ./myparser inctest_01.conf. This file contains few include lines sequentually
  • finally, run the binary with inctest_02.conf, which contains same structure with help of "*" (asterix) character.

Authors

Ervin Hegedüs

Version History

  • 0.1
    • Initial Release

License

This project is licensed under the GNU GPL License - see the LICENSE file for details.

About

A Flex example for file inclusion

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0