.


:




:

































 

 

 

 





compiller-2main -- Syntax_Analiz_1

|

NextLexema

|

p_progisWordInsertGIT

|

p_varNextLexisWordisOperatorGetTypeByWordInsertGIT

|

p_funcisWordSyntax_Analiz_1

|

p_begisOperator--insertBlock

|

p_enderror

4.4

 

:

1.

2.

3.

4.

5.

6.

 

4.5

lpdgram *p_block(int b)

{ :

: ( )

:

}

lpdgram p_codeline(int b)

{ :

: ( )

: Pascal

}

int getnumArg(int f)

{ :

:

: ,

}

operations operationType(char * op, int block)

{ : () ,

:

:

}

lpdgram initDgram(operations type, int ext, lpdgram left, lpdgram right)

{ : , ( ) ( ),

:

:

}

void dropDgram(lpdgram Dgram)

{ :

:

: -

}

void atLexima(int sl, int sw)

{ :

:

:

}

void rewindLexima(void)

{ :

:

:

}

char * nextLexima(void)

{ :

:

:

}

 

int Delimeter(char * line)

{ :

:

:

}

 

int isOperator(char * line)

{ :

:

: , line , , , -1

}

int isKeyWord(char * line)

{ :

:

: , line , ,

}

BOOL Syntax_Analiz_1(void)

{ :

: true , false

: ,

}

void p_program(void)

{ :

:

: program GIT (Global Ident Table)

}

void p_var(int _ext)

{ : : ,

:

: var GIT (Global Ident Table)

}

void p_function(void)

{ :

:

: function GIT (Global Ident Table)

}

void p_begin(void)

{ :

:

: begin, , ,

}

void p_end(void)

{ :

:

: begin

}

BOOL p_other_sym(char * lex)

{ : lex

: true , false

: (;)

}

BOOL insertGIT(char * lex, IdentTypes type, unsigned int ext, unsigned long val)

{ : , , : , ,

:

:

}

int searchGIT(char * name)

{ :

: , -1

: , .

}

int searchGITfrom(char * name, int _from)

{ : ; ,

: , -1

: ,

}

int searchGITblock(char * name, int block)

{ : ; ,

: , -1

: ,

}

int searchGITto(char * name, int block)

{ : ; ,

: , -1

: , ,

}

int insertBlock(int varIdx)

{ :

:

:

}

void addBlockStart(void)

{ :

:

:

}

void addBlockEnd(void)

{ :

:

:

}

void freeGIT(void)

{ :

:

:

}

void freeBlock(void)

{ :

:

:

}

BOOL isWord(char * tmp)

{ :

: true , , false .

: , tmp

}

int GetIdentTypeByWord(char * type)

{ :

: -1 ,

: (integer)

}

 

4.6

:

  Error in program structure detected, may be an `;' expected  
  Unexpected end-of-file detected  
  Error detected during compilation... Stopped...  
  Error unexpected end-of-file at line  
  program name must be a word  
  Wrong type definition, may be expected `:'  
  Invalid identificator name  
  expected type declaration  
  Function must have some name  
  Here must be variable or const definition  
  `;' Expected  
  `:' Expected  
  Function type specific-word must be a WORD!  
  Unknown type definition  
  Begin expected  
  Syntax error: Dublicate identificator  
  unknow identificator  
  Boolean operation dont supported  

5.1.1

test.pas:

program test;

var x:integer;

cy,h,c:integer;

function f(x:integer; var i,j:integer):integer;

var

d:integer;

begin

f:=x+i*j;

end;

var a:integer;

begin

cy:= 6;

c:= 9;

x:=c/cy + f(4,c,cy);

end.

 

test.asm:

; ---- primitive asm code generator (.pas to.asm)

;include procedure call and expression enterpriter

.386

.model flat, stdcall

option casemap:none

 

include masm32.inc

includelib lib1.lib

includelib masm32.lib

ExitProcess PROTO:DWORD

outdec PROTO:DWORD

 

__codeblock000 PROTO

__codeblock001 PROTO

.data

out_ db 200 dup (0)

real_ db 200 dup (0)

nl_ db 0Dh, 0Ah, 00h

nul_ db 30h, 00h

mm_ db '-', 00h

