scriptbasic belső modulok
DESCRIPTION
ScriptBasic Belső Modulok. Peter Verh á s Február 2002. Tartalom. Modulok általános felépítése Beolvasó, ... , építő modulok részletesen. Ismétlés. ScriptBasic belső modulok READER LEXER SYNTAXER BULDER EXECUTOR. Mi egy modul. Egy forrás fájlban implementált Függvények gyűjteménye - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/1.jpg)
S B
ScriptBasic Belső Modulok
Peter VerhásFebruár 2002
![Page 2: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/2.jpg)
S BTartalom
• Modulok általános felépítése• Beolvasó, ... , építő modulok
részletesen
![Page 3: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/3.jpg)
S BIsmétlés
• ScriptBasic belső modulok– READER– LEXER– SYNTAXER– BULDER– EXECUTOR
![Page 4: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/4.jpg)
S BMi egy modul
• Egy forrás fájlban implementált• Függvények gyűjteménye• typedef struct {} objektum adat
definíció• Jól definiált hívási felület és
eredmény
![Page 5: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/5.jpg)
S BObjektum adat, függvények
• Működési paraméterek• Pillanatnyi objektum státusz
reader.c
input
lines read
MODUL
![Page 6: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/6.jpg)
S BModul függvények
• Inicializáló és operációs függvények
• Belső függvények• Eredmény lekérdező függvények
ScriptBasic main()
Reader Lexer Syntax Build
![Page 7: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/7.jpg)
S BTechnikai megjegyzés
• A ScriptBasic C-ben van írva, nem C++• A fejléc fájlok mind a C kód
megjegyzéseiben vannak• A headerer.pl generál *.c *.h
fájlokat• A fejléc fájlokban a függvény prototípus
karbantartás automatizált• A // megjegyzéseket a headerer.pl
szedi ki (nem teszi bele a *.h-ba)• (Létezik headerer.bas is )
![Page 8: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/8.jpg)
S BBeolvasó
• Fájlból, vagy valamilyen más forrásból a memóriába olvassa be a programsorokat
• A beolvasott sorokat tárolja
![Page 9: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/9.jpg)
S BBeolvasó objektum struktúra 1/3
typedef struct _ReadObject { void * (*fpOpenFile)(char *, void *); int (*fpGetCharacter)(void *, void *); void (*fpCloseFile)(void *, void *); void *pFileHandleClass;
void *(*memory_allocating_function)(size_t, void *); void (*memory_releasing_function)(void *, void *); void *pMemorySegment;
ptConfigTree pConfig;
![Page 10: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/10.jpg)
S BBeolvasó objektum struktúra 2/3
char *Buffer; // buffer to read a line long dwBuffer; // size of Buffer in bytes long cBuffer; // number of characters in buffer
pSourceLine Result; // the lines of the file(s) read
// iteration variables pSourceLine CurrentLine; // the current line in the iteration long NextCharacterPosition; // position of next character // to be returned during iteration char fForceFinalNL; // if TRUE then an extra new line is // added to the last line // if it was terminated by EOF
![Page 11: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/11.jpg)
S BBeolvasó objektum struktúra 3/3
pReportFunction report; void * reportptr; // this pointer is passed // to the report function. The caller should set it. int iErrorCounter; unsigned long fErrorFlags;
pImportedFileList pImportList;
char *FirstUNIXline; struct _PreprocObject *pPREP; } ReadObject, *pReadObject;
![Page 12: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/12.jpg)
S BBeolvasó függvények
• reader_InitStructure• reader_ReadLines
• reader_StartIteration• reader_NextCharacter/NextLine• reader_FileName/LineNumber
![Page 13: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/13.jpg)
S BLexikális elemző
• A beolvasótól átveszi a karaktereket, és tokenizál
• Token típusokenum LexemeType { LEX_T_DOUBLE = 1, LEX_T_LONG, LEX_T_STRING, LEX_T_ASYMBOL, LEX_T_NSYMBOL, LEX_T_CHARACTER, LEX_T_SKIP, LEX_T_SKIP_SYMBOL, LEX_T_DUMMY };
![Page 14: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/14.jpg)
S BToken struktúra
typedef struct _Lexeme { enum LexemeType type; // type of the lexeme union { double dValue; // double value long lValue; // long value char *sValue; // string or symbol value } value; long sLen; //length of string or symbol char *szFileName; // where the lexeme is long lLineNumber; // where the lexeme is struct _Lexeme *next; // link to the next lexeme } Lexeme, *pLexeme;
![Page 15: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/15.jpg)
S B Lexikális elemző objektum struktúra 1/4
typedef struct _LexObject { // returns the next character from the input stream int (*pfGetCharacter)(void *);// returns a pointer to the file name that the last// character came from char * (*pfFileName)(void *);// returns the line number of the line that the last// character came from long (*pfLineNumber)(void *); void *pvInput;
void *(*memory_allocating_function)(size_t, void *); void (*memory_releasing_function)(void *, void *); void *pMemorySegment;
![Page 16: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/16.jpg)
S B Lexikális elemző objektum struktúra 2/4
char *SSC; // Start Symbol Character char *SCC; // Symbol Continuation Character char *SFC; // Symbol Final Character char *SStC; // Start String Character char *SKIP; // characters to be skipped // (though they are symbol // terminators and valid in strings) // this is usually space and tab
// Escape replacements. The first character is// the escape character and// for each odd n the nth character is// the replacement for the (n-1)th character char *ESCS; long fFlag; // various options
![Page 17: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/17.jpg)
S B Lexikális elemző objektum struktúra 3/4
pReportFunction report;// this pointer is passed to the report// function. The caller should set it. void *reportptr; int iErrorCounter; unsigned long fErrorFlags;
// should point to a buffer of size char *buffer; long cbBuffer; // this number of bytes
![Page 18: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/18.jpg)
S B Lexikális elemző objektum struktúra 4/4
pLexNASymbol pNASymbols; // Array of non alpha symbols// the longest Non Alpha Symbol// length including the final zchar int cbNASymbolLength;
// Array of tokenizable alpha symbols pLexNASymbol pASymbols;
// Array of command symbols for debug purposes// (used by ex_pprint via lex_SymbolicName) pLexNASymbol pCSymbols; pLexeme pLexResult; // list of tokens pLexeme pLexCurrentLexeme; // the actual lexeme struct _PreprocObject *pPREP; }LexObject, *pLexObject;
![Page 19: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/19.jpg)
S BLexikális elemző függvények
• lex_InitStructure• lex_ReadInput• lex_StartIteration• lex_NextLexeme• lex_Save/RestorePosition• lex_EOF• lex_Type• lex_Double/String/Long/StrLen• Lex_Finish
![Page 20: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/20.jpg)
S BSzintaxis elemző
• A token listát olvassa és• Szintaxis fát generál• A szintaxis fa eNODE-okból áll
– A szintaxis elemzőt nem tárgyaljuk• Nem érdemes, speciális, nem tipikus
– De a generált BASIC belső kódot igen
![Page 21: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/21.jpg)
S BeNODE struktúra
typedef struct _eNODE {
long OpCode; // the code of operation unsigned long NodeId; // the id of the node char *szFileName;// where the lexeme is long lLineNumber;// from which this syntax node is made
union {...}Parameter;
} eNODE,*peNODE;
![Page 22: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/22.jpg)
S BeNODE Paraméter struktúra
typedef struct _eNODE {
... union { // when the node is a command struct {...} CommandArgument; // when the node is an operation struct {...} Arguments; // when the node is a constant struct {...} Constant; // when the node is a variable struct {...} Variable; // when node is a user functions struct {...} UserFunction; }Parameter;
} eNODE,*peNODE;
![Page 23: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/23.jpg)
S BParancs Argumentum
// when the node is a command struct { union { struct _SymbolLABEL *pLabel; struct _eNODE *pNode; struct _eNODE_l *pNodeList; long lLongValue; double dDoubleValue; char *szStringValue; }Argument; long sLen; struct _eNODE *next; }CommandArgument;
![Page 24: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/24.jpg)
S BTovábbi paraméterek
// when the node is an operation struct { struct _eNODE_l *Argument; }Arguments;
// when the node is a constant struct { union { double dValue; long lValue; char *sValue; }Value; long sLen; //the length of the string constant }Constant;
// when the node is a variable struct { unsigned long Serial; }Variable;
// when node is a user functions struct { pSymbolUF pFunction; // pointer to the function struct _eNODE_l *Argument; }UserFunction;
![Page 25: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/25.jpg)
S BeNODE lista
// node listtypedef struct _eNODE_l{ unsigned long NodeId; // the id of the node
char *szFileName;// where the lexeme is long lLineNumber;// from which this syntax node is made
peNODE actualm; struct _eNODE_l *rest; } eNODE_l, *peNODE_l;
![Page 26: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/26.jpg)
S BCímke és változó struktúra
typedef struct _SymbolLABEL { // label for GOTO // and alikes long Serial; // serial value of the label unsigned long node; // where the label is placed (the
node id) } SymbolLABEL, *pSymbolLABEL;
typedef struct _SymbolVAR { //Variable long Serial; // serial number of the variable } SymbolVAR, *pSymbolVAR;
![Page 27: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/27.jpg)
S BSzintaxis elemzés példa
a$ = 23 + "5.5" & "E1"
2 OpCode=eNTYPE_GVR
Serial=1
1 OpCode=560 LET
Argumentnext
11actualm
10actualm
rest
5 OpCode=+
Argument
9 OpCode= &
Argument
12 OpCode=eNTYPE_STR
sValue=„E1”
6
actualm
rest
Argument
4 OpCode=eNTYPE_LNG
lValue=23
8 OpCode=eNTYPE_STR
sValue=„5.5”
13actualm
rest
rest
7
actualm
rest
3 OpCode= EX_LEX_EXP
Argumentnext
![Page 28: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/28.jpg)
S BSzintaxis elemző függvények
• ex_init• ex_Command_l
![Page 29: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/29.jpg)
S BÉpítő (builder)
• A szintaxis elemző pointer fáját alakítja át tömbbé
• eNODE cNODE
![Page 30: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/30.jpg)
S BcNODE struktúra
typedef struct _cNODE {
long OpCode; // the code of operation
union {...}Parameter;
} cNODE,*pcNODE;
typedef struct _eNODE {
long OpCode; // the code of operation unsigned long NodeId; // the id of the node char *szFileName;// where the lexeme is long lLineNumber;// from which this syntax node is
made
union {...}Parameter;
} eNODE,*peNODE;
![Page 31: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/31.jpg)
S BcNODE Parameter struktúra
union { // when the node is a command struct { ... }CommandArgument; // when the node is an operation struct { ... }Arguments; // when the node is a constant union { ... }Constant; // when the node is a variable struct { ... }Variable; // when node is a user functions struct { ... }UserFunction; // when the node is a node list
head struct { ... }NodeList; }Parameter;
eNODE union { // when the node is a command struct {...} CommandArgument; // when the node is an operation struct {...} Arguments; // when the node is a constant struct {...} Constant; // when the node is a variable struct {...} Variable; // when node is a user functions struct {...} UserFunction; }Parameter;
![Page 32: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/32.jpg)
S B cNODE Parancs Argumentum struktúra
// when the node is a command struct { unsigned long next; union { unsigned long pNode; // node id of the node long lLongValue; double dDoubleValue;// serial value of the string from the string table unsigned long szStringValue; }Argument; }CommandArgument;
![Page 33: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/33.jpg)
S B Építő modul függvények
build_Build
build_SaveCode
build_LoadCode
build_SaveCCode
build_LookupFunctionByName
build_LookupVariableByName
![Page 34: ScriptBasic Belső Modulok](https://reader036.vdocuments.site/reader036/viewer/2022062410/568156f7550346895dc49fe4/html5/thumbnails/34.jpg)
S B
Köszönöm a figyelmet.