Name | Modified | Size | Downloads / Week |
---|---|---|---|
c++bison.zip | 2019-08-02 | 32.8 kB | |
README.md | 2019-08-01 | 2.5 kB | |
Totals: 2 Items | 35.3 kB | 0 |
EXAMPLE FLEX/BISON/C++ parser project
Introduction
You should be able to clone this directory and change easily to use it as a basis for developing a parser for your own novel language. The parser can be for any language you can design in flex/bison and will be developed in C++.
The Makefile is set up to automatically generate and use make dependencies, This should, therefore, be a fairly safe quick-start example from which to base your own parser development.
Authorship
This directory is a variation on the following example:
Jonathan Beard deserves most of the credit for this work.
Lowell Boggs added :
- Automatic generation of Makefile depedencies
- The LocatedIdentifier class as an example of how bind identifiers to source file locations.
- Using #include pre-processing ala C and C++ in the language you are creating.
- Additional compiler options in the Makefile to improve debugging
- The ability to provide intelligent error messages to programmers trying to use the parser you develop:
- That is, the ability to print the file name and line number of tokens associated with compile errors
- Jonathon Beard's excellent example was set up for maximum parsing speed. This example is set up for maximum usability by humans who will use use the parser.
- A micro-grammer example that shows all the above.
A trivial example language which has integers, strings, arrays, and trivial expressions is included in order to show how to detect errors and print them in program context.
Compiling the Example
All you have to do is to CD to the directory where the source is and run make. It should build without error. If there are errors, confirm that all these programs are in your path: + bash + gnu make + g++ + flex + bison
And that g++ is at least 2014 standard capable.
Once the example is compiled, run
make tests
You should see compile errors (from my example grammar, not from c++) that tell you that the test.input file has an error because it uses a variable or an array instead of an integer constant as an array index.
Obviously, real languages require expressions of type integer for such things, but this is only a trivial example set up to show you how to detect and print useful error messages.
See EXAMPLE_RUNS.txt for what you should be seeing when you follow the above instructions.
Good luck!