Metody realizacji języków programowania/MRJP Laboratorium/Scrap
The lexical structure of kotek
Identifiers
Identifiers Ident are unquoted strings beginning with a letter, followed by any combination of letters, digits, and the characters _ ', reserved words excluded.
Literals
String literals <String> have the form "", where is any sequence of any characters except " unless preceded by \.
Integer literals <Int> are nonempty sequences of digits.
Reserved words and symbols
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
The reserved words used in kotek are the following:
array | class | delete |
do | done | else |
endif | extends | function |
if | int | new |
null | of | program |
read | return | string |
super | then | this |
type | var | void |
while | write |
The symbols used in kotek are the following:
; | { | } |
= | , | : |
( | ) | := |
[ | ] | . |
- | +} | ! |
* | / | <} |
> | <= | >= |
== | != | || |
&& |
Program | ::= | program ; Cialo | ||
Cialo | ::= | ListDeklaracja Blok | ||
Blok | ::= | \{ ListInstrukcja \} | ||
ListDeklaracja | ::= | |||
| | Deklaracja ListDeklaracja | |||
Deklaracja | ::= | DeklaracjaTypu | ||
| | DeklaracjaZmiennej | |||
| | DeklaracjaFunkcji | |||
| | DeklaracjaKlasy | |||
DeklaracjaTypu | ::= | type Ident {} OpisTypu | ||
OpisTypu | ::= | Ident | ||
| | \{ ListDeklaracjaZmiennej \} | |||
| | array of Typ | |||
ListDeklaracjaZmiennej | ::= | DeklaracjaZmiennej | ||
| | DeklaracjaZmiennej , ListDeklaracjaZmiennej | |||
Typ | ::= | Ident | ||
| | string | |||
| | int | |||
| | void | |||
DeklaracjaZmiennej | ::= | var Ident : Typ | ||
DeklaracjaFunkcji | ::= | function Ident ( DeklaracjaArgumentow ) : Typ Cialo | ||
DeklaracjaArgumentow | ::= | ListDeklaracjaZmiennej | ||
| | ||||
ListInstrukcja | ::= | |||
| | Instrukcja ListInstrukcja | |||
Instrukcja | ::= | Wyrazenie ; | ||
| | ZlozonaInstrukcja ; | |||
| | WyrazeniePostfiksowe :{} Wyrazenie ; | |||
| | Blok | |||
| | delete Wyrazenie ; | |||
| | ; | |||
| | read Ident ; | |||
| | write Wyrazenie ; | |||
| | return Wyrazenie ; | |||
| | return ; | |||
WyrazeniePodstawowe | ::= | Ident | ||
| | String | |||
| | Integer | |||
| | ( Wyrazenie ) | |||
| | this | |||
| | super | |||
| | null | |||
WyrazeniePostfiksowe | ::= | WyrazeniePostfiksowe [ Wyrazenie ] | ||
| | WyrazeniePostfiksowe ( Parametry ) | |||
| | WyrazeniePostfiksowe . Ident | |||
| | WyrazeniePodstawowe | |||
Parametry | ::= | |||
| | ListWyrazenie | |||
ListWyrazenie | ::= | Wyrazenie | ||
| | Wyrazenie , ListWyrazenie | |||
WyrazenieUnarne | ::= | OperatorUnarny WyrazenieUnarne | ||
| | WyrazeniePostfiksowe | |||
OperatorUnarny | ::= | {} | ||
| | {} | |||
| | ! | |||
WyrazenieMultiplikatywne | ::= | WyrazenieMultiplikatywne OperatorMultiplikatywny WyrazenieUnarne | ||
| | WyrazenieUnarne | |||
WyrazenieAddytywne | ::= | WyrazenieAddytywne OperatorAddytywny WyrazenieMultiplikatywne | ||
| | WyrazenieMultiplikatywne | |||
OperatorMultiplikatywny | ::= | * | ||
| | / | |||
OperatorAddytywny | ::= | {} | ||
| | {} | |||
WyrazeniePorownania | ::= | WyrazenieAddytywne OperatorPorownania WyrazenieAddytywne | ||
| | WyrazenieAddytywne | |||
OperatorPorownania | ::= | {} | ||
| | {} | |||
| | {\terminal{{}{}}} | |||
| | {\terminal{{}{}}} | |||
| | {\terminal{{}{}}} | |||
| | !{} | |||
WyrazenieLogiczne | ::= | WyrazeniePorownania OperatorLogiczny WyrazeniePorownania | ||
| | WyrazeniePorownania | |||
OperatorLogiczny | ::= | {\terminal{{}{}}} | ||
| | {\terminal{\ | \ | }} | |
Wyrazenie | ::= | WyrazenieLogiczne | ||
| | new Typ | |||
| | new Typ [ Wyrazenie ] | |||
ZlozonaInstrukcja | ::= | if Wyrazenie then ListInstrukcja else ListInstrukcja endif | ||
| | if Wyrazenie then ListInstrukcja endif | |||
| | while Wyrazenie do ListInstrukcja done | |||
DeklaracjaKlasy | ::= | class Ident extends Ident \{ ListDeklaracja \} | ||
array | class | delete |
do | done | else |
endif | extends | function |
if | int | new |
null | of | program |
read | return | string |
super | then | this |
type | var | void |
while | write | |
The symbols used in kotek are the following: \\
array | class | delete | ||
do | done | else | ||
endif | extends | function | ||
if | int | new | ||
null | of | program | ||
read | return | string | ||
super | then | this | ||
type | var | void | ||
while | write | |||
; | \{ | \} | ||
{} | , | : | ||
( | ) | :{} | ||
[ | ] | . | ||
{} | {} | ! | ||
* | / | {} | ||
{} | {\symb{{}{}}} | {\symb{{}{}}} | ||
{\symb{{}{}}} | !{} | {\symb{{}{}}} | ||
{\symb{\ | \ | }} | ||