-
Notifications
You must be signed in to change notification settings - Fork 0
Grammar
Programm -> Decls stmts
Decls -> Decls Decl |e
Decl -> Type id
Type -> Basic
Stmts -> Stmts Stmt |e
Stmt -> Assign
Assign -> Expr
Expr -> Expr + Term
| Expr - Term
| Term
Term -> Term * Unary
| Term / Unary
| Unary
Unary -> not Unary
| minus <Unary>
| Factor
Basic -> long
| double
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.
This article is a draft and work in progress. Feel free to comment and discuss on the issue tracker.
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)
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
digit -> [0-9]
digits -> digit+
integralDigits -> -? digits
exponent -> ((e | E) integralDigits)
num -> digits
real -> digits . digits exponent? | digits exponent
basic -> (long | double | string | bool)
alpha -> [a-zA-Z]
alphaNumeric -> [a-zA-Z0-9]
id -> alpha alphaNumeric*
Definition of semantic of each term (if necessary)