Metody realizacji języków programowania/MRJP Laboratorium/Scrap: Różnice pomiędzy wersjami

Z Studia Informatyczne
Przejdź do nawigacjiPrzejdź do wyszukiwania
Przemek (dyskusja | edycje)
Przemek (dyskusja | edycje)
Linia 158: Linia 158:
<td>''<ListDeklaracja>'' </td>
<td>''<ListDeklaracja>'' </td>
<td>::=  </td>
<td>::=  </td>
<td> </td>
<td> &epsilon;</td>
</tr>
</tr>
<tr>
<tr>
Linia 271: Linia 271:
</tr>
</tr>
<tr>
<tr>
<td> </td>
<td>|  </td>
<td>&epsilon;</td>
<td>&epsilon;</td>
<td>|  </td>
<td> </td>
</tr>
</tr>
<tr>
<tr>
Linia 281: Linia 281:
</tr>
</tr>
<tr>
<tr>
<td></td>
<td>| </td>
<td>
<td>
&epsilon;
&epsilon;
</td>
</td>
<td>|  </td>
<td>''<Instrukcja>'' ''<ListInstrukcja>''  </td>
<td>''<Instrukcja>'' ''<ListInstrukcja>''  </td>
</tr>
</tr>
Linia 434: Linia 435:
</tr>
</tr>
<tr>
<tr>
<td> </td>
<td>|  </td>
<td>|  </td>
<td>
<td>

Wersja z 14:58, 25 sie 2006


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 "x", where x 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:

; { }
= , :
( ) :=
[ ] .
- + !
* / <
> <= >=
== != ||
&&    

Comments

Single-line comments begin with {\symb{//}}. \\Multiple-line comments are enclosed with {\symb{(*}} and {\symb{*)}}.

The syntactic structure of kotek

Non-terminals are enclosed between and . The symbols  := (production), | (union) and ε (empty rule) belong to the BNF notation. All other symbols are terminals.


<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> ::= <
| >
| <=}
| >=
| ==
| !=
<WyrazenieLogiczne> ::= <WyrazeniePorownania> <OperatorLogiczny> <WyrazeniePorownania>
| <WyrazeniePorownania>
<OperatorLogiczny> ::= ||
| &&
<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> }