|

|
| Example Grammars |
| Hex Literals |
This grammar shows how to define Hex Literals in your
grammar. The formats used for C++ and Visual Basic are included |
| Identifiers |
This is a very simple example which defines a common
identifier. |
| Numbers |
Besides identifiers, programming languages often contain
terminals for integer and floating point literals. This grammar defines both. |
| Simple |
This is a very "simple" grammar that was used
in the Visual Basic Example project. The grammar
contains a few basic statements as well as the rules for basic mathematical expressions.
|
| Strings |
One of the most common declarations used in programming
languages is the "string". In this example, a character set is defined and then
used to declare a standard string terminal. |
| Strings (C
style) |
The C programming language uses a backslash to define
special characters normally not accessible via the keyboard. This grammar shows how to
define a String terminal which will accept C style strings. |
| Operator
Precedence |
This grammar contains the basic rules needed to define
mathematical expressions. It includes the levels of operator precedence used in common
arithmetic. |
| Phone Number |
This is a very simple example that parses U.S./Canada
style phone numbers. |
| Programming Languages |
| ALGOL 60 |
ALGOL is, by far, the most influential programming
language developed to date. Although is did not achieve mass use, a large number of
syntactic and semantic principles and concepts were developed and incorporated into the
language. These include: block structure, free-form structure (elements are not
required to be in a specific column), pass by name and the For-Loop. As a result, ALGOL is
considered the main reference language in computer science. |
| BASIC 64 |
BASIC is one of the oldest programming language and one
of the most popular. It was developed in 1964 by John G. Kemeny and Thomas E. Kurtz
to teach students the basics of programming concepts. |
| C (ANSI) |
C was designed for the creation and implementation of
low-level systems such as operating systems, device drivers, firmware, etc... To realize
this goal, the language contains the ability to perform operations directly
on memory and has direct access to system pointers. While this gives an enormous amount of
control and flexibility, it also makes C a professional programming language - not
to be used by an inexperienced programmer. |
| C# |
Updated! C# was
primarily the work of computer scientist Anders Hejlsberg who has worked on a wide range
of programming languages. These include, but are not limited to, Visual J++, Borland
Delphi and Turbo Pascal. His previous works and influences from Java and C++ can be seen
in C#. The goal of C# was to counter the flaws and difficulties found in Java and C++.
In addition, the language was designed to work well with the Common Language Runtime which
runs the Microsoft .NET platform.
The grammar was designed, in part, using the official language specification that can
be found on the Microsoft website. As a result, considerable time was required to write a
LALR(1) compliant version. |
| COBOL 85 |
The COBOL programming language is one of the oldest still
in use today. It was originally designed by the United States Department of defense
under the supervision of the Conference on Data Systems Languages (CODASYL)
Committee. Most of the groundwork and design of COBOL was done by Admiral Grace Hopper of
the United States Navy. The COBOL 85 grammar is complex - containing, on average, over
350 reserved words, 950 rules which results in 1,681 LALR states. This is the full
grammar. |
Commodore
PET BASIC |
This version of the BASIC Programming Language was
implemented on the Commodore 64. I wrote this grammar to amuse myself and to remember the
fun I had on that 8-bit wonder. You can also download a True Type Font I created
that mimics the character set of the Commodore 64. This is a new version of the font that
will work for both PC and Macintosh (the old version didn't work that well).
|
| Delphi 7 |
Rob van den Brink, who authored the Object Pascal Engine,
created the grammar for the Delphi 7 Programming Language. Delphi was developed from the
concepts and syntax of Pascal and, its successor, Object Pascal.
|
| Java |
Dmitry Gazko has submitted a grammar for the Java
Programming Language This grammar is based on a partial conversion of Sun Java 1.0-2.0
specification.
|
| JavaScript |
Meinhard Schnoor-Matriciani submitted this grammar for
the JavaScript Programming Language. The grammar has a few shift-reduce warnings - mainly
due to the classic hanging else.
|
| LISP |
LISP is one of the oldest programming language in use
today; second only to FORTRAN. It was invented by mathematician John McCarthy and
organizes data into abstract "lists"; which are delimited by parenthesis. This
metaphor is used for both data and functions and yields a degree of orthogonality not seen
in most languages. |
| Pascal |
Alexander Grau submitted the grammar for the Pascal
Programming Language. Pascal was developed by Niklaus Wirth of the ETH Technical Institute
of Zuerich in 1970-1971.
|
| Smalltalk IV |
The Smalltalk programming language was developed at the
Xerox labs at Palo Alto in the mid 1970s. The language was built upon the object-oriented
model of Simula and designed to work directly with the newly developed concept of the
graphic user interface (GUI), To this day, Smalltalk is considered one of the
"purest" object-oriented programming languages. |
| SQL 89 (ANSI) |
The SQL programming language was developed as a uniform
means of modifying and querying relational databases. By using a single abstract language
to interact with the database, programs can be written that are independent of the vender
and format of the database itself. |
| VB
Script |
Updated! Vladimir
Morozov submitted a grammer for the Visual Basic Scripting Language - VB Script. This is a
version of Microsoft Visual Basic that can be used in webpages or for scripting tasks in
Windows. Vladimir Morozov worked with Nathan Baulch on a number of updates which take
into account some real-world scenaros. These include the use keywords as identifiers, the
use dot in front of identifiers in WITH statements (grammar allows to use them anywhere),
missed statements, parameteres for calling SUB, and much more.
|
| Visual Basic .NET |
Visual Basic .NET is the latest version in the long
evoluation of the BASIC programming language. The Visual Basic .NET programming
language is far more "clean" and orthagonal than its predecessors.
Although some of the old constructs exist, the language is far easier to read and write. Only
use GOLD Parser Builder version 2.1 and later to compile this grammar. Earlier versions
cannot handle the complexity. |
| Academic Languages |
| Brainf#ck |
As legend states, the Brainf#ck Programming Language
(also called BF by those not wanting to curse) was created by Urban Müller
in 1993. The language was designed, in part, so Müller
could create the smallest compiler ever. The first BF compiler was written for the
Commodore Amiga OS 2.0 and was only 240 bytes in size. The BF Programming Language only
consists of 8 different instructions, an array and a pointer. Note: This grammar was
written as an example. For such a simple syntax, it is far easier to manually write a
specialized parser. |
| PL/0 |
PL/0 is a simple programming language created by Niklaus
Wirth in his 1976 book Algorithms + Data Structures = Programs. Essentially, the
grammar is a subset of Pascal and Modula-2 (both which Niklaus Wirth created). Most
programming language features such as functions, parameters, looping statements, etc..
were removed.
|
| Oberon-00 |
"Oberon-00 is a simple programming language proposed
in [Wirth98] as a simple example of a common language that can be used for hardware
and software compilation. Such language could be used for research purposes in the field
of high-level synthesis (HLS) and as a testbed for hardware-software codesign. Oberon-00
is derived as a hardware-friendly subset of Oberon. This package contains both a regular
BNF grammar derived from the Oberon-00 EBNF, which can be used within the GOLD environment
and the original EBNF."
|
| File Formats |
| Cascading Style Sheets |
Cascading Style Sheets was originally proposed in 1994 by
Hakon Wium Lie during "Mosaic and the Web" conference in Chicago. Shortly
afterwards, Hakon Wium Lie teamed up with Bert Bos who was developing a web browser called
"Argo". Together the format of the first Cascading Style Sheets was developed
and, with Thomas Reardon of Microsoft, was submitted to the W3C Committee in late 1996. |
| Graphviz (aka Dot) |
This grammar, submitted by Richard Scheider, is for a
graph language from AT&T known by the names Graphviz and Dot.
|
| HTML |
This grammar requires little explanation - being the
dominant format used for websites. Like XML, HTML is a descendant of SGML
(Standardized General Markup Language). This grammar was mainly written as an example.
Those parsing HTML documents should incorporate a simple stack rather than using a parsing
system. |
| Javascript Object Notation |
JSON is a text file format that was created for
data-interchange between different programming languages. The conventions of the format is
based on the C programming language and, as a result, should be familliar to programmers
of C++, Java, and C#. This is basic version of the grammar, but it works.
|
| XML |
XML, like the commonly used HTML format, is a descendant
of SGML (Standardized General Markup Language). However, XML is not a descendant of HTML
and structural differences exist between the two formats. XML has been adopted by leading
software companies including Sun Microsystems and Microsoft for their SOAP framework. |
| Miscellaneous Grammars |
| Commandline
Argument |
This is a grammar submitted by Alex K. Angelopoulos that
is designed to be similar to the parsing performed by WScript.
|
GOLD Grammar
(Official) |
This is the official grammar that is used
internally by versions 2.6 and later of the GOLD Parser Builder.
|
GOLD Grammar
(Matt Hounsell) |
Mathew Hounsell submitted a grammar that parses the
Grammar Outline used by the Builder. This is a very clean design.
|
| Pokchi/J |
Christian Beaumont submitted a grammar he wrote called
"Pokchi/J". This grammar defines a JavaScript like language with some C# like
extensions.
|
| Regular
Expressions |
This very simple grammar will parse regular expressions.
Unlike the grammar used for the GOLD Builder scanner, this grammar treats each character
as a different token. |
| YACC |
One of the oldest and most respected parsing engine
generators available to developers is YACC. Like "vi" "grep" and
"awk", this software is considered the de facto standard in the UNIX
world. YACC, which is an acronym for Yet Another Compiler-Compiler, was developed by
Stephen C. Johnson at AT&T. YACC can be used to create parsers using the C and C++
programming languages. |
|