Manual - mszczodrak/swift-fox GitHub Wiki

Lexical Conventions

In the Swift Fox language, a program consists of one or more translation units stored into different files. In the following section, we present the primitive constructs that are used throughout the first phase of the translation, namely the lexical analysis. During that phase, the source code of a Swift Fox program is considered to be a stream of characters that is fed into the lexical analyzer (lexer). Subsequently, the lexer1 groups sequences of characters together and identifies tokens. Each token is a pair of a name and a value; the value corresponds to a particular lexeme that is identified by the regular expression for the corresponding token, whereas the name is merely an identifier for abstracting the set of lexemes (i.e., referring to the language of lexemes that are described by the same regular expression)

token: < token name, token value > (e.g., < identifier, blink >)

Tokens

Tokens in Swift Fox, similarly to every other language, are composed by sequences of characters. The lexer (i.e., lexical analyzer) produces four classes of tokens:

  • identifiers
  • keywords
  • constants
  • operators Additionally, the whitespace character class is used in order to separate the various tokens. The following characters are considered whitespace and along with comments are ignored throughout the rest phases of the translation.
  • space
  • horizontal tab
  • vertical tab
  • form feed
  • carriage return Notice, however, that newlines are not considered whitespace and they have a special meaning in Swift Fox.

Comments

Comments are introduced by character # and terminate with a newline. Everything between the comment character and the newline character is considered to be a comment, and therefore it is ignored. Comments must start on a new line, and can only be preceded by a delimiter, but not a line of a Swift Fox code.

Identifiers

Identifiers in Swift Fox are sequences of letters, digits, and character “ ”. They are used in order to name specific instances of the primitive types that the language provides (see Section 3.3.1) and, hence, they are considered to be variables. Identifiers can be of arbitrary length but not zero (i.e., there is no such thing as the “empty” identifier). Moreover, the first character of an identifier cannot be a number; it must be either a letter, or character “ ”. Finally, identifiers are case sensitive and have a number of characters that are considered to be significant.

Identifiers in Swift Fox are only used for naming objects (e.g., applications, networks, sources, configurations, event-conditions) and referring to them. The binding between a name and the corresponding object is performed during the declaration of the identifier and remains the same for the rest of the program. For example, Swift Fox does not allow a user to change a configuration variable and assign a different configuration to it. The scope of all identifiers is, therefore, the same and it global (for a particular program). Similarly, the lifetime of all identifiers is the same and it is equal to the lifetime of the Swift Fox program.

Keywords

Swift Fox uses a set of special-meaning identifiers, namely keywords, which cannot be used otherwise. Below is the list of all the “reserved” words that are used in Swift Fox.

  • use
  • source
  • from
  • and
  • application
  • configuration
  • conf
  • goto
  • any
  • start
  • network
  • event
  • when

Syntax Notation

In this section we define the syntactic constructs that are used in Swift Fox language. The syntactic analysis is the bulk part of the second phase of the translation procedure. During that phase, a stream of tokens, which is provided by the lexer, is checked for adherence to Swift Fox rules. In other words, the source code is tested for conformity to the syntactic rules that are defined by the formal grammar of the language. The result of this procedure is an annotated parse tree of the program along with a special data structure that keeps information about each identifier (i.e., the symbol table).

Types

Swift Fox is a strongly typed language where type checking occurs only at compile time. The simplistic nature of Swift Fox syntax prevents type intermixing without loss of expressibility. The benefits of this approach are manifold. First, the language does not need to involve additional complexity with runtime checks. Notice that the execution environment of Swift Fox is severely constrained and any runtime type check will not only impact the performance of the system, but also drain the available power supply. Second, it allows strong guarantees about the runtime behavior of the program since there are no explicit or implicit type conversions. Third, it guards against evasions of the type system that can lead to unpredictable behavior.

Swift Fox is also a static typed language. This allows the optimal selec- tion of the storage needed for the various Swift Fox objects. This is, again, of paramount importance for the over constrained application domain of Swift Fox. The primitive types that define the building blocks of the language are the following:

  • application - This primitive type is used in order to define application components (e.g., Blink, Collector)
  • network - Similarly to the previous type, network is used in order to define network components (e.g., CTP or P2P-MultiHop)
  • source - Defines event sources (e.g., temperature readings, timeouts)
  • configuration - Configuration defines a specific binding among in- stances of the different classes of components that are provided by Fennec Fox)
  • event - Event-condition associates events with specific conditions (e.g., temperature > 90)

Operators

The operators used in Swift Fox can be classified as relational, logical, or enumerative. Relational operators are used in order to define an event- condition and they evaluate to true or false. Infix operators < (less), > (greater), <= (less or equal), >= (greater or equal), and = (equal) yield 0, if the relation that corresponds to a specific condition is false, and 1 if it is true. The infix logical operators and and or are used in order to combine two or more event-conditions conjunctively or disjunctively, whereas the infix comma (,) operator is used among two or more configurations in order to create a set from them. The not operator works as negation operator and takes one argument of type event. The return value of the not operator is an event which becomes true when the argument event is false. The and operator takes two arguments of type event and returns an event which is true when both argument events are true. The or operator takes two arguments of type event and returns two events that are true if either one of the argument events is true. To improve readability, in every statement we allow to use maximum one or operator. The number of not and and operators is unlimited. Finally, the not operator has higher precedence than the operator and, and operator or has the lowest precedence.

Separators

Separators are special characters that are used in Swift Fox in order to segregate various statements. Currently, Swift Fox uses only one separator: the newline (LF). Hence, library declaration statements, configuration and event-condition declaration statements, and policy and initial-configuration statements are separated from each other using newline characters.

Advance Operations

⚠️ **GitHub.com Fallback** ⚠️