|
Úvod
File->Program
File->Unit
Program->Body Block "."
Body->"uses" Uses Body
Body->"program" LEX ";" Body
Body->"type" TypeDef Body
Body->"var" Var Body
Body->"const" Constant Body
Body->Function Body
Body->Procedure Body
Body->epsilon
Uses->LEX Uses2
Uses2->"," IdUnit Uses2
Uses2->";"
TypeDef->Identifier "=" Type ";" TypeDef
Var->Identifier ":" Type ";" Var
Function->FunctionDefinition FunctionBody
FunctionDefinition->"function" Identifier Parameter ":" Type ";"
FunctionBody->"assembler" ";" Asm
FunctionBody->Block
Procedure->ProcedureDefinition ProcedureBody
ProcedureDefinition->"procedure" Identifier Parameter ";"
ProcedureBody->"assembler" ";" Asm
ProcedureBody->Block
Parameter->epsilon
Parameter->"(" IdentifierArray ":" Type Parameter2 ")"
IdentifierArray->Identifer IdentifierArray2
IdentifierArray2->epsilon
IdentifierArray2->"," Identifier ":" Type IdentifierArray2
Asm->"asm" Data "end"
Data->LEX Data
Block->"begin" Block2
Block2->Command ";" Block2
Block2->Command "end"
Command->If
Command->While
Command->RepeatUntil
Command->For
Command->Calling
Command->Assign
Command->Block
Command->Asm
Command->epsilon
If->"if" Term "then" Command Else
Else->epsilon
Else->"else" Command
While->"while" Term "do" Command
RepeatUntil->"repeat" RepeatUntil2
RepeatUntil2->Command RepeatUntil2
RepeatUntil2->"until" Term
For->"for" Assign For2
For2->"downto" Term "do" Command
For2->"to" Term "do" Command
Calling->Identifier CallingParameter
CallingParameter->epsilon
CallingParameter->"(" Term CallingParameter2
CallingParameter2->")"
CallingParameter2->"," Term CallingParameter2
Assign->Identifier ":=" Term
Unit->"unit" Identifier ";" UnitHead UnitBody UnitMain
UnitHead->"uses" Uses UnitHead
UnitHead->"const" Constant UnitHead
UnitHead->"type" Typedef UnitHead
UnitHead->"var" Var UnitHead
UnitHead->FunctionDefinition UnitHead
UnitHead->ProcedureDefinition UnitHead
UnitHead->"implementation"
UnitBody->Function
UnitBody->Procedure
UnitBody->epsilon
UnitMain->"end" "."
UnitMain->Block "."
Constant->Identifier Constant2
Constant2->":" Type "=" LEX ";"
Constant2->"=" LEX ";"
Type->"byte"
Type->"char"
Type->"shortint"
Type->"word"
Type->"integer"
Type->"longint"
Type->"real"
Type->"single"
Type->"double"
Type->"extended"
Type->"comp"
Type->"char"
Type->"string"
Type->"boolean"
Type->"file"
Type->"text"
Type->"pointer"
Type->"array" "[" Term ".." Term "]" "of" Type
Identifier->LEX Identifier2
Identifier->"[" Term Identifier2
Identifier2->"," Term2
Identifier2->"]" Identifier3
Identifier3->"." Identifier
Identifier3->epsilon
Term->B A
A-> "<" B A
A-> ">" B A
A-> "=" B A
A-> ">=" B A
A-> "<=" B A
A-> "<>" B A
A-> "in" Sada A
A->epsilon
B->D C
C->"+" D C
C->"-" D C
C->"or" D C
C->"xor" D C
C->epsilon
D->F E
E->"*" F E
E->"/" F E
E->"div" F E
E->"mod" F E
E->"and" F E
E->"shl" F E
E->"shr" F E
E->epsilon
F->"@" G
F->"not" G
F->"+" G
F->"-" G
F->G
G->Calling // pouze funkce
G->Identifier // konstanta/proměnná/volání funkce
G->"(" Term ")"
Tato gramatika popisuje vše co překladač umí. LEX je označen lexikální element, bez další specifikace.
Gramatika ovšem nebere v úvahu sémantický smysl jednotlivých pravidel. Ty jsou řešeny až přímo ve vnitřní podobě (některé jsou naznačeny za //).
Z praktického hlediska při vytváření stromu jsem pří detekování Command přešel na LL(2), viz. Calling<>Assign.
|
|
|