.code

 

outdec proc NUM:DWORD

pusha

push es

push ds

pop es

lea edi, out_

mov eax, NUM

cmp eax, 0

jl _otr

jne _ok

invoke StdOut, offset nul_

ret

_otr:

invoke StdOut, offset mm_

ret

_ok:

xor ebx, ebx

mov bl, 10

xor ecx, ecx

;===

cld

ll:

cmp eax, 0

jle ex

xor edx, edx

div ebx

xchg eax, edx

add al, 30h

stosb

mov al, 00h

stosb

xchg eax, edx

jmp ll

ex:

invoke StdOut, edi

sub edi, 2

cmp edi, offset out_

jge ex

;===

pop es

popa

ret

outdec endp

 

EntryPoint:

mov ebp, esp

 

 

sub esp, 20; vars to block 0

call __codeblock000

 

invoke ExitProcess,0

 

 

__codeblock000 proc

 

mov eax, 6

mov DWORD PTR [ebp-4], eax

mov eax, 9

mov DWORD PTR [ebp-12], eax

sub esp, 16; vars to block 1

mov eax, 4

push eax

mov eax, 12

push eax

mov eax, 4

push eax

call __codeblock001

add esp, 28

push eax

mov eax, DWORD PTR [ebp-4]

mov ebx, DWORD PTR [ebp-12]

xchg eax, ebx

xor edx, edx

idiv ebx

pop ebx

add eax, ebx

mov DWORD PTR [ebp-0], eax

 

ret

__codeblock000 endp

__codeblock001 proc

 

mov eax, DWORD PTR [ebp-0]

mov ebx, DWORD PTR [ebp-16]

xor edx, edx

imul ebx

 

add eax, DWORD PTR [ebp-16]

 

ret

__codeblock001 endp

 

 

END EntryPoint

 

test1.pas

program test1;

var i,j:integer;

x:integer;

function sum(i,j:integer):integer;

var

s:integer;

begin

s:=i+j;

sum:=s;

end;

begin

x:=sum (5,6);

end.

 

test1.asm

; ---- primitive asm code generator (.pas to.asm)

;include procedure call and expression enterpriter

.386

.model flat, stdcall

option casemap:none

 

include masm32.inc

includelib lib1.lib

includelib masm32.lib

ExitProcess PROTO:DWORD

outdec PROTO:DWORD

 

__codeblock000 PROTO

__codeblock001 PROTO

.data

out_ db 200 dup (0)

real_ db 200 dup (0)

nl_ db 0Dh, 0Ah, 00h

nul_ db 30h, 00h

mm_ db '-', 00h

.code

 

outdec proc NUM:DWORD

pusha

push es

push ds

pop es

lea edi, out_

mov eax, NUM

cmp eax, 0

jl _otr

jne _ok

invoke StdOut, offset nul_

ret

_otr:

invoke StdOut, offset mm_

ret

_ok:

xor ebx, ebx

mov bl, 10

xor ecx, ecx

;===

cld

ll:

cmp eax, 0

jle ex

xor edx, edx

div ebx

xchg eax, edx

add al, 30h

stosb

mov al, 00h

stosb

xchg eax, edx

jmp ll

ex:

invoke StdOut, edi

sub edi, 2

cmp edi, offset out_

jge ex

;===

pop es

popa

ret

outdec endp

 

EntryPoint:

mov ebp, esp

 

 

sub esp, 12; vars to block 0

call __codeblock000

 

invoke ExitProcess,0

 

 

__codeblock000 proc

 

sub esp, 12; vars to block 1

mov eax, 6

push eax

mov eax, 5

push eax

call __codeblock001

add esp, 20

mov DWORD PTR [ebp-8], eax

 

ret

__codeblock000 endp

__codeblock001 proc

 

mov eax, DWORD PTR [ebp-0]

add eax, DWORD PTR [ebp-16]

mov DWORD PTR [ebp-8], eax

mov eax, DWORD PTR [ebp-0]

 

ret

__codeblock001 endp

 

 

END EntryPoint

 

2

 





:


: 2017-01-28; !; : 261 |


:

:

, , 1:10
==> ...

1477 - | 1414 -


© 2015-2024 lektsii.org - -

: 0.093 .