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)
 
(Nie pokazano 10 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 130: Linia 130:


===Comments===
===Comments===
Single-line comments begin with {\symb{//}}. \\Multiple-line comments are  enclosed with {\symb{(*}} and {\symb{*)}}.
Single-line comments begin with <tt>//</tt>.  
Multiple-line comments are  enclosed with <tt>(*</tt> and <tt>*)</tt>.


==The syntactic structure of kotek==
==The syntactic structure of kotek==
Linia 158: Linia 159:
<td>''<ListDeklaracja>'' </td>
<td>''<ListDeklaracja>'' </td>
<td>::=  </td>
<td>::=  </td>
<td> </td>
<td> &epsilon;</td>
</tr>
</tr>
<tr>
<tr>
Linia 196: Linia 197:
<td>''<DeklaracjaTypu>'' </td>
<td>''<DeklaracjaTypu>'' </td>
<td>::=  </td>
<td>::=  </td>
<td><tt>'''type'''</tt> ''<Ident>'' <tt>{<math>=</math></tt>} ''<OpisTypu>''  </td>
<td><tt>'''type'''</tt> ''<Ident>'' <tt><math>=</math></tt> ''<OpisTypu>''  </td>
</tr>
</tr>
<tr>
<tr>
Linia 271: Linia 272:
</tr>
</tr>
<tr>
<tr>
<td>
<td> </td>
 
</td>
<td>|  </td>
<td>|  </td>
<td> </td>
<td>&epsilon;</td>
</tr>
</tr>
<tr>
<tr>
<td>''<ListInstrukcja>'' </td>
<td>''<ListInstrukcja>'' </td>
<td>::=  </td>
<td>::=  </td>
<td> </td>
<td>
&epsilon;
</td>
</tr>
</tr>
<tr>
<tr>
<td>
<td></td>
<td>| </td>


</td>
<td>|  </td>
<td>''<Instrukcja>'' ''<ListInstrukcja>''  </td>
<td>''<Instrukcja>'' ''<ListInstrukcja>''  </td>
</tr>
</tr>
Linia 306: Linia 306:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td>''<WyrazeniePostfiksowe>'' <tt>:{<math>=</math></tt>} ''<Wyrazenie>'' <tt>;</tt>  </td>
<td>''<WyrazeniePostfiksowe>'' <tt>:<math>=</math></tt> ''<Wyrazenie>'' <tt>;</tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 395: Linia 395:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt'''super'''</tt>  </td>
<td><tt>'''super'''</tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 433: Linia 433:
<td>''<Parametry>'' </td>
<td>''<Parametry>'' </td>
<td>::=  </td>
<td>::=  </td>
<td> </td>
<td>
&epsilon;
</td>
</tr>
</tr>
<tr>
<tr>
<td>
<td> </td>
<td>|  </td>


</td>
<td>|  </td>
<td>''<ListWyrazenie>''  </td>
<td>''<ListWyrazenie>''  </td>
</tr>
</tr>
Linia 469: Linia 470:
<td>''<OperatorUnarny>'' </td>
<td>''<OperatorUnarny>'' </td>
<td>::=  </td>
<td>::=  </td>
<td><tt>{<math>-</math></tt>} </td>
<td><tt><math>-</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 476: Linia 477:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt>{<math>+</math></tt>} </td>
<td><tt><math>+</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 524: Linia 525:
<td>''<OperatorAddytywny>'' </td>
<td>''<OperatorAddytywny>'' </td>
<td>::=  </td>
<td>::=  </td>
<td><tt>{<math>+</math></tt>} </td>
<td><tt><math>+</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 531: Linia 532:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt>{<math>-</math></tt>} </td>
<td><tt><math>-</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 548: Linia 549:
<td>''<OperatorPorownania>'' </td>
<td>''<OperatorPorownania>'' </td>
<td>::=  </td>
<td>::=  </td>
<td><tt>{<math><</math></tt>} </td>
<td><tt><math><</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 555: Linia 556:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt>{<math>></math></tt>} </td>
<td><tt><math>></math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 562: Linia 563:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt>{<math><</math>}{<math>=</math>}}</tt>  </td>
<td><tt><math><=</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 569: Linia 570:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td>{\terminal{{<math>></math>}{<math>=</math>}}} </td>
<td><tt><math>>=</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 576: Linia 577:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td>{\terminal{{<math>=</math>}{<math>=</math>}}} </td>
<td><tt><math>==</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 583: Linia 584:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td><tt>!{<math>=</math></tt>} </td>
<td><tt>!<math>=</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 600: Linia 601:
<td>''<OperatorLogiczny>'' </td>
<td>''<OperatorLogiczny>'' </td>
<td>::=  </td>
<td>::=  </td>
<td>{\terminal{{<math>|</math>}{<math>|</math>}}} </td>
<td><tt><math>||</math></tt>  </td>
</tr>
</tr>
<tr>
<tr>
Linia 607: Linia 608:
</td>
</td>
<td>|  </td>
<td>|  </td>
<td>{\terminal{\</td>
<td><tt>&&</tt></td>
<td>\</td>
<td>}}  </td>
</tr>
</tr>
<tr>
<tr>
Linia 652: Linia 651:
<td>''<DeklaracjaKlasy>'' </td>
<td>''<DeklaracjaKlasy>'' </td>
<td>::=  </td>
<td>::=  </td>
<td><tt>'''class'''</tt> ''<Ident>'' <tt>extends</tt> ''<Ident>'' <tt>\{</tt> ''<ListDeklaracja>'' <tt>\</tt>} </td>
<td><tt>'''class'''</tt> ''<Ident>'' <tt>'''extends'''</tt> ''<Ident>'' <tt>{</tt> ''<ListDeklaracja>'' <tt>}</tt>  </td>
</tr>
</tr>
<tr>
<tr>

Aktualna wersja na dzień 15:07, 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 //. Multiple-line comments are enclosed with (* and *).

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> }