LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > astrogeek
User Name
Password

Notices


Rate this Entry

Flex / Bison Project Template README

Posted 08-19-2017 at 03:17 AM by astrogeek

Flex / Bison Project Template README file.

This file provides a description of the source files and of the major features and purpose of the template project.

Code:
Flex/Bison project skeleton template

This set of files consists of:

README - This file

Makefile        Simple makefile for building project files
                Defines multiple targets, see file for details

fbproject.l     Flex scanner source with a few useful default rules
                You must redefine and/or add rules specific to your project

fbproject.y     Bison parser source with trivial, single grouping level grammar
                You must redefine types, tokens and grammar and modify code for
                specific to your project

ex_commands,
ex_comments,
ex_errors,
ex_strings      Provide test cases for major function of compiled template

Use of this template provides a robust boiler-plate functional skeleton which allows
you to move immediately to implementation of your grammar and code for many projects

Important Features of Template:

Lexer
        * Supports Bison locations information
        * Supports C-style multi-line comments /*...*/
        * Supports shell style # comments
        * Supports double-quoted strings with internal escape sequences
          (returns string values without surrounding quote characters)
        * Warns of unclosed comments at end of file (accepts without error)
        * Warns of unclosed strings at end of line (accepts string without error)
        * Reports unrecognized character groups in input, returns error token
        * Handles "debug" and "quit" commands by returning DBG and QUIT tokens
        * Produces lexer header file for inclusion in parser and project files

Parser
        * Defines union of semantic values
        * Implements %locations option, redefines YYLTYPE to include input filename
        * Defines yyerror() function to make use of locations
        * Defines lyyerror() function for lexer error handling
        * Implements %destructor option for semantic values, reports actions when debug set
        * Defines simple, single grouping level grammar for initial execution
        * Grammar includes an error recovery rule, recovers to end of line
        * Supports input from STDIN or one or more files
        * Includes getopt_long () invocation arg handling
 Language and Grammar

        The template implements a trivial grammar of single grouping level, sufficient
        only for verifying operation of the lexer and skeleton features.

        The grammar rules and lexer rules should be replaced by those required by your
        project, with template commands replaced or integrated into that grammar as
        required.

        The language of the template consists of the following sentences:

                /* Comment */     : Silently ignored by lexer, may cross line ends
                # Comment         : Silently ignored to end of line by lexer
                "Quoted string" : Prints the string value to STDOUT
                d[ebug] <ENTER> : Toggles parser trace output state
                h[elp] <ENTER> : Prints a help message to STDOUT
                q[uit] <ENTER>  : Quit the parser in interactive mode
                <ENTER>   : No action

        The grammar for this language is:

                sentence: /* empty */
                    | sentence QSTRING EOL
                    | sentence HELP EOL
                    | sentence QUIT EOL
                    | sentence DBG EOL
                    | sentence EOL
                    | sentence error EOL
                    ;

Invocation Options:

        The skeleton code includes arg processing with getopt_long ()
        The following simple options and their use are defined:

        Usage: fbproject [OPTIONS] [filename ...]
                Reads input from filename(s) if given, else STDIN
                        Interactive Commands (one per line only):
                d|db|debug      Toggle debug mode (Bison trace output)
                q[uit]          Quit program
                "string"        Writes double-quoted string value to STDOUT
                ?|h|help        Print this help information
                /* comment */   C-style multi-line comments ignored
                # comment       Shell style comment ignored (must be first non-space character on line)
                        Invocation OPTIONS:
                -d, --debug     Start in debug mode (Bison trace output)
                -h, --help      Print this help message and exit
                -v, --verbose   Start in verbose mode

Makefile Targets

        fbproject: (default)    Builds executable parser named fbproject
        lex.yy.c:               Runs Flex to build lexer source and headers
        fbproject.tab.h:        Runs Bison to build parser source and headers
        dot:                    Runs Bison with graphviz output option
                                Produces fbproject.dot file
        dotx11:                 Produces fbproject.dot file and opens in X-window
        dotpng:                 Produces fbproject.dot file and generates fbproject.png
        clean:                  Clean build environment, remove generated files
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 01:33 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration