0% found this document useful (0 votes)
27 views6 pages

Scala Syntax Summary

This document summarizes Scala syntax elements including types, expressions, and definitions. Types can be simple types like Int and Double, function types, and more complex types will be introduced later. Expressions include identifiers, literals, function applications, operators, conditionals, blocks and anonymous functions. Definitions include function definitions, value definitions, parameters which can be call-by-value or call-by-name.

Uploaded by

mcraciun
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Scala Syntax Summary

This document summarizes Scala syntax elements including types, expressions, and definitions. Types can be simple types like Int and Double, function types, and more complex types will be introduced later. Expressions include identifiers, literals, function applications, operators, conditionals, blocks and anonymous functions. Definitions include function definitions, value definitions, parameters which can be call-by-value or call-by-name.

Uploaded by

mcraciun
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Scala Syntax Summary

Language Elements Seen So Far:


We have seen language elements to express types, expressions and denitions. Below, we give their context-free syntax in Extended Backus-Naur form (EBNF), where
| denotes an alternative, [...] an option (0 or 1), {...} a repetition (0 or more).

Types
Type = SimpleType | FunctionType FunctionType = SimpleType = > Type | ( [ Types ] ) = > Type SimpleType = Ident Types = Type { , Type }

A type can be:


A numeric type: Int, Double (and Byte, Short, Char, Long,


Float),

The Boolean type with the values true and false, The String type, A function type, like Int => Int, (Int, Int) => Int.

Later we will see more forms of types.

Expressions
Expr = | InfixExpr = Operator = PrefixExpr = SimpleExpr = | FunctionExpr = Bindings = | Binding = Block = InfixExpr | FunctionExpr if ( Expr ) Expr else Expr PrefixExpr | InfixExpr Operator InfixExpr ident [ + | - | ! | ~ ] SimpleExpr ident | literal | SimpleExpr . ident Block Bindings = > Expr ident [ : SimpleType ] ( [ Binding { , Binding }] ) ident [ : Type ] { { Def ; } Expr }

Expressions (2)
An expression can be:

An identier such as x, isGoodEnough, A literal, like 0, 1.0, abc, A function application, like sqrt(x), An operator application, like -x, y + x, A selection, like math.abs, A conditional expression, like if (x < 0) -x else x, A block, like { val x = math.abs(y) ; x * 2 } An anonymous function, like x => x + 1.

Denitions
Def FunDef ValDef Parameter Parameters = FunDef | ValDef = def ident { ( [ Parameters ] ) } [ : Type ] = Expr = val ident [ : Type ] = Expr = ident : [ = > ] Type = Parameter { , Parameter }

A denition can be:


A function denition, like def square(x: Int) = x * x A value denition, like val y = square(2)

A parameter can be:


A call-by-value parameter, like (x: Int), A call-by-name parameter, like (y: => Double).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy