| Coco / R | |
|---|---|
| Type of | Parser / scanner generator |
| Author | Hanspeter Mössenböck and others |
| Hardware platform | Cross platform |
| License | GNU GPL |
| Site | ssw.jku.at/Coco/ |
Content
Introduction
Soso / R - a program for generating compilers or interpreters of the language. The program reads a file with attributive grammar of the implemented language, described in the form of RBNF ( Extended Backus-Naura Form , EBNF) and generates a number of files:
- sources of the lexical analyzer (scanner); works like a state machine.
- sources of the parser; uses a descending recursive descent technique.
- information files (log, table of language tokens).
Using Soso / R is very simple. The code generated by the program is fast and easy to understand.
The program itself is already implemented in many languages, and generates the source code of the compiler in many languages as well. There are versions of Soso / R that create sources in Java, C ++, C #, Delphi, Pascal, Ada, Modula-2, Modula-3, Oberon, Component Pascal and other languages.
Developing your own language is to develop a language grammar file. A special kind of commentary (..) Is added to the grammar of the language, in which the code is enclosed to perform additional actions. As a rule, this is a code for entering data into identifier tables, generating code or interpreting it.
Soso / R version for C # language
The input file for Soso / R has the extension .ATG and contains language character sets, tokens, and language products that describe the structure of the compiled language and insertions in C #.
Soso / R generates scanner and parser classes in C # (Scanner.cs, Parser.cs). An error handler is also automatically created (it is part of Parser.cs), which subsequently allows you to display a list of errors when analyzing user programs with their locations . Thus, the program for the automated generation of Soso / R compilers greatly simplifies the process of creating compilers.
Example
In this case, Soso / R describes the grammar of the form:
- S -> aU | bV
- U -> bV | bS | e
- V -> a | b
- U -> bV | bS | e
COMPILER CLN // language name
public system . Windows Forms TextBox text ; // name of the text box in our compiler in the language it is written in (C #)
public string Production = "" ; // variable in the compiler program with the products
public string Conditions = "" ;
public string dd ; // intermediate line
CHARACTERS // section, which describes valid characters, divided into groups
Blet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . // capital letters
Slet = "abcdefghijklmnopqrstuvwxyz" . // small ..))
TOKENS // tokens, they are tokens. Structural units of which the described compiler input language consists
Unterminal = Blet . // for example, nonterminals can be any letter and group described above as Blet, i.e. all capital letters
Product = Slet { Blet | Slet }. // similarly, products consist of one small letter and then the nth number of uppercase and lowercase letters (en from 0 to infinite)
Cr = '\ r' | '\ n' . // possible options for the end of the line
goto = "->" . // arrow
Divider = "|" . // product separator
COMMENTS FROM "//" TO '\ n' // comments - will be ignored
IGNORE '\ t' + '' // list of ignored characters, in this case tabs and spaces
PRODUCTIONS // section describing the structure of the input language of the compiler, in this case, grammar)
CLN = // start of description, described as a set of tokens described above. in curly brackets, as above - means that the piece may not be, but may be from 1 to many times)
// in square brackets (not here ..) - either 0 or 1 time)
{
Unterminal (. Conditions + = t . Val ;. )
goto
Product (. Production + = t . Val + "" ; .)
{
Divider
Product (. Production + = t . Val + "" ; .)
}
(. Production + = '\ n' ;.) // in (..) There are inserts in the final language (si sharpe), which without change will be transferred to the parser and scanner
{ Cr }
}.
END CLN . // end of description
Links
- The Compiler Generator Coco / R (inaccessible link) . Date of treatment March 11, 2009. Archived March 7, 2009.
- Ada Coco / R - User Guide . Archived March 3, 2012.