Download An Eclipse-Based Integrated Development Environment for Curry

Transcript
5.2 The Grammar
At the end of this section, we present an Xtext-grammar which can be used to generate an IDE that parses Curry modules correctly, this is, it detects syntactical errors.
However, semantic errors are not detected. This kind of validation is the topic of Section 5.4.
5.2.1 Lexicon
A lexicon is a set of words that serves as the basis for any syntax. The syntax defines
valid combinations of words from the lexicon by grammar rules. Before we start to
develop the grammar for Curry, we have to define the lexicon:
Curry’s lexicon is defined as follows [Han12]:
• Every word beginning with a letter followed by any number of letters, digits, underscores, and single quotes, these words are called identifiers (ID)
• Any string of characters from the string “˜!@#$%ˆ&*+-=<>?./|\:“, we call these
words infix operators 4
• Any word from (ID) enclosed in ’...’ like ’mod’ is also called infix operator
• The strings “(“, “)”, “[“, “]”, “@”, “{“, “}”, “;”, “{-” and “-}”, newlines, and whitespaces
(blanks and tabs)
• Strings, characters, numbers, and floats like ”abc”, ’a’, 36, and 3.14159.
Moreover, the case of words matters, so that abc and Abc are two unequal identifiers.
Curry supports four case modes which define different constraints on the case of particular identifiers. The modes are prolog mode, gödel mode, haskell mode, and free mode.
We implement the haskell mode, later it may be possible to weaken the constraints
towards free mode. This seems to be a good approach, because the constraints prohibit
ambiguities and, hence, facilitate the parsing.
As the name suggests, the haskell mode corresponds to the definitions for the lanuguage
Haskell. The Haskell Report 2010 [Mar] defines the identifiers as follows:
There are six kinds of names in Haskell: those for variables and constructors denote
values; those for type variables, type constructors, and type classes refer to entities related to the type system; and module names refer to modules. There are two constraints
on naming:
Names for variables and type variables are identifiers beginning with lowercase letters
or underscore; the other four kinds of names are identifiers beginning with uppercase
letters.
4
There are some exceptions which are mentioned later.
41