Skip to content
flofreud edited this page Apr 24, 2013 · 25 revisions

Grammar rules

Programm -> Decls Stmts
Decls -> Decls Decl | e
Decl -> Type id;
Type -> Basic
Stmts -> Stmts Stmt | e
Stmt -> Assign; | Return id;
Assign -> Expr
Expr -> Expr + Term | Expr - Term | Term
Term -> Term * Unary | Term / Unary | Unary
Unary -> ! Unary | - <Unary> | Factor
Factor -> num | real
```
Hier wurde die Grammatik von Unten verkürzt, dass wir die arithmitische Operatoren haben bis anfang Mai habe. die Grammatik bedeckt alle Fälle zu arithmitik wie ihr sieht und ist erweitarbar.

## Document Status: Draft / Work in Progress 
This article is a draft and work in progress. Feel free to comment and discuss on the [issue tracker](https://github.com/swp-uebersetzerbau-ss13/common/issues/5).  

## Remarks 
Several questions have to be addressed:

* What is the definition of  "id“, "num", "basic", "real" und "string"?
* What is the semantic of "if (assign)" for "assign" -> "loc = assign"?
* The grammar is ambiguous for "if else" (Dangling Else). How to solve it (prioritoes)?
* What is the difference between "id" and "loc.id" for "loc"?
* What is the semantic for "break" outside of a loop?

(Author: Sven, Translator: Flo) 

## Grammar rules
The provided grammmar can be found here:
<https://github.com/swp-uebersetzerbau-ss13/common/blob/master/doc/quellsprache.pdf?raw=true>

```
program -> decls stmts
block -> {decls stmts}
decls -> decls decl | ϵ
decl -> type *id*;
type -> type [*num*] | *basic* | *record* {decls}
stmts -> stmts stmt | ϵ

stmt -> assign;
     | *if*(assign) stmt
     | *if*( assign ) stmt *else* stmt
     | *while*( assign ) stmt
     | *do* stmt *while* ( assign );
     | *break*;
     | *return*;
     | *return* loc;
     | *print* loc;
     | block
loc -> loc [assign] | *id* | loc.*id*

assign -> loc=assign | bool
bool -> bool||join | join
join -> join&&equality | equality
equality -> equality==rel | equality!=rel | rel
rel -> expr<expr | expr<=expr | expr>=expr | expr>expr | expr
expr -> expr+term | expr-term | term
term -> term*unary | term/unary | unary
unary -> !unary | -unary | factor
factor -> (assign) | loc | *num* | *real* | *true* | *false* | *string*

basic -> long | double | string | bool

string -> " (.*) " //?? escaping?

id -> ...
```

Note: \*...\* marks terminals

## terminal definition

```
digit -> [0-9]
digits -> digit+
integralDigits -> -? digits
exponent -> ((e | E) integralDigits)
num -> digits exponent?
real -> digits . digits exponent?
basic -> (long | double | string | bool)
alpha -> [a-zA-Z]
alphaNumeric -> [a-zA-Z0-9]
id -> alpha alphaNumeric*

```

## Regular expressions
```
NUM("[0-9]+((E|e)(-)?[0-9]+)?")
REAL("[0-9]+(\.)[0-9]+((E|e)(-)?[0-9]+)?")
TRUE("true")
FALSE("false")
STRING("\\"[^\\"]*\\"")
ID("^[a-zA-Z_][a-zA-Z0-9_]*")
IF("if")
ELSE("else")
WHILE("while")
DO("do")
BREAK("break")
RETURN("return")
PRINT("print")
ASSIGNOP("\=")
EQUALOP("['==''!=']")
BOOLOP("['||''&&']")
RELOP("['<''<=''>=''>']")
ARITHMOP("[+-*/]")
UNARYOP("[!-]")
```

## Semantic
Definition of semantic of each term (if necessary)
Clone this wiki locally