styx-2.0.1/ 0000755 0001750 0001750 00000000000 12116751140 007520 5 0000000 0000000 styx-2.0.1/inc/ 0000755 0001750 0001750 00000000000 12116751137 010277 5 0000000 0000000 styx-2.0.1/inc/prs_abs.h 0000644 0001750 0001750 00000022507 12112434362 012021 0000000 0000000 /* ------------------------------------------------------------------------ */ /* */ /* [prs_abs.h] Abstract LR Parser Interface */ /* */ /* Copyright (c) 2002 by D\olle, Manns */ /* ------------------------------------------------------------------------ */ /* File generated by 'ctoh'. Don't change manually. */ #ifndef prs_abs_INCL #define prs_abs_INCL #include "prs_dfn.h" #ifdef __cplusplus extern "C" { #endif /*
This module [prs_abs] provides an abstract LR parser interface for the term generation module [ptm_gen].
It can be used to integrate an externally defined parser with the STYX term generation facility. */ /* ----------------------------- The Types --------------------------------- */ AbstractType(AbsPlr_T); /* Abstract parser interface type */ /* Types of the parser (interface and configuration) functions */ typedef int (*PF_cfgsize )(Abs_T parser); typedef int (*PF_symType )(Abs_T parser, int symID); typedef c_string (*PF_symName )(Abs_T parser, int symID); typedef int (*PF_startSym)(Abs_T parser, int startID); typedef int (*PF_prodNT )(Abs_T parser, int prodID); typedef c_string (*PF_prodName)(Abs_T parser, int prodID); typedef int (*PF_dynprod )(Abs_T parser, int prodID); typedef int (*PIF_nextTok)(AbsPlr_T pconfig); typedef c_string (*PIF_curTok )(AbsPlr_T pconfig); typedef Any_T (*PIF_topVal )(AbsPlr_T pconfig); typedef Any_T (*PIF_shift )(AbsPlr_T pconfig, int symID); typedef Any_T (*PIF_reduce ) ( AbsPlr_T pconfig, int symcnt, int prodID, c_bool accept ); typedef c_bool (*PIF_parse ) ( AbsPlr_T pconfig, c_string symStart, c_bool early ); typedef c_bool (*PIF_accept )(AbsPlr_T pconfig); typedef void (*PIF_error )(AbsPlr_T pconfig); typedef void (*PIF_debug )(AbsPlr_T pconfig, Any_T value); /* ---------------------------- Init & Quit -------------------------------- */ AbsPlr_T AP_init(void); /* creates an abstract parser interface */ void AP_quit(AbsPlr_T pconfig) /* removes abstract parser interface 'pconfig' */ ; /* --------------- Specification of the external parser interface ---------- */ void AP_setParser(AbsPlr_T pconfig, Abs_T parser) /* specifies the external 'parser' of the abstract interface 'pconfig' */ ; /*
An external defined parser must provide the following interface functions. They have to be assigned to the abstract parser interface before initializing the term generation. That module calls them during the construction of the derivation tree. */ void AP_setFunSymCnt(AbsPlr_T pconfig, PF_cfgsize symCnt) /* specifies 'symCnt' as corresponding function for PLR_symbolCnt in the abstract interface 'pconfig' */ ; void AP_setFunTokCnt(AbsPlr_T pconfig, PF_cfgsize tokCnt) /* specifies 'tokCnt' as corresponding function for PLR_tokenCnt in the abstract interface 'pconfig' */ ; void AP_setFunProdCnt(AbsPlr_T pconfig, PF_cfgsize prodCnt) /* specifies 'prodCnt' as corresponding function for PLR_prodCnt in the abstract interface 'pconfig' */ ; void AP_setFunSymType(AbsPlr_T pconfig, PF_symType symType) /* specifies 'symType' as corresponding function for PLR_symType in the abstract interface 'pconfig' */ ; void AP_setFunSymName(AbsPlr_T pconfig, PF_symName symName) /* specifies 'symName' as corresponding function for PLR_symName in the abstract interface 'pconfig' */ ; void AP_setFunStartSym(AbsPlr_T pconfig, PF_startSym startSym) /* specifies 'startSym' as corresponding function for PLR_startSymbol in the abstract interface 'pconfig' */ ; void AP_setFunProdNT(AbsPlr_T pconfig, PF_prodNT prodNT) /* specifies 'prodNT' as corresponding function for PLR_prodNonTerm in the abstract interface 'pconfig' */ ; void AP_setFunProdName(AbsPlr_T pconfig, PF_prodName prodName) /* specifies 'prodName' as corresponding function for PLR_prodName in the abstract interface 'pconfig' */ ; void AP_setFunProdDynIdx(AbsPlr_T pconfig, PF_dynprod prodDynIdx) /* specifies 'prodDynIdx' as corresponding function for PLR_prodDSymIdx in the abstract interface 'pconfig' */ ; void AP_setFunProdDynSym(AbsPlr_T pconfig, PF_dynprod prodDynSym) /* specifies 'prodDynSym' as corresponding function for PLR_prodDSymSym in the abstract interface 'pconfig' */ ; void AP_setFunTopVal(AbsPlr_T pconfig, PIF_topVal topVal) /* specifies 'topVal' as corresponding function for PLR_topVal in the abstract interface 'pconfig' */ ; void AP_setFunParse(AbsPlr_T pconfig, PIF_parse parse) /* specifies 'parse' as corresponding function for PLR_parse in the abstract interface 'pconfig' */ ; void AP_setFunAccept(AbsPlr_T pconfig, PIF_accept accept) /* specifies 'accept' as corresponding function for PLR_accept in the abstract interface 'pconfig' */ ; /* --------------- Specification of the external parser configuration ------ */ void AP_setExtCfg(AbsPlr_T pconfig, Abs_T extcfg) /* specifies the external configuration 'extcfg' of the abstract interface 'pconfig' */ ; /*
An external defined parser must be configurable by the following callback functions. These handlers will be defined and assigned by the term generation module and must be called by the parser during processing. */ void AP_setFunNextTok(AbsPlr_T pconfig, PIF_nextTok nextTok) /* specifies 'nextTok' as "get next token" handler in the abstract interface 'pconfig' */ ; void AP_setFunCurTok(AbsPlr_T pconfig, PIF_curTok curTok) /* specifies 'curTok' as "get current token name" handler in the abstract interface 'pconfig' */ ; void AP_setFunShift(AbsPlr_T pconfig, PIF_shift shift) /* specifies 'shift' as "shift operation" handler in the abstract interface 'pconfig' */ ; void AP_setFunReduce(AbsPlr_T pconfig, PIF_reduce reduce) /* specifies 'reduce' as "reduce operation" handler in the abstract interface 'pconfig' */ ; void AP_setFunError(AbsPlr_T pconfig, PIF_error error) /* specifies 'error' as "error reporting" handler in the abstract interface 'pconfig' */ ; void AP_setFunDebug(AbsPlr_T pconfig, PIF_debug debug) /* specifies 'debug' as "debugging" handler in the abstract interface 'pconfig' */ ; /* --------------- Accessing the external parser interface ----------------- */ Abs_T AP_getParser(AbsPlr_T pconfig) /* get the external parser of the abstract interface 'pconfig' */ ; PF_cfgsize AP_getFunSymCnt(AbsPlr_T pconfig) /* get the corresponding function for PLR_symbolCnt in the abstract interface 'pconfig' */ ; PF_cfgsize AP_getFunTokCnt(AbsPlr_T pconfig) /* get the corresponding function for PLR_tokenCnt in the abstract interface 'pconfig' */ ; PF_cfgsize AP_getFunProdCnt(AbsPlr_T pconfig) /* get the corresponding function for PLR_prodCnt in the abstract interface 'pconfig' */ ; PF_symType AP_getFunSymType(AbsPlr_T pconfig) /* get the corresponding function for PLR_symType in the abstract interface 'pconfig' */ ; PF_symName AP_getFunSymName(AbsPlr_T pconfig) /* get the corresponding function for PLR_symName in the abstract interface 'pconfig' */ ; PF_startSym AP_getFunStartSym(AbsPlr_T pconfig) /* get the corresponding function for PLR_startSymbol in the abstract interface 'pconfig' */ ; PF_prodNT AP_getFunProdNT(AbsPlr_T pconfig) /* get the corresponding function for PLR_prodNonTerm in the abstract interface 'pconfig' */ ; PF_prodName AP_getFunProdName(AbsPlr_T pconfig) /* get the corresponding function for PLR_prodName in the abstract interface 'pconfig' */ ; PF_dynprod AP_getFunProdDynIdx(AbsPlr_T pconfig) /* get the corresponding function for PLR_prodDSymIdx in the abstract interface 'pconfig' */ ; PF_dynprod AP_getFunProdDynSym(AbsPlr_T pconfig) /* get the corresponding function for PLR_prodDSymSym in the abstract interface 'pconfig' */ ; PIF_topVal AP_getFunTopVal(AbsPlr_T pconfig) /* get the corresponding function for PLR_topVal in the abstract interface 'pconfig' */ ; PIF_parse AP_getFunParse(AbsPlr_T pconfig) /* get the corresponding function for PLR_parse in the abstract interface 'pconfig' */ ; PIF_accept AP_getFunAccept(AbsPlr_T pconfig) /* get the corresponding function for PLR_accept in the abstract interface 'pconfig' */ ; /* --------------- Accessing the external parser configuration ------------- */ Abs_T AP_getExtCfg(AbsPlr_T pconfig) /* get the external configuration of the abstract interface 'pconfig' */ ; PIF_nextTok AP_getFunNextTok(AbsPlr_T pconfig) /* get the "get next token" handler in the abstract interface 'pconfig' */ ; PIF_curTok AP_getFunCurTok(AbsPlr_T pconfig) /* get the "get current token name" handler in the abstract interface 'pconfig' */ ; PIF_shift AP_getFunShift(AbsPlr_T pconfig) /* get the "shift operation" handler in the abstract interface 'pconfig' */ ; PIF_reduce AP_getFunReduce(AbsPlr_T pconfig) /* get the "reduce operation" handler in the abstract interface 'pconfig' */ ; PIF_error AP_getFunError(AbsPlr_T pconfig) /* get the "error reporting" handler in the abstract interface 'pconfig' */ ; PIF_debug AP_getFunDebug(AbsPlr_T pconfig) /* get the "debugging" handler in the abstract interface 'pconfig' */ ; #ifdef __cplusplus } #endif #endif styx-2.0.1/inc/scn_base.h 0000644 0001750 0001750 00000032424 12112434362 012144 0000000 0000000 /* ------------------------------------------------------------------------ */ /* */ /* [scn_base.h] Basic Token Separation */ /* */ /* Copyright (c) 1993 by D\olle, Manns */ /* ------------------------------------------------------------------------ */ /* File generated by 'ctoh'. Don't change manually. */ #ifndef scn_base_INCL #define scn_base_INCL #include "symbols.h" #include "scn_io.h" #ifdef __cplusplus extern "C" { #endif /*
The module [scn_base] implements the scan stream interface based on a given STYX-konform scanner definition. ( see [scn_gen] )
The scan stream is reentrant and allows multiple scan operations at a time.
*/
/* ------------------------ Macros ---------------------------------------- */
/*
Token definition flags ( see Scn_dfnToken ) */ #define SCN_FLG_IgnoreToken 1 /* token has to be ignored */ #define SCN_FLG_IgnoreCase 2 /* case insensitive token */ #define SCN_FLG_EofToken 4 /* eof token in embedded language */ #define SCN_FLG_SwitchToken 8 /* switch to/from embedded language */ #define SCN_FLG_CfgToken 16 /* embedded language token */ #define SCN_FLG_IndentToken 32 /* (de)indent token */ #define SCN_FLG_PatternToken 64 /* (start or end) pattern token */ #define SCN_FLG_GroupStack 128 /* push/pop token group */ /*
Token preprocessing result values
*/
#define SCN_FLG_RescanNone 0
#define SCN_FLG_RescanString 1
#define SCN_FLG_RescanBString 2
#define SCN_FLG_RescanFile 3
#define SCN_FLG_RescanBFile 4
#define SCN_FLG_RescanExtFile 5
#define SCN_FLG_RescanExtBFile 6
#define SCN_FLG_RescanChar 7
#define SCN_FLG_RescanChrItr 8
#define SCN_FLG_RescanBChrItr 9
/* ------------------------- Stream of tokens ----------------------------- */
AbstractType( Scn_Stream ); /* Stream onto a scanner */
AbstractType( Scn_Stream_Itr ) /* Character iterator onto a scan stream */
;
/*
Type of token preprocessing function
RC = SCN_FLG_RescanChrItr & valid cMacVal --> rescan character iterator cMacVal
( frees character iterator )
RC = SCN_FLG_RescanBChrItr & valid cMacVal --> rescan binary char iterator cMacVal
( frees character iterator )
RC = SCN_FLG_RescanString & valid cMacVal --> rescan string cMacVal
RC = SCN_FLG_RescanFile & valid cMacVal --> rescan file cMacVal
RC = SCN_FLG_RescanBString & valid cMacVal --> rescan binary string cMacVal
RC = SCN_FLG_RescanBFile & valid cMacVal --> rescan binary file cMacVal
RC = SCN_FLG_RescanExtFile & valid cMacVal --> rescan file cMacVal,
with main stream read function if possible
RC = SCN_FLG_RescanExtBFile & valid cMacVal --> rescan binary file cMacVal,
with main stream read function if possible
RC = SCN_FLG_RescanChar & valid cMacVal --> rescan character cMacVal
( single byte or ucs4 )
RC = SCN_FLG_RescanNone & valid cMacVal --> replace cTokVal with cMacVal
( single byte or utf-8 )
ELSE --> ignore cTokVal
*/
typedef int (*Scn_PreMacFun)
(
Scn_Stream pStream, c_string cTokNam,
c_string cTokVal, symbol* cMacVal
);
/*
Type of the embedded language token constructor
*/
typedef Any_T (*Scn_eTerm)
(
Abs_T CurPTCfg, c_string language, c_string StartSymbol
);
/*
Type of the embedded language accept token recognizer
*/
typedef c_bool (*Scn_eAccept)(Abs_T CurPTCfg);
/* ------------------- Accessing scanner definition ----------------------- */
c_string Scn_id(Scn_T scn)
/* name of the scanner (group) 'scn'; allocs memory
*/
;
short Scn_check_Token(Scn_T scn, c_string s)
/* whether string 's' is a token in scanner 'scn';
result = token number ( > 0 ) or 0
assertion: Scn_groups(scn) = 0
*/
;
short Scn_check_WCToken(Scn_T scn, wc_string s)
/* whether wide string 's' is a token in scanner 'scn';
result = token number ( > 0 ) or 0
assertion: Scn_groups(scn) = 0
*/
;
int Scn_tokens(Scn_T scn)
/* number of tokens defined in scanner ( group ) 'scn' */
;
c_string Scn_tokid(Scn_T scn, int i)
/* name of the i-th token definied in scanner 'scn'; allocs memory
assertion: Scn_groups(scn) = 0
*/
;
c_byte Scn_tokFlags(Scn_T scn, int i)
/* flags of the i-th token definied in scanner 'scn'
assertion: Scn_groups(scn) = 0
*/
;
int Scn_dycks(Scn_T scn)
/* number of dyck token defined in scanner ( group ) 'scn' */
;
Scn_T Scn_dyck(Scn_T scn, int i)
/* i-th dyck scanner definied in scanner group 'scn'
assertion: Scn_dycks(scn) > 0
*/
;
int Scn_dycktoken(Scn_T scn, int i)
/* i-th dyck token definied in scanner group 'scn'
assertion: Scn_dycks(scn) > 0
*/
;
int Scn_groups(Scn_T scn)
/* number of groups defined in scanner ( group ) 'scn' */
;
Scn_T Scn_group(Scn_T scn, int i)
/* i-th scanner definied in scanner group 'scn'
assertion: Scn_groups(scn) > 0
*/
;
int Scn_SwitchGroup(Scn_T scn, int i)
/* switch group of the i-th token definied in scanner group 'scn' or -1
assertion: Scn_groups(scn) = 0
*/
;
long Scn_check_GroupToken(Scn_T scn, c_string s)
/* whether string 's' is a token in scanner group 'scn';
result: high = group index , low = token number ( > 0 ) or 0
assertion: Scn_groups(scn) > 0
*/
;
long Scn_check_GroupWCToken(Scn_T scn, wc_string s)
/* whether wide string 's' is a token in scanner group 'scn';
result: high = group index , low = token number ( > 0 ) or 0
assertion: Scn_groups(scn) > 0
*/
;
/* ------------------- Character iterator definition ---------------------- */
Scn_Stream_Itr Stream_Itr_new
(
int f_getc (StdCPtr file),
void f_close(StdCPtr file),
c_string f_wc2mb(wc_string wc),
LONG_INT f_seek (StdCPtr file, long offset, int origin),
StdCPtr file,
c_string fileid
)
/* creates and initializes a character iterator
onto the open character source 'file'
'f_getc' : next character
'f_close': closes character source
'f_wc2mb': converts wide to multibyte character
'f_seek' : positions character source
'fileid' : character source identifier
*/
;
void Stream_Itr_free(Scn_Stream_Itr itr); /* frees character iterator 'itr' */
/* ------------------------ Scan stream definition ------------------------ */
Scn_Stream Stream_bgn(Scn_T scn, Scn_Stream_Itr itr)
/* creates and initializes a scan stream
onto scanner 'scn' and character iterator 'itr'
*/
;
void Stream_close(Scn_Stream t)
/* closes character source i.e. file of scan stream 't' */
;
void Stream_free(Scn_Stream t); /* frees scan stream 't' */
void Stream_reset(Scn_Stream t)
/* re-initializes scan process in current scan stream 't' */
;
void Stream_premac_set(Scn_Stream t, Scn_PreMacFun cPreMac)
/* adds 'cPreMac' to scan stream 't'
for token preprocessing & macro expansion
*/
;
void Stream_eterm_set
(
Scn_Stream t, Abs_T CurPTCfg, Scn_eTerm eTerm, Scn_eAccept eAccept
)
/* adds 'eTerm', 'eAccept' and 'CurPTCfg' to scan stream 't'
for embedded language token construction
( deactivates other token concatenation )
*/
;
void Stream_add_ctxval(Scn_Stream t, Any_T id, Any_T val)
/* adds the context pair 'id' |--> 'val' to scan stream 't';
updates existing entries
*/
;
void Stream_concat_other(Scn_Stream t)
/* activates other token concatenation in scan stream 't' */
;
void Stream_skip_character(Scn_Stream t, int cC)
/* skips character 'cC' ( but tracks position ) */
;
void Stream_enable_lookahead(Scn_Stream t)
/* activates n character lookahead in scan stream 't' */
;
void Stream_binmode_set(Scn_Stream t)
/* activates binary mode in scan stream 't'
( deactivates other token concatenation )
*/
;
Scn_Stream Stream_line
(
Scn_T scn, StdCPtr line, int (*cGet)(StdCPtr line), c_string id
)
#define STREAM_STDIN(scn) \
Stream_line(scn,stdin,(int (*)(StdCPtr f))fgetc," This module [ctx] provides functions for the definition of a program context and
the verification of the current commandline against the current program context.
The definition interface will be used by the CMD Compiler
which parses and evaluates a command decription file [.cmd], constructs a program context
out of it and finally makes it persistent.
The application interface will be used by the applications and the generated
program specific context modules.
The module [hpat] provides some functionality for the evaluation of
template files based on the context-free grammar [hpat.sty].
It is used by the STYX reference generator.
Pattern types */
#define HPAT_REF_LIST 0 // pattern list
#define HPAT_REF_PAT 1 // pattern
#define HPAT_REF_PAR 2 // pattern parameter
AbstractType(HPat_T); // Abstract template type
/* Callback function types */
// pattern reference evaluation function
typedef c_bool (*PFN_Pat)(HPat_T pHPat);
// print function
typedef void (*PFN_PatPrint)(HPat_T pHPat, c_string szTxt);
// replacement specification pattern load function
typedef StdCPtr (*PFN_PatLoad)(GLS_Lst(hpatContent) pLst);
// replacement specification apply function
typedef c_string (*PFN_PatOpr)(c_string szTxt, StdCPtr pData);
// replacement specification free function
typedef void (*PFN_PatFree)(StdCPtr pData);
/* -------------------------- Special Functions -------------------------- */
c_string HP_pat_to_txt(GLS_Lst(hpatContent) pLst)
/* template term list 'pLst' to string; allocs memory */
;
/* ------------------------- Init & Quit -------------------------------- */
void HP_init(void); /* initializes template evaluation module */
void HP_quit(void); /* terminates template evaluation module */
/* ------------------------- Create & Dispose --------------------------- */
HPat_T HP_create(void); /* creates a template evaluation object */
void HP_drop(HPat_T pHP); /* frees template evaluation object 'pHP' */
/* ------------------------- Get & Set ---------------------------------- */
void HP_setContext(HPat_T pHP, Abs_T pDocCtx)
/* sets evaluation context 'pDocCtx' in template object 'pHP' */
;
Abs_T HP_getContext(HPat_T pHP)
/* evaluation context of template object 'pHP' */
;
void HP_setPrintFun(HPat_T pHP, PFN_PatPrint pPrint)
/* sets print function 'pPrint' in template object 'pHP' */
;
PFN_PatPrint HP_getPrintFun(HPat_T pHP)
/* print function of template object 'pHP' */
;
void HP_setRefAlias(HPat_T pHP, symbol pRefAlias)
/* sets reference alias 'pRefAlias' in template object 'pHP'
*/
;
symbol HP_getRefAlias(HPat_T pHP)
/* reference alias of template object 'pHP' */
;
void HP_addPatSpec
(
HPat_T pHP, symbol pPat, PFN_Pat pPatFun, long lPatTyp
)
/* adds/overwrites evaluation function 'pPatFun'
for pattern 'pPat' of type 'lPatTyp'
to template object 'pHP'
*/
;
PFN_Pat HP_getPatFun(HPat_T pHP, symbol pPat)
/* evaluation function for pattern 'pPat'
in template object 'pHP'
*/
;
ROW(symbol) HP_getListPatRow(HPat_T pHP, symbol pListPat)
/* member patterns of pattern list 'pListPat'
in template object 'pHP'
*/
;
void HP_setScanner(HPat_T pHP, Scn_T pScn)
/* sets external scanner 'pScn' in template object 'pHP'
( will be removed by HP_drop )
*/
;
Scn_T HP_getScanner(HPat_T pHP)
/* pattern scanner of template object 'pHP' */
;
symbol HP_getPatRef(GLS_Tok pPatRef)
/* symbol of pattern refernce token 'pPatRef' */
;
c_bool HP_addSpecialFun
(
symbol pPatSym,
PFN_PatLoad pPatLoad,
PFN_PatOpr pPatOpr,
PFN_PatFree pPatFree
)
/* adds special evaluation functions for
replacement specification pattern 'pPatSym'
'pPatLoad': loads replacement specification
'pPatOpr' : applies replacement specification
'pPatFree': frees replacement specification
( RC = ok/error )
*/
;
/* ------------------------- Load & Check ------------------------------- */
c_bool HP_load
(
HPat_T pHP, Scn_Stream pStream, symbol pSrcId,
symbol pRootPat, c_bool bRecursive
)
/* loads template pattern from scan stream 'pStream'
into template object 'pHP'
'pSrcId' : optional source identifier
'pRootPat' : root pattern for evaluation
'bRecursive': recursive evaluation
( RC = ok/error )
*/
;
c_bool HP_check(HPat_T pHP)
/* checks loaded template pattern in template object 'pHP'
( RC = ok/error )
*/
;
/* ------------------------- Output Generation -------------------------- */
void HP_gendoc_ref(HPat_T pHP, GLS_Tok pPatRef)
/* evaluates and prints reference token 'pPatRef'
according template object 'pHP'
*/
;
c_bool HP_fun_defined(HPat_T pHP, symbol pRefSym)
/* whether template object 'pHP' contains a
replacement specification for pattern 'pRefSym'
*/
;
c_string HP_fun_apply(HPat_T pHP, symbol pRefSym, c_string szTxt)
/* applies the replacement specification for pattern 'pRefSym'
in template object 'pHP' to text 'szText'
RC = szTxt, if no functions defined, else result text
*/
;
void HP_gendoc_pat(HPat_T pHP, symbol pPatSym)
/* evaluates and prints pattern 'pPatSym'
according template object 'pHP'
*/
;
void HP_gendoc_src(HPat_T pHP, symbol pSrcId)
/* evaluates and prints template 'pSrcId'
according template object 'pHP'
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/ptm.h 0000644 0001750 0001750 00000040602 12112434362 011164 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [ptm.h] Type: Parse Tree / Term */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef ptm_INCL
#define ptm_INCL
#include "otab.h"
#include "binimg.h"
#include "list.h"
#include "sink.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ============================ Parse Tree ================================ */
/*
[ptm] implements the parse i.e. derivation tree as special term data type.
Term representation
Three forms of term representation are supported by the construction functions.
C: This is an efficient representation which lacks an explicit list node
for the childs of a nonterminal node.
Xaron: This is a Lisp-like representation with an explicit list node
for the childs of a nonterminal node. ( used by the xaron project )
ABS: This is a special optimized representation of the abstract parse tree only
with all keywords and comments discarded. For a traversal of the tree you
must use the abstract variant of the generated function interface.
Definition of the symbol position
1. Terminal : Position of the first terminal character
2. Nonterminal : Position of the first terminal character if exists
3. Empty production : Position of the first character of the next terminal
*/
/* ------------------------ Types ------------------------------------------- */
AbstractType(PT_Term); /* Abstract parse tree type */
AbstractType(PT_Itr); /* Abstract parse tree iterator type */
/* ----------------------- Construction & Disposing ------------------------- */
PT_Term PT_newTNode(symbol cfgsym, short symcls, symbol value)
/* C: creates a node for
token 'cfgsym' of type 'symcls' and 'value'
*/
;
PT_Term XPT_newTNode(symbol cfgsym, short symcls, symbol value)
/* Xaron: creates a node for
token 'cfgsym' of type 'symcls' and 'value'
*/
;
PT_Term PT_newNtNode(symbol cfgsym, symbol prdsym, PT_Term parts)
/* C: creates a node for nonterminal 'cfgsym',
production 'prdsym' and child nodes 'parts'
*/
;
PT_Term XPT_newNtNode(symbol cfgsym, symbol prdsym, List(PT_Term) parts)
/* Xaron: creates a node for nonterminal 'cfgsym',
production 'prdsym' and child nodes 'parts'
*/
;
PT_Term PT_updVal(PT_Term PTree, Any_T value)
/* updates token node 'PTree' with 'value'; returns 'PTree' */
;
PT_Term PT_updPos(PT_Term PTree, symbol file, long row, long col)
/* updates node 'PTree' with the position 'file', 'row' and 'col';
returns 'PTree'
*/
;
PT_Term PT_consT(PT_Term left, PT_Term right)
/* C: child node concatenation:
child list = cons('left','right')
*/
;
List(PT_Term) XPT_consT(PT_Term left, List(PT_Term) right)
/* Xaron: child node concatenation:
child list = cons('left','right')
*/
;
PT_Term PT_copyPos(PT_Term left, PT_Term right)
/* assigns position of node 'right' to node 'left';
returns 'left'
*/
;
PT_Term PT_copyNode(PT_Term PTree)
/* copies node 'PTree' ( without child nodes ) */
;
void PT_delT(PT_Term PTree); /* removes parse tree / term 'PTree' */
/* ----------------------- Accessing ---------------------------------------- */
/*
Recognizer
*/
c_bool PT_isXaron(PT_Term PTree)
/* whether 'PTree' is a Xaron-konform parse tree / term */
;
c_bool PT_isNonTerm(PT_Term PTree)
/* whether 'PTree' starts with a nonterminal node */
;
c_bool PT_isCFG(PT_Term PTree)
/* whether 'PTree' is an embedded language node */
;
c_bool PT_isToken(PT_Term PTree); /* whether 'PTree' is a token node */
c_bool PT_isKey(PT_Term PTree); /* whether 'PTree' is a keyword node */
c_bool PT_isComment(PT_Term PTree); /* whether 'PTree' is a comment node */
c_bool PT_hasPos(PT_Term PTree)
/* whether node 'PTree' contains position informations */
;
/*
Selection
*/
symbol PT_product(PT_Term PTree)
/* production symbol of node 'PTree';
assertion: PT_isNonTerm(PTree)
*/
;
symbol PT_symbol(PT_Term PTree); /* symbol of node 'PTree' ( NT,T ) */
short PT_symtyp(PT_Term PTree)
/* symbol type of node 'PTree' ( NT/T, see [cfg_dfn] ) */
;
symbol PT_value(PT_Term PTree)
/* token value of node 'PTree'
assertion: ! PT_isNonTerm(PTree) && ! PT_isCFG(PTree)
*/
;
PT_Term PT_cfg(PT_Term PTree)
/* embedded language of node 'PTree'
assertion: PT_isCFG(PTree)
*/
;
symbol PT_file(PT_Term PTree)
/* position - source file of node 'PTree'
assertion: PT_hasPos(PTree)
*/
;
long PT_row(PT_Term PTree)
/* position - source line of node 'PTree'
assertion: PT_hasPos(PTree)
*/
;
long PT_col(PT_Term PTree)
/* position - source column of node 'PTree'
assertion: PT_hasPos(PTree)
*/
;
PT_Term PT_next(PT_Term PTree)
/* C: next node / rest of child list 'PTree' or NULL */
;
PT_Term PT_parts(PT_Term PTree)
/* C: child list ( first node ) of node 'PTree'
assertion: PT_isNonTerm(PTree)
*/
;
List(PT_Term) XPT_parts(PT_Term PTree)
/* Xaron: child list of node 'PTree'
assertion: PT_isNonTerm(PTree)
*/
;
List(PT_Term)* XPT_parts_ref(PT_Term PTree)
/* Xaron: pointer reference to child list of node 'PTree'
assertion: PT_isNonTerm(PTree)
*/
;
/*
Convenience macros for identifying a certain nonterminal,
token or production
*/
#define PT_THISNTM(t,s) ( ( PT_isNonTerm(t) && PT_symbol(t) == (s) ) ? \
C_True : C_False )
#define PT_THISTOK(t,s) ( ( PT_isToken(t) && PT_symbol(t) == (s) ) ? \
C_True : C_False )
#define PT_THISPRD(t,p) ( ( PT_isNonTerm(t) && PT_product(t) == (p) ) ? \
C_True : C_False )
/* ----------------------------- Searching ---------------------------------- */
int PT_cntST_ex
(
PT_Term PTree, c_bool (*filter)(PT_Term PTree, Any_T any), Any_T any
)
/* number of nodes t within child list of node 'PTree'
sacrifying condition filter(t,any) = False
*/
;
int PT_cntST(PT_Term PTree, c_bool (*filter)(PT_Term PTree))
/* number of nodes t within child list of node 'PTree'
sacrifying condition filter(t) = False
*/
;
PT_Term PT_nthST_ex
(
PT_Term PTree, int nth,
c_bool (*filter)(PT_Term PTree, Any_T any), Any_T any
)
/* 'nth' node t within child list of node 'PTree'
sacrifying condition filter(t,any) = False
[nth=1..PT_cntST_ex]
*/
;
PT_Term PT_nthST(PT_Term PTree, int nth, c_bool (*filter)(PT_Term PTree))
/* 'nth' node t within child list of node 'PTree'
sacrifying condition filter(t) = False
[nth=1..PT_cntST]
*/
;
int PT_symbolCnt(PT_Term PTree, symbol cfgsym, c_bool filter)
/* filter --> number of nodes with symbol 'cfgsym'
else --> number of token and nonterminal nodes
( skipping keywords and comments )
within child list of node 'PTree'
*/
;
PT_Term PT_nthSymbol(PT_Term PTree, symbol cfgsym, int nth, c_bool filter)
/* filter --> 'nth' node with symbol 'cfgsym'
else --> 'nth' token or nonterminal node
( skipping keywords and comments )
within child list of node 'PTree' [nth=1..PT_symbolCnt]
*/
;
PT_Term PT_nthMember(PT_Term PTree, int nth)
/* 'nth' token, keyword or nonterminal node
( skipping comments )
within child list of node 'PTree' [nth=1..PT_symbolCnt]
*/
;
PT_Term PT_r_find
(
PT_Term PTree, c_bool (*pred)(PT_Term PTree, StdCPtr any), StdCPtr any
)
/* first subterm t of parse tree / term 'PTree'
sacrifying condition pred(t,any) ( recursive )
*/
;
PT_Term PT_l_find
(
PT_Term PTree, c_bool (*pred)(PT_Term PTree, StdCPtr any), StdCPtr any
)
/* first subterm t of parse tree / term 'PTree'
sacrifying condition pred(t,any) ( non-recursive )
*/
;
/* -------------------------- Term Iterator --------------------------------- */
/*
Traversal order
All nodes will be visited in pre and post order.
*/
#define PT_ROOT 1 // root / start order
#define PT_PRAE 2 // pre order
#define PT_POST 3 // post order
PT_Itr PT_newIT(PT_Term PTree)
/* creates an iterator for parse tree / term 'PTree' */
;
void PT_delIT(PT_Itr iter); /* removes term iterator 'iter' */
PT_Itr PT_copyIT(PT_Itr iter); /* copies term iterator 'iter' */
short PT_stateIT(PT_Itr iter)
/* current traversal order of term iterator 'iter'
( PT_PRAE / PT_POST )
*/
;
PT_Term PT_termIT(PT_Itr iter); /* current node of term iterator 'iter' */
OT_Tab PT_stackIT(PT_Itr iter)
/* current node stack of term iterator 'iter' */
;
c_bool PT_df_getIT(PT_Itr iter)
/* next node of term iterator 'iter'
in depth first, prae/post order ;
returns False on end-of-term
*/
;
c_bool PT_bf_getIT(PT_Itr iter)
/* next node of term iterator 'iter'
in breast first, prae/post order;
returns False on end-of-term
*/
;
c_bool PT_filterIT(PT_Itr iter, c_bool (*get)(PT_Itr iter))
/* next node of term iterator 'iter' in prae/post order
sacrifying filter condition get(iter),
skipping comments and keywords;
returns False on end-of-term i.e. notfound
*/
;
void PT_skipIT(PT_Itr iter)
/* skips subterms of current node in term iterator 'iter'
assertion: current traversal order = PT_PRAE
*/
;
/* ---------------------- Convenient iterator macros ------------------------ */
/* For - statement with basic iterators. Make sure to
free the iterator if you leave the loop via break.
*/
#define PT_FORALL(it,tr) for( (it) = PT_newIT(tr); \
( PT_df_getIT(it) ) \
? C_True : ( PT_delIT(it), C_False ); )
#define PT_FORALL_F(it,tr) for( (it) = PT_newIT(tr); \
( PT_filterIT(it,PT_df_getIT) ) \
? C_True : ( PT_delIT(it), C_False ); )
#define PT_FORALL_BF(it,tr) for( (it) = PT_newIT(tr); \
( PT_bf_getIT(it) ) \
? C_True : ( PT_delIT(it), C_False ); )
#define PT_FORALL_BF_F(it,tr) for( (it) = PT_newIT(tr); \
( PT_filterIT(it,PT_bf_getIT) ) \
? C_True : ( PT_delIT(it), C_False ); )
#define PT_BREAK(it) { PT_delIT(it); break; }
/* ----------------------- Hashing & Predicates ----------------------------- */
long PT_hash(PT_Term PTree); /* hash value of parse tree / term 'PTree' */
c_bool PT_equal(PT_Term left, PT_Term right)
/* term 'left' = term 'right' ? */
;
c_bool PT_subterm(PT_Term left, PT_Term right)
/* term 'left' <= term 'right' ? */
;
/* ---------------------------- Binary Image -------------------------------- */
void PT_fputT(BinImg_T img, PT_Term PTree)
/* unloads parse tree / term 'PTree'
to binary image 'img' (reentrant)
*/
;
void PT_putT(PT_Term PTree)
/* unloads parse tree / term 'PTree'
to the current ( previously opened ) image
*/
;
void PT_fgetT(BinImg_T img, PT_Term* PTree)
/* loads parse tree / term 'PTree'
from binary image 'img' (reentrant)
*/
;
void PT_getT(PT_Term* PTree)
/* loads parse tree / term 'PTree'
from the current ( previously opened ) image
*/
;
/* ------------------------------- Printing --------------------------------- */
void PT_prind(PT_Term PTree, int ind)
/* prints parse tree / term 'PTree' to stdout
( with indent 'ind' )
*/
;
void PT_prind_utf8(PT_Term PTree, int ind)
/* prints utf8 parse tree / term 'PTree' to stdout
( with indent 'ind' )
*/
;
void PT_prind_rawutf8(PT_Term PTree, int ind)
/* prints utf8 parse tree / term 'PTree' to stdout
( printable ascii or hex, with indent 'ind' )
*/
;
void PT_print(PT_Term PTree); /* prints parse tree / term 'PTree' to stdout */
void PT_print_utf8(PT_Term PTree)
/* prints utf8 parse tree / term 'PTree' to stdout */
;
void PT_print_rawutf8(PT_Term PTree)
/* prints utf8 parse tree / term 'PTree' to stdout
( printable ascii or hex )
*/
;
void PT_TermToString(PT_Term PTree)
/* prints value of parse tree / term 'PTree' to stdout */
;
void PT_TermToSink(PT_Term PTree, Sink snk)
/* prints value of parse tree / term 'PTree' to sink 'snk'
( without comments )
*/
;
/* ----------------------------- Normalizer --------------------------------- */
PT_Term PT_keycom_Skip(PT_Term x)
/* C: skips comment and keyword nodes in child list 'x';
returns first token / nonterminal node or NULL
*/
;
List(PT_Term) XPT_keycom_Skip(List(PT_Term) x)
/* Xaron: skips comment and keyword nodes in child list 'x';
returns next token / nonterminal node or NULL
*/
;
PT_Term PT_ignkey_Skip(PT_Term x, ROW(PT_Term) coms)
/* skips 'ign#'-production, comment and keyword nodes
in parse tree / term 'x', collecting comment nodes in 'coms';
returns next token / nonterminal node
*/
;
PT_Term PT_ign_Skip(PT_Term x)
/* skips 'ign#'-production, comment and keyword nodes
in parse tree / term 'x';
returns next token / nonterminal node
*/
;
/* -------------------------- Xaron Support --------------------------------- */
void PT_references(PT_Term x, StdCPtr (*act)(StdCPtr r))
/* performs 'act' on all pointer and symbol references in node 'x'
( garbage collection service for xaron )
*/
;
/* ========================== Parse Tree (ABS) ============================== */
/*
The above mentioned special optimzed form of an abstract parse tree can be
produced with the following - non-reentrant - unload/load-API.
parse tree --- unload --->
binary image
parse tree (ABS) <--- load ---
*/
/* ------------------------ Types & Macros ---------------------------------- */
AbstractHugeType(PT_Abs_Term); /* Abstract parse tree type [ABS] */
#define PT_Abs_nonterm(X) ((symbol)(((long __HUGE*)(X))[0]))
#define PT_Abs_token(X) ((symbol)(((long __HUGE*)(X))[0]))
#define PT_Abs_product(X) ((symbol)(((long __HUGE*)(X))[1]))
#define PT_Abs_value(X) ((symbol)(((long __HUGE*)(X))[2]))
#define PT_Abs_part(X,N) ((PT_Abs_Term)(((long __HUGE*)(X))[2+(N)]))
#define PT_Abs_cfg(X) ((PT_Abs_Term)(((long __HUGE*)(X))[2+(1)]))
#define PT_Abs_isToken(X) (PT_Abs_product(X) == (symbol)NULL)
#define PT_Abs_isNonTerm(X) (PT_Abs_product(X) != (symbol)NULL)
#define PT_Abs_isCFG(X) \
(PT_Abs_product(X) == (symbol)NULL && PT_Abs_value(X) == NULL)
/* ------------------------- Init & Quit ------------------------------------ */
void PT_putBgn(void); /* initializes abstract term putting */
void PT_putEnd(void); /* quits abstract term putting */
void PT_getBgn(void); /* initializes abstract term getting */
void PT_getEnd(void); /* quits abstract term getting */
/* ------------------------------ Put & Get --------------------------------- */
long PT_Symbol_to_Ref(symbol s); /* reference corresponding to symbol 's' */
long PT_putSymbol(symbol s); /* creates a reference for symbol 's' */
void PT_putAllSymbols(void)
/* puts all symbol references
to the current ( previously opened ) binary image
*/
;
void PT_getAllSymbols(void)
/* gets all symbol references
from the current ( previously opened ) binary image
*/
;
symbol PT_getSymbol(long RefId)
/* symbol corresponding to reference 'RefId' */
;
long PT_Term_to_Ref(PT_Term PTree)
/* abstract term reference corresponding to parse tree 'PTree'
( unload phase )
*/
;
PT_Abs_Term PT_Ref_to_Term(long __HUGE* nodes, long RefId)
/* abstract term in node array 'nodes'
corresponding to reference 'RefId'
( load phase )
*/
;
long PT_putAbsNode(PT_Term PTree)
/* creates an abstract term reference for parse tree 'PTree' */
;
void PT_putAbsT(void)
/* puts all abstract term references
to the current ( previously opened ) binary image
*/
;
long __HUGE* PT_getAbsT(void)
/* gets all abstract term references
from the current ( previously opened ) binary image
*/
;
long __HUGE* PT_patchAbsT(long __HUGE* nodes)
/* patches all abstract term references
in node array 'nodes'; returns 'nodes'
*/
;
/* ------------------------- Disposing -------------------------------------- */
void PT_delAbsT(long __HUGE* nodes)
/* removes node array 'nodes' with abstract term references */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/prim.h 0000644 0001750 0001750 00000003476 12112434362 011343 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [prim.h] Instance functions for simple data types */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef prim_INCL
#define prim_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ----------- Pre-defined functions for various data types --------------- */
long bytesHash(c_byte x[], long len); /* hash function for byte sequences */
long strHash(c_string s); /* hash function for type "string" */
c_bool strEqual(c_string a, c_string b); /* whether 'a' and 'b' are equal */
long combineOrderedHash(long a, long b)
/* combination of two non-commuative hash values */
;
long combineCommutativeHash(long a, long b)
/* combination of two permutable hash values */
;
/* ----------- Pre-defined functions for primitive data types --------------- */
long primHash(StdCPtr x)
/* hash function for primitive types like "char","int","pointer" */
;
c_bool primEqual(StdCPtr a, StdCPtr b); /* whether 'a' and 'b' are equal */
c_bool primGreatEqual(StdCPtr a, StdCPtr b)
/* whether 'a' is greater equal than 'b' */
;
c_bool primLessEqual(StdCPtr a, StdCPtr b)
/* whether 'a' is less equal than 'b' */
;
int primCompare(StdCPtr a, StdCPtr b); /* order of 'a' and 'b' */
StdCPtr primCopy(StdCPtr a); /* identity */
void primFree(StdCPtr a); /* frees a primitive value; i.e. does nothing */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/cfg_abs.h 0000644 0001750 0001750 00000005002 12112434362 011743 0000000 0000000 /*----------------------------------------------------------------------------*/
/* */
/* [cfg_abs.h] Abstract Context Free Grammar */
/* */
/* Copyright (c) 1993 by Doelle, Manns */
/*----------------------------------------------------------------------------*/
/* File generated by 'ctoh'. Don't change manually. */
#ifndef cfg_abs_INCL
#define cfg_abs_INCL
#include "standard.h"
#include "hset.h"
#include "prs.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
[cfg_abs] provides functions that derives the nonterminal and production classes
which constitutes the abstract context free grammar from a given parse table.
For further documentation of the definition of an abstract context free grammar
follow the reference to module [prs_gen]. The module [scn_gen] supports the construction of regular sets and
produces the scanner definitions as base for the
scan streams.
The complexity of the scanner is linear. A consequence of this design-goal
is its restriction to a one-character-lookahead.
The construction of regular sets is reentrant.
There also exists a reentrant version of the scanner production. The resulting regular sets when applying one of the following functions
have to be released.
*/
RegSet_T RegSet_Epsilon(void); /* epsilon "" */
RegSet_T RegSet_Empty(void); /* empty set '' */
RegSet_T RegSet_Range(wc_char dfa_lower, wc_char dfa_upper)
/* character range L .. U */
;
RegSet_T RegSet_Char(wc_char c); /* character 'c' */
RegSet_T RegSet_Copy(RegSet_T a); /* copies regular set 'a' */
RegSet_T RegSet_Union(RegSet_T a, RegSet_T b); /* union a | b */
RegSet_T RegSet_Intersection(RegSet_T a, RegSet_T b); /* intersection a ^ b */
RegSet_T RegSet_Difference(RegSet_T a, RegSet_T b); /* difference a - b */
RegSet_T RegSet_Concat(RegSet_T a, RegSet_T b); /* concatenation a b */
RegSet_T RegSet_Star(RegSet_T a); /* iteration { a } */
RegSet_T RegSet_CsetN(wc_string s,int len); /* character set '...'[0:len) */
RegSet_T RegSet_Cset(wc_string s); /* character set '...' */
RegSet_T RegSet_StringN(wc_string s,int len)
/* character sequence / string "..."[0:len) */
;
RegSet_T RegSet_String(wc_string s); /* character sequence / string "..." */
RegSet_T RegSet_Option(RegSet_T a); /* option [ a ] */
RegSet_T RegSet_Plus(RegSet_T a); /* iteration a + */
RegSet_T RegSet_Plus_ntimes(RegSet_T a, int n)
/* iteration { a } n-times, n >= 0 */
;
RegSet_T RegSet_Plus_range(RegSet_T a, int lwr, int upr)
/* iteration { a } lwr-times .. upr-times, lwr >= 0, upr >= 0 */
;
c_bool RegSet_isChar(RegSet_T a); /* a = 'x' ? */
wc_char RegSet_charVal(RegSet_T a); /* x; assertion: a = 'x' */
/* ----------------------- Scanner production ----------------------------- */
AbstractType(ScnDfn_T) /* Scanner production handle */
;
void Scn_dfnBegin(c_string name)
/* begins a scanner definition;
uses 'name' as identifier
*/
;
ScnDfn_T Scn_dfnBegin_reentrant(c_string name)
/* reentrant version of Scn_dfnBegin */
;
void Scn_setMsgFun(void (*prMsg)(c_string msg))
/* defines 'prMsg' as default message function */
;
void Scn_setMsgFun_reentrant(ScnDfn_T curdfn, void (*prMsg)(c_string msg))
/* reentrant version of Scn_setMsgFun */
;
void Scn_dfnToken(c_string name, c_byte tok_flags, RegSet_T value)
/* adds a new token to the scanner under production
'name' : identifier
'flags': attributes ( see [scn_base] )
'value': regular set
*/
;
void Scn_dfnToken_reentrant
(
ScnDfn_T curdfn, c_string name, c_byte tok_flags, RegSet_T value
)
/* reentrant version of Scn_dfnToken */
;
void Scn_dfnDyckToken
(
c_string name, c_byte tok_flags,
RegSet_T left, Scn_T dyck
)
/* adds a new dyck token to the scanner under production;
consumes 'dyck'
'name' : identifier
'flags': attributes ( see [scn_base] )
'left' : regular set for left paranthesis
'dyck' : dyck scanner ( left, inner and right token )
*/
;
void Scn_dfnDyckToken_reentrant
(
ScnDfn_T curdfn, c_string name, c_byte tok_flags,
RegSet_T left, Scn_T dyck
)
/* reentrant version of Scn_dfnToken */
;
void RegSet_Print(RegSet_T x)
/* prints regular set to stdout; for debugging */
;
void RegSet_Print_reentrant(ScnDfn_T curdfn, RegSet_T x)
/* reentrant version of RegSet_Print */
;
Scn_T Scn_dfnEnd(c_bool diagnose)
/* completes and creates scanner definition
diagnose --> prints scanner definiton
*/
;
Scn_T Scn_dfnEnd_reentrant(ScnDfn_T curdfn, c_bool diagnose)
/* reentrant version of Scn_dfnEnd;
consumes 'curdfn'
*/
;
/* ----------------------- Scanner group production ------------------------ */
Scn_T ScnGrp_dfnBegin(c_string name)
/* begins a scanner group definition;
uses 'name' as identifier
*/
;
void ScnGrp_dfnScanner(Scn_T group, Scn_T scanner)
/* adds 'scanner' to 'group'; consumes 'scanner' */
;
void ScnGrp_dfnSwitch(Scn_T group, c_string from, c_string token, c_string to)
/* adds context switch information for 'group';
'token' in scanner 'from' switches to scanner 'to'
*/
;
int ScnGrp_dfnEnd(Scn_T group)
/* completes definition for 'group';
returns number of unreachable scanners
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/prs.h 0000644 0001750 0001750 00000017776 12112434362 011210 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [prs.h] LALR(1) Parser */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef prs_INCL
#define prs_INCL
#include "prs_io.h" /* to complete the interface */
#include "otab.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
This module [prs] does the actual - low level - parsing based on a given
STYX-konform parse table definition. ( see [prs_gen] )
The parser is reentrant and allows multiple parse operations at a time.
A second facility refers to its flexible configuration which for example
allows the use of another scanner than provided by the STYX system.
Within the STYX system the parse interface will only be used by the higher
level parse and term construction module [ptm_gen].
Beside that the module offers access to the parse table definition.
The parser handles syntax errors as described below:
On activated early reduction mode and in the case none of the nonterminals
are specified as resumption points the parse process will stop.
Otherwise a variant of the panic-mode error recovery method which only tracks
the specified nonterminals will be applied.
Nonterminal conversion macros
*/
/* Nonterminal index to symbol */
#define PLR_NTI_TO_NTS(t,i) (PLR_tokenCnt(t)+(i))
/* Nonterminal symbol to index */
#define PLR_NTS_TO_NTI(t,s) ((s)-PLR_tokenCnt(t))
/* Nonterminal symbol to class */
#define PLR_NTS_TO_NTC(t,s) PLR_ntClass((t), \
PLR_ntClassId((t),PLR_NTS_TO_NTI(t,s)))
int PLR_startSymbol(PLR_Tab PTab, int startId)
/* startsymbol 'startId' of parse table 'PTab'
[startId=0..StartCnt-1] --> [0..SymbolCnt-1]
*/
;
c_bool PLR_isErrorNt(PLR_Tab PTab, int ntId)
/* whether 'ntId' is an error nonterminal of parse table 'PTab'
[ntId=0..NtCnt-1]
*/
;
int PLR_ntClassId(PLR_Tab PTab, int ntId)
/* class index of nonterminal 'ntId' of parse table 'PTab'
[ntId=0..NtCnt-1] --> [0..NtCnt-1]
*/
;
int PLR_ntClass(PLR_Tab PTab, int ntClsId)
/* class symbol of nonterminal 'ntId' of parse table 'PTab'
[ntClsId=0..NtCnt-1] --> [0..SymbolCnt-1]
*/
;
int PLR_symType(PLR_Tab PTab, int symId)
/* type of symbol 'symId' of parse table 'PTab' [symId=0..SymbolCnt-1] */
;
c_string PLR_symName(PLR_Tab PTab, int symId)
/* name of symbol 'symId' of parse table 'PTab' [symId=0..SymbolCnt-1] */
;
int PLR_prodCnt(PLR_Tab PTab)
/* number of productions of parse table 'PTab' */
;
int PLR_prodNonTerm(PLR_Tab PTab, int prodId)
/* nonterminal of production 'prodId' of parse table 'PTab'
[prodId=0..PCnt-1] --> [0..SymbolCnt-1]
*/
;
int PLR_prodMethod(PLR_Tab PTab, int prodId); /* unused */
int PLR_prodSymCnt(PLR_Tab PTab, int prodId)
/* number of members of production 'prodId'
of parse table 'PTab' [prodId=0..PCnt-1]
*/
;
int PLR_prodSymbol(PLR_Tab PTab, int prodId, int psymId)
/* symbol of production 'prodId' and member 'psymId'
of parse table 'PTab'
[prodId=0..PCnt-1,psymId=0..PSCnt-1] --> [0..SymbolCnt-1]
*/
;
int PLR_prodDSymIdx(PLR_Tab PTab, int prodId)
/* dynamic symbol member index of production 'prodId'
of parse table 'PTab' or -1
[prodId=0..PCnt-1] --> [0..PSCnt-1]
*/
;
int PLR_prodDSymSym(PLR_Tab PTab, int prodId)
/* dynamic symbol member of production 'prodId'
of parse table 'PTab' or -1
[prodId=0..PCnt-1] --> [0..SymbolCnt-1]
*/
;
int PLR_prodSymFrm(PLR_Tab PTab, int prodId, int psymId)
/* layout info for production 'prodId' and member 'psymId'
of parse table 'PTab'
[prodId=0..PCnt-1,psymId=0..PSCnt-1] -->
[negative(-->NL)] column position
*/
;
c_string PLR_prodName(PLR_Tab PTab, int prodId)
/* name of production 'prodId' of parse table 'PTab'
[prodId=0..PCnt-1]
*/
;
int PLR_stateCnt(PLR_Tab PTab); /* number of states in parse table 'PTab' */
ROW(int) PLR_shiftValues(PLR_Tab PTab, int stateId)
/* shift value ( tokenId, followStateId ) ...
of state 'stateId' in parse table 'PTab'; allocs result row
[followStateId,stateId=0..StateCnt-1, tokenId=0..TokenCnt-1]
*/
;
ROW(int) PLR_gotoValues(PLR_Tab PTab, int ntId)
/* goto value ( followStateId, fromStateId ) ...
of nonterminal 'ntId' in parse table 'PTab'; allocs result row
[followStateId,fromStateId=0..StateCnt-1, ntId=0..NtCnt-1]
*/
;
ROW(int) PLR_actionValues(PLR_Tab PTab, int stateId)
/* action value ( error=-2|accept=-1|prodId, tokenId|startId|-1 ) ...
of state 'stateId' in parse table 'PTab'; allocs result row
[stateId=0..StateCnt-1, prodId=0..PCnt-1,
tokenId=0..TokenCnt-1, startId=TokenCnt..TokenCnt+StartCnt-1]
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/dicts.h 0000644 0001750 0001750 00000006066 12112434362 011500 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [dicts.h] Type: Dictionary Iterator */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef dicts_INCL
#define dicts_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ---------------------- The Type ----------------------------------------- */
/*
The dictionary iterator provides sequentiell, platform-independant access to
a specified part of the file system.
Supported platforms are Unix and Windows.
*/
AbstractType(DII); /* Abstract dictionary iterator type */
/* --------------------------- Create & Drop -------------------------------- */
DII DII_make
(
c_string PathName, c_string Pattern,
c_bool recursive, c_bool skipErr
)
/* creates a ['recursive'] dictionary iterator for
directory 'PathName' and file 'Pattern'
'skipErr' --> error message on open failure, otherwise the program aborts
*/
;
void DII_drop(DII dii); /* drops dictionary iterator 'dii' */
/* ------------------------- Dictionary iterator access -------------------- */
c_bool DII_empty(DII dii); /* empty dictionary iterator ? */
void DII_next(DII dii); /* next dictionary entry */
c_bool DII_isFile(DII dii); /* dictionary entry = file ? */
c_bool DII_isDir(DII dii); /* dictionary entry = directory ? */
c_bool DII_isCDev(DII dii); /* dictionary entry = character device ? */
c_bool DII_isBDev(DII dii); /* dictionary entry = block device ? */
c_bool DII_isFifo(DII dii); /* dictionary entry = FIFO ? */
c_string DII_get_file(DII dii)
/* filename of dictionary entry; allocs memory */
;
c_string DII_get_base(DII dii)
/* basename of dictionary entry; allocs memory */
;
c_string DII_get_ext(DII dii)
/* extension of dictionary entry; allocs memory */
;
c_string DII_get_path(DII dii); /* path of dictionary entry; allocs memory */
/* ---------------------- Convenient iterator macros ----------------------- */
#define DII_FORALL(dii,Path,Pattern) \
for (dii = DII_make(Path,Pattern,C_False,C_False); \
DII_empty(dii)?DII_drop(dii),C_False:C_True; DII_next(dii))
#define DII_FORALL_R(dii,Path,Pattern) \
for (dii = DII_make(Path,Pattern,C_True,C_False); \
DII_empty(dii)?DII_drop(dii),C_False:C_True; DII_next(dii))
#define DII_SFORALL(dii,Path,Pattern) \
for (dii = DII_make(Path,Pattern,C_False,C_True); \
DII_empty(dii)?DII_drop(dii),C_False:C_True; DII_next(dii))
#define DII_SFORALL_R(dii,Path,Pattern) \
for (dii = DII_make(Path,Pattern,C_True,C_True); \
DII_empty(dii)?DII_drop(dii),C_False:C_True; DII_next(dii))
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/charlib.h 0000644 0001750 0001750 00000004203 12112434362 011765 0000000 0000000 /* -------------------------------------------------------------------------- */
/* */
/* [charlib.h] Basic Character ( Set ) & String Library */
/* */
/* Copyright (c) 1995 by D\olle, Manns */
/* -------------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef charlib_INCL
#define charlib_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ibmpc_a_uml 132
#define ibmpc_A_uml 142
#define ibmpc_o_uml 148
#define ibmpc_O_uml 153
#define ibmpc_u_uml 129
#define ibmpc_U_uml 154
#define ibmpc_sz 225
#define latin_a_uml 228
#define latin_A_uml 196
#define latin_o_uml 246
#define latin_O_uml 214
#define latin_u_uml 252
#define latin_U_uml 220
#define latin_sz 223
/* ---------------------- ( German ) Character types ------------------------ */
c_bool ger_islower(char c); /* german islower */
char ger_tolower(char c); /* german tolower */
c_bool ger_isupper(char c); /* german isupper */
char ger_toupper(char c); /* german toupper */
c_bool ger_isprint(char c); /* german isprint */
int ger_charcmp(char l, char r); /* l - r ( german ) */
/* ------------------------- Character conversion --------------------------- */
char umlaut_ascii_to_eascii(char c); /* us ascii --> extended/OEM ascii */
char umlaut_eascii_to_ascii(char c); /* extended/OEM ascii --> us ascii */
char umlaut_eascii_to_ansi(char c); /* extended/OEM ascii --> ansi */
char umlaut_ansi_to_eascii(char c); /* ansi --> extended/OEM ascii */
/* --------------------------- String match --------------------------------- */
c_bool Str_matches(c_string str, c_string pat)
/* whether 'str' matches 'pat'
meta characters: '*', '?'
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/cmd_pim.h 0000644 0001750 0001750 00000000500 12112434362 011765 0000000 0000000 /* [cmd_pim.h] Parser table for 'cmd' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef cmd_pim_INCL
#define cmd_pim_INCL
#include "prs.h"
#ifdef __cplusplus
extern "C" {
#endif
PLR_Tab PLR_get_cmd(); /* simulates a PLR_getTab */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/binset.h 0000644 0001750 0001750 00000010147 12112434362 011651 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [binset.h] Type: Binary Set */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef binset_INCL
#define binset_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------- Types and macros --------------------------------- */
/*
The elements in a binary set M with card(M) = N are represented by the numbers 0 .. N-1.
*/
AbstractType(BS_Set); /* Abstract binary set type */
/* Element, row and column index */
#define BS_RELEL(l,r,maxC) ( ( ( ( l ) - 1 ) * ( maxC ) ) + ( r ) )
/* r = SetElement 1 .. maxC */
/* l = SetElement 1 .. */
#define BS_RIDX(v,maxC) ( ( ( v ) - 1 ) / ( maxC ) + 1 )
#define BS_CIDX(v,maxC) ( ( ( v ) - 1 ) % ( maxC ) + 1 )
/* ------------------------------- Basics --------------------------------- */
BS_Set BS_init(BS_Set set); /* initializes set */
BS_Set BS_create(INT card); /* creates a binary set */
INT BS_card(BS_Set set); /* cardinality of set */
void BS_delS(BS_Set set); /* deletes set */
/* ----------------- Operations and predicates on one set ----------------- */
INT BS_setE(INT element, BS_Set set); /* adds element to set */
void BS_delE(INT element, BS_Set set); /* deletes element from set */
c_bool BS_member(INT element, BS_Set set); /* element in set ? */
c_bool BS_empty(BS_Set set); /* empty set ? */
INT BS_cnt(BS_Set set); /* number of elements in set */
/* ---------------- Operations and predicates on two sets ----------------- */
c_bool BS_equal(BS_Set left, BS_Set right); /* left = right ? */
c_bool BS_subset(BS_Set left, BS_Set right); /* left <= right ? */
BS_Set BS_copy(BS_Set dst, BS_Set src); /* copies src to dst */
BS_Set BS_union(BS_Set dst, BS_Set left, BS_Set right)
/* dst = left U right */
;
BS_Set BS_minus(BS_Set dst, BS_Set left, BS_Set right)
/* dst = left - right */
;
BS_Set BS_inter(BS_Set dst, BS_Set left, BS_Set right)
/* dst = left & right */
;
/* ------------------------ Binary graph ---------------------------------- */
INT BS_setGE(BS_Set rel, INT SetCard, INT from, INT to)
/* adds a vertice, requires initialized rel */
;
BS_Set BS_setG(BS_Set rel, INT SetCard, c_bool (*isRel)(INT from, INT to))
/* adds vertices, requires initialized rel */
;
BS_Set BS_copyR(BS_Set rel, BS_Set set, INT row, c_bool toGraph)
/* copies set to rel[row] (toGraph = True), rel[row] to set (toGraph = False) */
;
INT BS_findR(BS_Set rel, BS_Set set)
/* searches row with rel[row] = set, returns
row = 1 .. ( BS__CARD(rel) / BS__CARD(set) ) oder 0
*/
;
/* Identifier of other other
[reg_exp] implements a regular expression evaluator based on the
following regular expression syntax.
Literal
Construction
iterator macro for convenience */
#define HS_FORALL(elm,itr,set) for \
( \
itr = HS_CREATE_ITR(set); \
HS_EMPTY_ITR(itr) \
? (HS_DROP_ITR(itr), C_False) \
: (HS_GET(itr, ((StdCPtr)&elm)), C_True); \
)
/* ======================= Sets & Relations ================================= */
/* ------------------------- Creation of sets ------------------------------- */
HS_Set HS_createSet
( /* function parameter: */
c_bool (*equal)(HS_Elm l, HS_Elm r), /* equality on set elements */
long (*hash)(HS_Elm elm) /* hash value of set element */
)
#define HS_CREATE_SET(type,equ,hsh) \
HS_createSet \
( \
(c_bool (*)(HS_Elm l, HS_Elm r))(equ),(long (*)(HS_Elm elm))(hsh) \
)
#define HS_CREATE_ADTSET(type) HS_CREATE_SET(type,primEqual,primHash)
/** creates a new set */
;
/* ---------------------- Basics for sets and relations --------------------- */
void HS_dropSet(HS_Set set)
#define HS_DROP_SET HS_dropSet
/* removes set/relation 'set' */
;
HS_Set HS_clear(HS_Set set)
#define HS_CLEAR HS_clear
/* clears set/relation 'set'; removes all elements */
;
HS_Set HS_copy(HS_Set set)
#define HS_COPY HS_copy
/* copies set/relation 'set' */
;
/* -------------- Operations and predicates on one set/relation ------------- */
long HS_card(HS_Set set)
#define HS_CARD HS_card
/* cardinality of set/relation 'set' */
;
c_bool HS_emptySet(HS_Set set)
#define HS_EMPTY_SET HS_emptySet
/* whether set/relation 'set' is empty */
;
/*
The following functions can also be applied to relations.
In this case the element represents a tuple.
*/
void HS_setElm(HS_Elm elm, HS_Set set)
#define HS_SET_ELM(elm,set) HS_setElm(ABS_CAST(HS_Elm,elm),set)
/* set = set U { elm } */
;
void HS_delElm(HS_Elm elm, HS_Set set)
#define HS_DEL_ELM(elm,set) HS_delElm((HS_Elm)(elm),set)
/* set = set \ { elm } */
;
c_bool HS_mbrElm(HS_Elm elm, HS_Set set)
#define HS_MBR_ELM(elm,set) HS_mbrElm((HS_Elm)(elm),set)
/* whether 'elm' is a member of set/relation 'set' */
;
HS_Set HS_part(HS_Set set, c_bool (*wherepart)(HS_Elm elm))
#define HS_PART(set,where) HS_part(set,(c_bool (*)(HS_Elm elm))(where))
/* result = { e in set | wherepart(e) } */
;
/* ------------- Operations and predicates on two sets/relations ------------ */
/* The predicate functions expects equal types ! */
c_bool HS_equal(HS_Set l, HS_Set r)
#define HS_EQUAL HS_equal
/* l = r ? */
;
c_bool HS_subset(HS_Set l, HS_Set r)
#define HS_SUBSET HS_subset
/* l <= r ? */
;
HS_Set HS_union(HS_Set dst, HS_Set l, HS_Set r)
#define HS_UNION HS_union
/* dst = l U r */
;
HS_Set HS_minus(HS_Set dst, HS_Set l, HS_Set r)
#define HS_MINUS HS_minus
/* dst = l \ r */
;
HS_Set HS_inter(HS_Set dst, HS_Set l, HS_Set r)
#define HS_INTER HS_inter
/* dst = l & r */
;
HS_Set HS_product(HS_Set l, HS_Set r, c_bool plane)
#define HS_PRODUCT HS_product
/* result = l X r ( plane --> no tuple hierarchy ) */
;
/* ------------------------- Creation of relations -------------------------- */
HS_Set HS_createRel
( /* function parameter: */
int argcnt, /* tuple arity; number of following pairs */
c_bool (*equal)(HS_Dom l, HS_Dom r), /* equality on tuple components */
long (*hash)(HS_Dom d), ... /* hash value of tuple component */
)
#define HS_CREATE_REL_2(t1,e1,h1,t2,e2,h2) \
HS_createRel \
( \
4, \
(c_bool (*)(HS_Dom l, HS_Dom r))(e1), \
(long (*)(HS_Dom d))(h1), \
(c_bool (*)(HS_Dom l, HS_Dom r))(e2), \
(long (*)(HS_Dom d))(h2) \
)
#define HS_CREATE_ADTREL_2(t1,t2) \
HS_CREATE_REL_2(t1,primEqual,primHash,t2,primEqual,primHash)
/** creates a new relation */
;
/* ------------------------- Basics for relations --------------------------- */
int HS_arity(HS_Elm tpl)
#define HS_ARITY HS_arity
/* number of tuple components */
;
HS_Dom HS_tplcol(HS_Elm tpl, int Nth)
#define HS_TPLCOL(typ,t,n) ((typ)HS_tplcol(t,n))
/* Nth tuple component ( Nth >= 1 ) */
;
/* --------------- Operations and predicates on one relation ---------------- */
void HS_setTpl(int argcnt, HS_Set rel, HS_Dom dom, ...)
#define HS_SETTPL_2(d1,d2,rel) HS_setTpl(3,rel,(HS_Dom)(d1),(HS_Dom)(d2))
/* rel = rel U { (dom,...) } */
;
void HS_delTpl(int argcnt, HS_Set rel, HS_Dom dom, ...)
#define HS_DELTPL_2(d1,d2,rel) HS_delTpl(3,rel,(HS_Dom)(d1),(HS_Dom)(d2))
/* rel = rel \ { (dom,...) } */
;
c_bool HS_mbrTpl
(
int argcnt, HS_Set rel, HS_Dom dom, ...
)
#define HS_MBRTPL_2(d1,d2,rel) HS_mbrTpl(3,rel,(HS_Dom)(d1),(HS_Dom)(d2))
/* whether (dom,...) is a member of relation 'rel' */
;
HS_Set HS_project(HS_Set rel, int Nth)
#define HS_PROJECT HS_project
/* result = rel.Nth column ( Nth >= 1 ) */
;
HS_Set HS_range
(
int argcnt, HS_Set rel, HS_Dom dom, ...
)
#define HS_RANGE_1(d,rel) HS_range(2,rel,(HS_Dom)(d))
/* result = Range((dom,...)) */
;
HS_Set HS_domain
(
int argcnt, HS_Set rel, HS_Dom rng, ...
)
#define HS_DOMAIN_1(r,rel) HS_domain(2,rel,(HS_Dom)(r))
/* result = Domain((rng,...)) */
;
HS_Set HS_trans(HS_Set rel)
#define HS_TRANS HS_trans
/* R' (reverse elements) */
;
/*
The following functions can be applied only to binary relations
over a single domain !
*/
HS_Set HS_rclosure(HS_Set dst, HS_Set rel, HS_Set set)
#define HS_IR_RCLOSURE HS_rclosure
#define HS_R_RCLOSURE(d,r) HS_rclosure(d,r,(HS_Set)NULL)
/* dst = R + Id ( relation 'rel', domain 'set' ) */
;
HS_Set HS_sclosure(HS_Set dst, HS_Set rel)
#define HS_SCLOSURE HS_sclosure
/* dst = R + R' */
;
HS_Set HS_closure(HS_Set dst, HS_Set rel, HS_Set set)
#define HS_IR_CLOSURE HS_closure
#define HS_R_CLOSURE(d,r) HS_closure(d,r,(HS_Set)NULL)
/* dst = R* ( relation 'rel', domain 'set' ) */
;
HS_Set HS_iclosure(HS_Set dst, HS_Set rel)
#define HS_ICLOSURE HS_iclosure
/* dst = R+ */
;
HS_Set HS_eclosure
(
HS_Set dst, HS_Set rel, HS_Set set, int (*compare)(HS_Dom l, HS_Dom r)
)
#define HS_IR_ECLOSURE HS_eclosure
#define HS_R_ECLOSURE(d,r,c) HS_eclosure(d,r,(HS_Set)NULL,c)
/* dst = (R + R')* ( relation 'rel', domain 'set' and 'compare' ) */
;
void HS_quotient(HS_Set eclosure,int (*compare)(HS_Dom l, HS_Dom r))
#define HS_QUOTIENT(ecl,cmp) \
HS_quotient(ecl,(int (*)(HS_Dom l, HS_Dom r))(cmp))
/* re-sets class representants [eclosure] of partition 'eclosure' */
;
HS_Dom HS_class(HS_Dom dom, HS_Set eclosure)
#define HS_CLASS(typ,dom,ecl) ((typ)HS_class((HS_Dom)(dom),ecl))
/* get class representant [dom] of domain 'dom' in partition 'eclosure' */
;
HS_Set HS_kern(HS_Set dst, HS_Set iclosure)
#define HS_KERN HS_kern
/* dst = R+ \ square(R+) */
;
HS_Set HS_conclusion(HS_Set dst, HS_Set rel)
#define HS_CONCLUSION HS_conclusion
/* dst = square(R) */
;
/* --------------- Operations and predicates on two relations --------------- */
HS_Set HS_join
(
int argcnt, HS_Set l, HS_Set r, /* ( long cl, long cr ) */ ...
)
#define HS_JOIN(l,r) HS_join(2,l,r)
#define HS_JOIN_1(l,r,cl,cr) HS_join(4,l,r,(long)(cl),(long)(cr))
/** joins two relations, using columns ( cl, cr ),... */
;
/*
The following functions can be applied only to binary relations !
*/
HS_Set HS_compose(HS_Set dst, HS_Set l, HS_Set r)
#define HS_COMPOSE HS_compose
/* dst = l * r ( special binary relation --> binary relation ) */
;
/* ---------------------------- Printing ------------------------------------ */
void HS_fprint
(
FILE* file,
HS_Set set,
int indent,
void (*fpMember)(FILE *file, HS_Elm elm)
)
#define HS_PRINT(set,ind,pMbr) \
HS_fprint(STDOUT,set,(ind),(void (*)(FILE *file, HS_Elm elm))(pMbr))
/* prints set/relation 'set' to 'file' */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/lim__cim.h 0000644 0001750 0001750 00000000511 12112434362 012127 0000000 0000000 /* [lim__cim.h] Context table for 'lim_test' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef lim__cim_INCL
#define lim__cim_INCL
#include "ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void CTX_init_lim_test(int argc, c_string argv[]); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/styx_lim.h 0000644 0001750 0001750 00000000510 12112434362 012226 0000000 0000000 /* [styx_lim.h] Scanner table for 'styx' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef styx_lim_INCL
#define styx_lim_INCL
#include "scn_io.h"
#ifdef __cplusplus
extern "C" {
#endif
void Scn_get_styx(Scn_T *scn); /* simulates a Scn_get */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/literal.h 0000644 0001750 0001750 00000003124 12112434362 012016 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [literal.h] Literal Conversion */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef literal_INCL
#define literal_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------- String to C-Literal ---------------------------- */
c_string LIT_c_str_lit(c_string s)
/* converts string 's' to a C-Literal; allocs memory
( single byte character set or UTF-8 )
*/
;
c_string LIT_c_char_lit(char c)
/* converts character 'c' to a C-Literal; allocs memory
( single byte character set or UTF-8 )
*/
;
/* --------------------- STYX-Literal to string ------------------------- */
int LIT_hex2_char(int h1, int h2)
/* constructs a single byte character from the hex values 'h1' and 'h2' */
;
int LIT_hex_val(int h, int p)
/*
constructs a unicode character from up to 8 hex values;
has to be called for each hex value and the result added to get the final code
h = hex digit, p = position [ 0 .. 7 ]
*/
;
wc_string LIT_styx_lit_str(long *len, c_string s, c_bool* ucs4)
/* converts STYX literal 's' to a string; allocs memory
( 'ucs4' --> unicode character found in literal )
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/ptm_gen.h 0000644 0001750 0001750 00000017532 12112434362 012023 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [ptm_gen.h] Parse Term Construction */
/* - during parse process - */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef ptm_gen_INCL
#define ptm_gen_INCL
#include "symbols.h"
#include "scn_base.h"
#include "scn_abs.h"
#include "prs_dfn.h"
#include "prs_abs.h"
#include "ptm.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
The module [ptm_gen] provides a high-level parse interface. It implements
the construction of the parse tree / term during the parse process.
The scan, parse and term construction functions are reentrant which offers
the possibility of multiple concurrent parse operations.
*/
/* ------------------------- Types ------------------------------------------ */
AbstractType(PT_Diag); /* Abstract parse term diagnose type */
AbstractType(PT_Cfg); /* Abstract parse term configuration type */
/* ------------------------ Parsing & Term Construction -------------------- */
PT_Cfg PT_init(PLR_Tab PTab, Scn_Stream cStream)
/* initializes parse term construction
for parse table 'PTab' and scan stream 'cStream';
creates a configuration
*/
;
PT_Cfg PT_init_extscn(PLR_Tab PTab, AbsScn_T sconfig)
/* initializes parse term construction
for parse table 'PTab' and external scanner 'sconfig';
creates a configuration
*/
;
PT_Cfg PT_init_ext(AbsPlr_T pconfig, AbsScn_T sconfig)
/* initializes parse term construction
for external parser 'pconfig' and external scanner 'sconfig';
creates a configuration
*/
;
void PT_setMsgFun(void (*prMsg)(c_string msg))
/* defines 'prMsg' as ( static ) default message function
( 'msg': single byte character set or UTF-8 )
*/
;
void PT_setDiagFun(PT_Cfg PCfg, PT_Diag PDiag)
/* adds diagnose environment 'PDiag' to
parse term configuration 'PCfg'
*/
;
void PT_setTokConvFun(PT_Cfg PCfg, symbol convTok(symbol tok, symbol val))
/* adds token value converter 'convTok' to
parse term configuration 'PCfg'
( user-defined shift-handler )
*/
;
void PT_setNtmConvFun(PT_Cfg PCfg, PT_Term convNtm(PT_Term Tree))
/* adds nonterminal value converter 'convNtm' to
parse term configuration 'PCfg'
( user-defined reduce-handler; must release each replaced source tree )
*/
;
void PT_setTokConvFunEx
(
PT_Cfg PCfg,
symbol convTok(symbol tok, symbol val, Any_T ctx),
Any_T ctx
)
/* like PT_setTokConvFun
Additionally, a non-NULL context 'ctx' will be passed
to the shift-handler.
Both handler must use the same context.
( currently not supported by 'pim_test' )
*/
;
void PT_setNtmConvFunEx
(
PT_Cfg PCfg, PT_Term convNtm(PT_Term Tree, Any_T ctx),
Any_T ctx
)
/* like PT_setNtmConvFun
Additionally, a non-NULL context 'ctx' will be passed
to the reduce-handler.
Both handler must use the same context.
( currently not supported by 'pim_test' )
*/
;
void PT_setEParser
(
PT_Cfg PCfg,
Abs_T newEParser(Any_T ePlrCtx, c_string language),
void freeEParser(Abs_T eParser),
Any_T ePlrCtx
)
/* adds embedded parser constructor 'newEParser',
destructor 'freeEParser' and some context 'ePlrCtx' to
parse term configuration 'PCfg';
must be set for embedded languages
*/
;
void PT_quit(PT_Cfg PCfg)
/* terminates parse term construction;
removes configuration 'PCfg'
*/
;
PT_Term PT_parse(PT_Cfg PCfg, c_string StartSymbol, c_bool interprete)
#define PT_PARSE(pcfg,start) PT_parse((pcfg),(start),C_False)
#define PT_INTERPRETE(pcfg,start) PT_parse((pcfg),(start),C_True)
/* parses and constructs parse term of type C ( see [ptm] )
according configuration 'PCfg';
uses 'StartSymbol' as start nonterminal or default if empty
( interprete --> early reduction )
*/
;
PT_Term XPT_parse(PT_Cfg PCfg, c_string StartSymbol, c_bool interprete)
#define XPT_PARSE(pcfg,start) XPT_parse((pcfg),(start),C_False)
#define XPT_INTERPRETE(pcfg,start) XPT_parse((pcfg),(start),C_True)
/* parses and constructs parse term of type Xaron ( see [ptm] )
according configuration 'PCfg';
uses 'StartSymbol' as start nonterminal or default if empty
( interprete --> early reduction )
*/
;
int PT_synErrorCnt(PT_Cfg PCfg)
/* number of syntax errors in parse term configuration 'PCfg' */
;
symbol PT_ErrorSymbol(PT_Cfg PCfg)
/* symbol of error token in parse term configuration 'PCfg' */
;
/* --------------------------- Semantic Analysis ---------------------------- */
/* ---------------- ... using the default environment ( static ) ------------ */
void PT_diagnose(PT_Term PTree, c_string format, ...)
/* prints a test message for parse term node 'PTree'
according variable format specification 'format' and '...'
*/
;
void PT_error(PT_Term PTree, c_string format, ...)
/* increments the number of semantic errors and
prints an error message for parse term node 'PTree'
according variable format specification 'format' and '...'
*/
;
void PT_warn(PT_Term PTree, c_string format, ...)
/* increments the number of warnings and
prints a warning message for parse term node 'PTree'
according variable format specification 'format' and '...'
*/
;
void PT_setErrorCnt(int cnt)
/* resets the number of semantic errors with 'cnt' */
;
int PT_errorCnt(void); /* number of semantic errors */
void PT_setWarningCnt(int cnt); /* resets the number of warnings with 'cnt' */
int PT_warnCnt(void); /* number of warnings */
/* ---------------- ... using the diagnose environment ( reentrant ) -------- */
PT_Diag PT_diag_init(void (*prMsg)(c_string msg))
/* creates a diagnose environment
using 'prMsg' as message function
( 'msg': single byte character set or UTF-8 )
*/
;
void PT_diag_quit(PT_Diag PDiag); /* removes diagnose environment 'PDiag' */
void PT_diag_msg(PT_Term PTree, PT_Diag PDiag, c_string format, ...)
/* prints a message for parse term node 'PTree'
according diagnose environment 'PDiag',
variable format specification 'format' and '...'
*/
;
void PT_diag_test(PT_Term PTree, PT_Diag PDiag, c_string format, ...)
/* like PT_diag_msg; prints a test message */
;
void PT_diag_err(PT_Term PTree, PT_Diag PDiag, c_string format, ...)
/* increments the number of semantic errors
in diagnose environment 'PDiag' and
prints an error message for parse term node 'PTree'
according variable format specification 'format' and '...'
*/
;
void PT_diag_warn(PT_Term PTree, PT_Diag PDiag, c_string format, ...)
/* increments the number of warnings
in diagnose environment 'PDiag' and
prints a warning message for parse term node 'PTree'
according variable format specification 'format' and '...'
*/
;
void PT_diag_setErrorCnt(PT_Diag PDiag, int cnt)
/* resets the number of semantic errors
in diagnose environment 'PDiag' with 'cnt'
*/
;
int PT_diag_errorCnt(PT_Diag PDiag)
/* number of semantic errors in diagnose environment 'PDiag' */
;
void PT_diag_setWarningCnt(PT_Diag PDiag, int cnt)
/* resets number of warnings
in diagnose environment 'PDiag' with 'cnt'
*/
;
int PT_diag_warnCnt(PT_Diag PDiag)
/* number of warnings in diagnose environment 'PDiag' */
;
void (*PT_diag_msgFun(PT_Diag PDiag))(c_string msg)
/* message function in diagnose environment 'PDiag' */
;
/* ---------------- Accessing configuration ( Xaron support ) --------------- */
Scn_Stream PT_stream(PT_Cfg PCfg)
/* current scan stream in parse term configuration 'PCfg' */
;
PLR_Tab PT_ptab(PT_Cfg PCfg)
/* current parse table in parse term configuration 'PCfg' */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/hmap.h 0000644 0001750 0001750 00000024601 12112434362 011312 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [hmap.h] Type: Finite Map */
/* Endliche Abbildungen mittels dynamischen Hashing */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef hmap_INCL
#define hmap_INCL
#include "standard.h"
#include "prim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
[hmap] implements finite maps based on dynamic hashing.
*/
/* ------------------------- Types and macros ------------------------------ */
AbstractType( HMP_Dom ); /* Abstract domain type of maps */
AbstractType( HMP_Rng ); /* Abstract range type of maps */
#define MAP(Alpha,Beta) HMP_Map /* Polymorphic MAP - Type */
#define MAPIT HMP_Itr /* Polymorphic ITR - Type */
#define MAPTY HMP_Typ /* Polymorphic meta-type of MAPs */
AbstractType( HMP_Typ ) /* Abstract meta-type of maps */
/* "Klasse" der Abbildungen */
;
ConcreteType( HMP_Ent )
/* interner Typ; Kette der Defintionen mit gleichem Hash-Wert */
;
typedef HMP_Ent __HUGE *HMP_Tab; /* interner Typ; das hash-array */
AbstractType( HMP_Map ) /* Abstract type of maps */
;
/* ------------------------- Meta type of hash maps ------------------------ */
HMP_Typ HMP_newTyp
( /* function parameter: */
HMP_Dom (*domcpy)(HMP_Dom a), /* copies a domain */
void (*domfre)(HMP_Dom a), /* frees a domain */
c_bool (*domequ)(HMP_Dom a, HMP_Dom b), /* equality on domains */
long (*domhsh)(HMP_Dom a), /* hash value of domain */
HMP_Rng (*rngcpy)(HMP_Rng a), /* copies a range */
void (*rngfre)(HMP_Rng a) /* frees a range */
)
#define MAP_newTyp(dc, df, de, dh, rc, rf) \
HMP_newTyp( \
(HMP_Dom (*)(HMP_Dom a)) dc, \
(void (*)(HMP_Dom a)) df, \
(c_bool (*)(HMP_Dom a,HMP_Dom b)) de, \
(long (*)(HMP_Dom a)) dh, \
(HMP_Rng (*)(HMP_Rng a)) rc, \
(void (*)(HMP_Rng a)) rf \
)
/** defines a new hash type */
;
void HMP_freeTyp( HMP_Typ t )
#define MAP_freeTyp HMP_freeTyp
/* frees hash type 't' */
;
HMP_Dom (*HMP_domcpy(HMP_Typ t))(HMP_Dom a)
#define MAP_domcpy(Alpha,t) ((Alpha (*)(Alpha a)) HMP_domcpy(t))
/* get domain copy function of hash type 't' */
;
void (*HMP_domfre(HMP_Typ t))(HMP_Dom a)
#define MAP_domfre(Alpha,t) ((void (*)(Alpha a)) HMP_domfre(t))
/* get domain free function of hash type 't' */
;
c_bool (*HMP_domequ(HMP_Typ t))(HMP_Dom a, HMP_Dom b)
#define MAP_domequ(Alpha,t) ((c_bool (*)(Alpha a, Alpha b)) HMP_domequ(t))
/* get domain equal function of hash type 't' */
;
long (*HMP_domhsh(HMP_Typ t))(HMP_Dom a)
#define MAP_domhsh(Alpha,t) ((long (*)(Alpha a)) HMP_domhsh(t))
/* get domain hash function of hash type 't' */
;
HMP_Rng (*HMP_rngcpy(HMP_Typ t))(HMP_Rng a)
#define MAP_rngcpy(Beta ,t) ((Beta (*)(Beta a)) HMP_rngcpy(t))
/* get range copy function of hash type 't' */
;
void (*HMP_rngfre(HMP_Typ t))(HMP_Rng a)
#define MAP_rngfre(Beta ,t) ((void (*)(Beta a)) HMP_rngfre(t))
/* get range free function of hash type 't' */
;
/* =============================== Hash Maps ============================== */
/* -------------------------- Creating & Disposing ------------------------ */
HMP_Map HMP_newMap( HMP_Typ t )
#define MAP_newMap HMP_newMap
/* creates a new empty map */
;
void HMP_freeMap(HMP_Map m)
#define MAP_freeMap HMP_freeMap
/* removes map 'm' from storage
all references to 'm' are invalidated!
*/
;
/* ------------------------------- Accessing ------------------------------ */
HMP_Typ HMP_MapTyp(HMP_Map m)
#define MAP_MapTyp HMP_MapTyp
/* get meta-type of map 'm' */
;
long HMP_count(HMP_Map m)
#define MAP_count HMP_count
/* number of domain values on which map 'm' is defined
HMP_count(m) == | { d in HMP_Dom | HMP_defined(m,d) } |
*/
;
c_bool HMP_emptyMap(HMP_Map m)
#define MAP_emptyMap HMP_emptyMap
/* whether map 'm' is empty
HMP_emptyMap(m) == (HMP_count(m) == 0)
*/
;
c_bool HMP_defined(/* con */ HMP_Map m, /* con */ HMP_Dom d)
#define MAP_defined(m,d) HMP_defined(m,(HMP_Dom)(d))
/* whether domain 'd' is defined in map 'm' */
;
HMP_Rng HMP_apply(/* con */ HMP_Map m, /* con */ HMP_Dom d)
#define MAP_apply(Beta,m,d) ABS_CAST(Beta,HMP_apply(m,(HMP_Dom)(d)))
#define MAP_apply_small(Beta,m,d) ((Beta)((long)HMP_apply(m,(HMP_Dom)(d))))
#define MAP_apply_short(m,d) ((short)((long)HMP_apply(m,(HMP_Dom)(d))))
/* get range of domain 'd' in map 'm'
raises execption if not HMP_defined(m,d)
*/
;
/* ------------------------------ Modifying ------------------------------- */
void HMP_ovrdom(/* var */ HMP_Map m, /* con */ HMP_Dom d, /* con */ HMP_Rng r)
#define MAP_ovrdom(m,d,r) HMP_ovrdom(m,ABS_CAST(HMP_Dom,d),ABS_CAST(HMP_Rng,r))
/* defines pair ( 'd', 'r' ) or updates range of domain 'd' in map 'm'
m := m \ { (d, r) }
*/
;
void HMP_dfndom(/* var */ HMP_Map m, /* con */ HMP_Dom d, /* con */ HMP_Rng r)
#define MAP_dfndom(m,d,r) HMP_dfndom(m,ABS_CAST(HMP_Dom,d),ABS_CAST(HMP_Rng,r))
#define MAP_define MAP_dfndom
/* defines pair ( 'd', 'r' ) in map'm'
m := m U { (d, r) }; raises exception if HMP_defined(m,d)
*/
;
void HMP_upddom(/* var */ HMP_Map m, /* con */ HMP_Dom d, /* con */ HMP_Rng r)
#define MAP_upddom(m,d,r) HMP_upddom(m,(HMP_Dom)(d),(HMP_Rng)(r))
#define MAP_update MAP_upddom
/* updates range of domain 'd' in map 'm'
m := m \ { (d, r) }; raises exception if not HMP_defined(m,d)
*/
;
void HMP_rmvdom(/* con */ HMP_Map m, /* con */ HMP_Dom d)
#define MAP_rmvdom(m,d) HMP_rmvdom(m,(HMP_Dom)(d))
#define MAP_remove MAP_rmvdom
/* removes domain 'd' from map 'm'
makes m(d) be undefined; raises exception if not HMP_defined(m,d)
*/
;
void HMP_rmvall(/* var */ HMP_Map m)
#define MAP_rmvall HMP_rmvall
/* clears map 'm'
makes m(d) be undefined for all d
*/
;
/* --------------------- Basic hash set iterator -------------------------- */
/* Do not modify the content of an hash set
while using a basic iterator on this set.
*/
AbstractType( HMP_Itr ) /* Abstract type of iterators on maps */
;
/* ------------------------- Creating & Disposing ------------------------- */
HMP_Itr HMP_newItr(HMP_Map m)
#define MAP_newItr HMP_newItr
/* creates an iterator on hash set 'm' */
;
void HMP_freeItr(HMP_Itr i)
#define MAP_freeItr HMP_freeItr
/* removes iterator 'i' */
;
/* ------------------------ Accessing & Modifiying ------------------------ */
c_bool HMP_emptyItr(HMP_Itr i)
#define MAP_emptyItr HMP_emptyItr
/* whether iterator 'i' is empty */
;
void HMP_getItr(HMP_Itr i, HMP_Dom *d)
#define MAP_getItr(i,d) HMP_getItr(i,(HMP_Dom *) d)
/* get the next domain from iterator 'i' into 'd'
raises exception if 'HMP_emptyItr(i)'
*/
;
void HMP_getItrAsg(HMP_Itr i, HMP_Dom *d, HMP_Rng *r)
#define MAP_getItrAsg(i,d,r) HMP_getItrAsg(i,(HMP_Dom *)(d),(HMP_Rng *)(r))
/* get the next pair ( domain, range ) from iterator 'i' into 'd' and 'r'
raises exception if 'HMP_emptyItr(i)'
*/
;
/* ---------------------- Convenient iterator macros ----------------------- */
/* For - statement with basic iterators. Make sure to
free the iterator if you leave the loop via break.
*/
#define MAP_forItr(DomVar,ItrVar,MapExpr) \
for (ItrVar = MAP_newItr(MapExpr); \
MAP_emptyItr(ItrVar) \
? (MAP_freeItr(ItrVar), C_False) \
: (MAP_getItr(ItrVar, ((StdCPtr)&DomVar)), C_True );\
)
#define MAP_forItrAsg(DomVar,RngVar,ItrVar,MapExpr) \
for (ItrVar = MAP_newItr(MapExpr); \
MAP_emptyItr(ItrVar) \
? (MAP_freeItr(ItrVar), C_False) \
: (MAP_getItrAsg(ItrVar, ((StdCPtr)&DomVar), ((StdCPtr)&RngVar)), C_True );\
)
/* ------------------------------- Operations on maps --------------------- */
MAP(_,_) MAP_copy(MAP(_,_) a)
/* copies map 'a';
The result map references the type of map 'a'.
*/
;
/* ------------------------------- Printing ------------------------------- */
void HMP_fprintMap
(
FILE *f,
HMP_Map m,
int indent,
void (*fprintPair)(FILE *f, HMP_Dom d, HMP_Rng r, int indent)
)
#define MAP_fprintMap HMP_fprintMap
/* prints map 'm' to file 'f' */
;
void HMP_printMap
(
HMP_Map m,
int indent,
void (*printPair)(HMP_Dom d, HMP_Rng r, int indent)
)
#define MAP_printMap HMP_printMap
/* prints map 'm' to 'stdout' */
;
/* ------------------- Debugging & Profiling ------------------------------ */
void HMP_technicalView
(
HMP_Map m,
int indent,
void (*printPair)(HMP_Dom d, HMP_Rng r, int indent)
)
/* For visual inspection and debugging purposes */
;
/* ---------------------------- Primitive Maps ---------------------------- */
/*
Primitive maps have an implicit meta-type which treats the
domain and range values as anonymous pointer.
The domain / range copy function return the element itself.
The domain / range free function do nothing.
The domain equal function performs a simple '==' operation.
The domain hash function simply hashes the domain ( pointer ) value.
*/
void MAP_init(void); /* inits this module ( create meta-type ) */
void MAP_quit(void); /* quits this module ( free meta-type ) */
MAP(_,_) MAP_newPrimMap(void); /* creates a primitive map */
c_bool MAP_prim_equal(MAP(_,_) a, MAP(_,_) b)
/* whether the primitive maps 'a' and 'b' are equal */
;
MAP(_,_) MAP_prim_copy(MAP(_,_) a); /* copies the primitive map 'a' */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/memosx.h 0000644 0001750 0001750 00000002255 12112434362 011676 0000000 0000000 /* -------------------------------------------------------------------------- */
/* */
/* [memosx.h(mem_base)] Memory Management */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* -------------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef mem_base_INCL
#define mem_base_INCL
#include "sysbase0.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------------- Memory ----------------------------------- */
long ObjCount(void); /* allocated objects */
StdCPtr NewMem(long objsize)
/* creates an object of size 'objsize'; raises exception */
;
#if !defined(HAVE_CONFIG_H) || defined(HAVE_REALLOC)
StdCPtr ResizeMem(StdCPtr Any, long objsize)
/* resizes an object to size 'objsize'; raises exception */
;
#endif
void FreeMem(StdCPtr Any); /* frees object 'Any' */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/cmd_lim.h 0000644 0001750 0001750 00000000504 12112434362 011765 0000000 0000000 /* [cmd_lim.h] Scanner table for 'cmd' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef cmd_lim_INCL
#define cmd_lim_INCL
#include "scn_io.h"
#ifdef __cplusplus
extern "C" {
#endif
void Scn_get_cmd(Scn_T *scn); /* simulates a Scn_get */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/hpat_pim.h 0000644 0001750 0001750 00000000504 12112434362 012162 0000000 0000000 /* [hpat_pim.h] Parser table for 'hpat' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef hpat_pim_INCL
#define hpat_pim_INCL
#include "prs.h"
#ifdef __cplusplus
extern "C" {
#endif
PLR_Tab PLR_get_hpat(); /* simulates a PLR_getTab */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/list.h 0000644 0001750 0001750 00000003630 12112434362 011337 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [list.h] Type: List */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef list_INCL
#define list_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ---------------------------- The Type --------------------------------- */
/*
This module implements a functional,i.e. LISP-like list data type.
*/
#define List(Abs_T) list
AbstractType(List(Abs_T)); /* Abstract list type */
/* ---------------------------- Operations and predicates ---------------- */
c_bool empty(List(Abs_T) x); /* whether list 'x' is empty */
Abs_T list_fst(List(Abs_T) x)
#define fst(TYPE, LIST) ((TYPE) list_fst(LIST))
/* first member of list 'x' */
;
List(Abs_T) rst(List(Abs_T) x); /* rest of list 'x' */
List(Abs_T) cons(Abs_T fst, List(Abs_T) rst); /* list constructor */
List(Abs_T) *rst_ref(List(Abs_T) x); /* pointer to rest(x); use with care! */
Abs_T *fst_ref(List(Abs_T) x); /* pointer to first(x); use with care! */
int length(List(Abs_T) x); /* length of list 'x' */
void pList(List(Abs_T) x, int Indent, void (*pMember)(Abs_T x))
/* prints list 'x' to stdout */
;
void pListEx
(
List(Abs_T) x, int Indent,
void (*pMember)(Abs_T x, StdCPtr any), StdCPtr any
)
/* prints list 'x' to stdout;
uses 'any' as member context
*/
;
void freeList(List(Abs_T) x, void (*freeMember)(Abs_T x))
/* frees list 'x' */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/gls.h 0000644 0001750 0001750 00000011231 12112434362 011145 0000000 0000000 /* ---------------------------------------------------------------------- */
/* */
/* [gls.h] Generic Language Support */
/* */
/* Copyright (c) 1994 by Lars D\olle, Heike Manns */
/* ---------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef gls_INCL
#define gls_INCL
#include "standard.h"
#include "ptm.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
[gls] provides a generic interface for the token and nonterminal lists of
the abstract derivation trees in the generated grammar-specific interface
modules ( ... to skip comments, keywords and ignore-nodes
Token separation types
*/
#define PTP_SEP_NON 0 // none
#define PTP_SEP_SPC 1 // space
#define PTP_SEP_IND 2 // indent
#define PTP_SEP_ROW 3 // row
AbstractType(PTP_T) /* Abstract transformation and pp type */
;
/* ---------------------------- Init & Quit -------------------------------- */
void PTP_init(PLR_Tab tab)
/* initializes transformation and pretty printing
based on parse table 'tab' as target grammar specification
*/
;
PTP_T PTP_init_reentrant(PLR_Tab tab); /* reentrant version of PTP_init */
void PTP_quit(void); /* terminates transformation and pretty printing */
void PTP_quit_reentrant(PTP_T ctx)
/* reentrant version of PTP_quit; consumes 'ctx' */
;
void PTP_set_line(int len); /* set 'len' as line length for pretty printing */
void PTP_set_line_reentrant(PTP_T ctx, int len)
/* reentrant version of PTP_set_line */
;
void PTP_tok_sep(symbol t_lft, symbol t_rgt, int sep)
/* specifies the kind of seperation ( 'sep' )
between the token 't_rgt' and 't_lft';
replaces a previously defined seperation
*/
;
void PTP_tok_sep_reentrant(PTP_T ctx, symbol t_lft, symbol t_rgt, int sep)
/* reentrant version of PTP_tok_sep */
;
void PTP_tok_conv(symbol t_id, symbol (*conv)(symbol t_id, symbol t_src))
/* specifies a conversion 'conv' for token 't_id';
replaces a previously defined conversion
't_id' = NULL --> apply 'conv' to all tokens
*/
;
void PTP_tok_conv_reentrant
(
PTP_T ctx, symbol t_id, symbol (*conv)(symbol t_id, symbol t_src)
)
/* reentrant version of PTP_tok_conv */
;
void PTP_tok_cset(c_bool utf8, c_bool wprint)
/* specifies source character set (single/multi-byte) and
pp output (on multi-byte source character set)
*/
;
void PTP_tok_cset_reentrant(PTP_T ctx, c_bool utf8, c_bool wprint)
/* reentrant version of PTP_tok_cset */
;
/* ------------------------- Term Pretty Printer --------------------------- */
void PTP_pp(PT_Term tree, FILE* fp)
/* performs pretty printing on parse term 'tree'
( output to file 'fp' )
*/
;
void PTP_pp_reentrant(PTP_T ctx, PT_Term tree, FILE* fp)
/* rrentrant version of PTP_pp */
;
/* ------------------------- Tree Transformation --------------------------- */
PT_Term PTP_nt_transform_aux(PT_Term tree, symbol nt)
/* performs tree-to-tree transformation on source 'tree';
uses 'nt' as startsymbol
*/
;
PT_Term PTP_nt_transform_aux_reentrant
(
PTP_T ctx, PT_Term tree, symbol nt
)
/* reentrant version of PTP_nt_transform_aux */
;
PT_Term PTP_transform(PT_Term tree)
/* performs tree-to-tree transformation on source 'tree' */
;
PT_Term PTP_transform_reentrant(PTP_T ctx, PT_Term tree)
/* reentrant version of PTP_transform */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/styx_int.h 0000644 0001750 0001750 00000025400 12116661367 012257 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [styx_int.h] Language Interface */
/* */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef styx_int_INCL
#define styx_int_INCL
#include "ptm.h"
#include "gls.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------- symbol objects - init & quit --------------------- */
void styx_initSymbols(); /* */
void styx_quitSymbols(); /* */
/* -------------------------- Types & Constants --------------------------- */
AbstractType( styx );
AbstractType( styxSource );
AbstractType( styxOptCfg );
AbstractType( styxQlxDfn );
AbstractType( styxQlxCat );
AbstractType( styxQlxGrp );
AbstractType( styxQlxOpt );
AbstractType( styxExp );
AbstractType( styxOptNat );
AbstractType( styxLimit );
AbstractType( styxDfn );
AbstractType( styxCat );
AbstractType( styxDfnOpt );
AbstractType( styxLay );
AbstractType( styxPrd );
AbstractType( styxMbr );
AbstractType( styxConflict );
AbstractType( styxState );
AbstractType( styxToken );
AbstractType( styxRule );
/* --------------------------- Access to Tokens --------------------------- */
c_bool Tstyx_Ide(GLS_Tok x); /* */
c_bool Tstyx_Nat(GLS_Tok x); /* */
c_bool Tstyx_Set(GLS_Tok x); /* */
c_bool Tstyx_Seq(GLS_Tok x); /* */
/* --------------------------- Access to Terms ---------------------------- */
c_bool styx_styx(PT_Term x, styx* x1); /* */
c_bool styx_Source(PT_Term x, styxSource* x1); /* */
c_bool styx_OptCfg(PT_Term x, styxOptCfg* x1); /* */
c_bool styx_QlxDfn(PT_Term x, styxQlxDfn* x1); /* */
c_bool styx_QlxCat(PT_Term x, styxQlxCat* x1); /* */
c_bool styx_QlxGrp(PT_Term x, styxQlxGrp* x1); /* */
c_bool styx_QlxOpt(PT_Term x, styxQlxOpt* x1); /* */
c_bool styx_Exp(PT_Term x, styxExp* x1); /* */
c_bool styx_OptNat(PT_Term x, styxOptNat* x1); /* */
c_bool styx_Limit(PT_Term x, styxLimit* x1); /* */
c_bool styx_Dfn(PT_Term x, styxDfn* x1); /* */
c_bool styx_Cat(PT_Term x, styxCat* x1); /* */
c_bool styx_DfnOpt(PT_Term x, styxDfnOpt* x1); /* */
c_bool styx_Lay(PT_Term x, styxLay* x1); /* */
c_bool styx_Prd(PT_Term x, styxPrd* x1); /* */
c_bool styx_Mbr(PT_Term x, styxMbr* x1); /* */
c_bool styx_Conflict(PT_Term x, styxConflict* x1); /* */
c_bool styx_State(PT_Term x, styxState* x1); /* */
c_bool styx_Token(PT_Term x, styxToken* x1); /* */
c_bool styx_Rule(PT_Term x, styxRule* x1); /* */
/* --------------------------------- styx --------------------------------- */
c_bool styx_Start_Source(styx x, styxSource* x1)
#define styx_Start_0 styx_Start_Source
;
/* -------------------------------- Source -------------------------------- */
c_bool styxSource_root(styxSource x, styxOptNat* x1, GLS_Tok* x2,
GLS_Lst(styxQlxDfn)* x3, styxOptCfg* x4)
;
/* -------------------------------- OptCfg -------------------------------- */
c_bool styxOptCfg_non(styxOptCfg x); /* */
c_bool styxOptCfg_cfg(styxOptCfg x, GLS_Lst(styxDfn)* x1, GLS_Lst(styxConflict)* x2); /* */
/* -------------------------------- QlxDfn -------------------------------- */
c_bool styxQlxDfn_defd(styxQlxDfn x, GLS_Tok* x1); /* */
c_bool styxQlxDfn_defn(styxQlxDfn x, styxQlxCat* x1, styxQlxOpt* x2,
styxQlxGrp* x3, GLS_Tok* x4,
styxQlxGrp* x5, styxExp* x6)
;
c_bool styxQlxDfn_igrp(styxQlxDfn x, GLS_Tok* x1); /* */
c_bool styxQlxDfn_tgrp(styxQlxDfn x, GLS_Tok* x1); /* */
c_bool styxQlxDfn_mgrp(styxQlxDfn x, GLS_Tok* x1, GLS_Lst(GLS_Tok)* x2);/* */
c_bool styxQlxDfn_xgrp(styxQlxDfn x, GLS_Tok* x1); /* */
/* -------------------------------- QlxCat -------------------------------- */
c_bool styxQlxCat_comC(styxQlxCat x); /* */
c_bool styxQlxCat_indC(styxQlxCat x); /* */
c_bool styxQlxCat_letC(styxQlxCat x); /* */
c_bool styxQlxCat_tokC(styxQlxCat x); /* */
c_bool styxQlxCat_lanC(styxQlxCat x); /* */
c_bool styxQlxCat_ignC(styxQlxCat x); /* */
/* -------------------------------- QlxGrp -------------------------------- */
c_bool styxQlxGrp_non(styxQlxGrp x); /* */
c_bool styxQlxGrp_pigrp(styxQlxGrp x); /* */
c_bool styxQlxGrp_pop(styxQlxGrp x); /* */
c_bool styxQlxGrp_igrp(styxQlxGrp x); /* */
c_bool styxQlxGrp_pgrp(styxQlxGrp x, GLS_Tok* x1); /* */
c_bool styxQlxGrp_grp(styxQlxGrp x, GLS_Tok* x1); /* */
/* -------------------------------- QlxOpt -------------------------------- */
c_bool styxQlxOpt_ignca(styxQlxOpt x); /* */
c_bool styxQlxOpt_non(styxQlxOpt x); /* */
/* --------------------------------- Exp ---------------------------------- */
c_bool styxExp_conc(styxExp x, styxExp* x1, styxExp* x2); /* */
c_bool styxExp_diff(styxExp x, styxExp* x1, styxExp* x2); /* */
c_bool styxExp_sequ(styxExp x, GLS_Tok* x1); /* */
c_bool styxExp_plusn(styxExp x, styxExp* x1, styxLimit* x2); /* */
c_bool styxExp_plus0(styxExp x, styxExp* x1); /* */
c_bool styxExp_dyck(styxExp x, styxExp* x1, styxExp* x2,
styxExp* x3)
;
c_bool styxExp_non(styxExp x); /* */
c_bool styxExp_opt(styxExp x, styxExp* x1); /* */
c_bool styxExp_range(styxExp x, styxExp* x1, styxExp* x2); /* */
c_bool styxExp_plus(styxExp x, styxExp* x1); /* */
c_bool styxExp_epat(styxExp x, styxExp* x1, GLS_Tok* x2,
styxExp* x3)
;
c_bool styxExp_set(styxExp x, GLS_Tok* x1); /* */
c_bool styxExp_union(styxExp x, styxExp* x1, styxExp* x2); /* */
c_bool styxExp_quot(styxExp x, styxExp* x1, styxExp* x2); /* */
c_bool styxExp_ident(styxExp x, GLS_Tok* x1); /* */
c_bool styxExp_star(styxExp x, styxExp* x1); /* */
c_bool styxExp_spat(styxExp x, styxExp* x1, GLS_Tok* x2,
styxExp* x3)
;
/* -------------------------------- OptNat -------------------------------- */
c_bool styxOptNat_non(styxOptNat x); /* */
c_bool styxOptNat_nat(styxOptNat x, GLS_Tok* x1); /* */
/* -------------------------------- Limit --------------------------------- */
c_bool styxLimit_range(styxLimit x, GLS_Tok* x1, styxOptNat* x2); /* */
c_bool styxLimit_ntime(styxLimit x, GLS_Tok* x1); /* */
/* --------------------------------- Dfn ---------------------------------- */
c_bool styxDfn_defn(styxDfn x, styxCat* x1, styxDfnOpt* x2,
GLS_Tok* x3, GLS_Lst(styxPrd)* x4)
;
/* --------------------------------- Cat ---------------------------------- */
c_bool styxCat_letC(styxCat x); /* */
c_bool styxCat_bgnC(styxCat x); /* */
/* -------------------------------- DfnOpt -------------------------------- */
c_bool styxDfnOpt_non(styxDfnOpt x); /* */
c_bool styxDfnOpt_errnt(styxDfnOpt x); /* */
/* --------------------------------- Lay ---------------------------------- */
c_bool styxLay_grp(styxLay x); /* */
c_bool styxLay_rec(styxLay x); /* */
c_bool styxLay_dft(styxLay x); /* */
/* --------------------------------- Prd ---------------------------------- */
c_bool styxPrd_prod(styxPrd x, styxLay* x1, GLS_Tok* x2,
GLS_Lst(styxMbr)* x3)
;
/* --------------------------------- Mbr ---------------------------------- */
c_bool styxMbr_opt(styxMbr x, GLS_Lst(GLS_Tok)* x1, styxMbr* x2,
GLS_Lst(GLS_Tok)* x3)
;
c_bool styxMbr_dtok(styxMbr x, GLS_Tok* x1, GLS_Tok* x2); /* */
c_bool styxMbr_klst1(styxMbr x, GLS_Lst(GLS_Tok)* x1, styxMbr* x2,
GLS_Lst(GLS_Tok)* x3, GLS_Lst(GLS_Tok)* x4)
;
c_bool styxMbr_tkm(styxMbr x, GLS_Tok* x1); /* */
c_bool styxMbr_ntm(styxMbr x, GLS_Tok* x1); /* */
c_bool styxMbr_klst0(styxMbr x, GLS_Lst(GLS_Tok)* x1, styxMbr* x2,
GLS_Lst(GLS_Tok)* x3, GLS_Lst(GLS_Tok)* x4)
;
c_bool styxMbr_else(styxMbr x); /* */
/* ------------------------------- Conflict ------------------------------- */
c_bool styxConflict_defn(styxConflict x, styxState* x1, styxToken* x2,
GLS_Lst(styxRule)* x3)
;
/* -------------------------------- State --------------------------------- */
c_bool styxState_nat(styxState x, GLS_Tok* x1); /* */
c_bool styxState_ide(styxState x, GLS_Tok* x1); /* */
c_bool styxState_seq(styxState x, GLS_Tok* x1); /* */
/* -------------------------------- Token --------------------------------- */
c_bool styxToken_seq(styxToken x, GLS_Tok* x1); /* */
c_bool styxToken_ide(styxToken x, GLS_Tok* x1); /* */
/* --------------------------------- Rule --------------------------------- */
c_bool styxRule_red(styxRule x, GLS_Tok* x1, GLS_Tok* x2); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/pim__cim.h 0000644 0001750 0001750 00000000511 12112434362 012133 0000000 0000000 /* [pim__cim.h] Context table for 'pim_test' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef pim__cim_INCL
#define pim__cim_INCL
#include "ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void CTX_init_pim_test(int argc, c_string argv[]); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/glo_tab.h 0000644 0001750 0001750 00000004435 12112434362 011777 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [glo_tab.h] Global Table */
/* */
/* Copyright (c) 1993 by Lars D\olle, Heike Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef glo_tab_INCL
#define glo_tab_INCL
#include "standard.h"
#include "symbols.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Through the means of the module [glo_tab] it is possible to store and retrieve
arbitrary pairs ( key, value ) with a bijective mapping between them.
This defines a special global process memory.
Originally this functionality was needed in order to make statically bind C-functions
persistent. ( see also [binimg] )
In addition this module handles i.e. keeps track of dynamical loaded objects. This module [scn_abs] provides an abstract scanner interface for the
term generation module [ptm_gen].
It can be used to integrate an externally defined scanner with the STYX term
generation facility.
*/
/* ----------------------------- The Types --------------------------------- */
AbstractType(AbsScn_T); /* Abstract scanner interface type */
/*
Types of the scanner (interface) functions
*/
typedef void (*SF_scan )(Abs_T scanner);
typedef short (*SF_tok )(Abs_T scanner);
typedef symbol (*SF_symbol )(Abs_T scanner);
typedef long (*SF_pos )(Abs_T scanner);
typedef c_bool (*SF_flag )(Abs_T scanner);
typedef void (*SF_defID )(Abs_T scanner, short id);
typedef c_bool (*SF_defDynID )(Abs_T scanner, symbol sym, short id);
typedef void (*SF_defTxtID )(Abs_T scanner, c_string text, short id);
typedef void (*SF_defWCTxtID)(Abs_T scanner, wc_string text, short id);
typedef Any_T (*SIF_eTerm )
(
Abs_T CurPTCfg, c_string language, c_string StartSymbol
);
typedef c_bool (*SIF_eAccept )(Abs_T CurPTCfg);
/* ---------------------------- Init & Quit -------------------------------- */
AbsScn_T AS_init(void); /* creates an abstract scanner interface */
void AS_quit(AbsScn_T sconfig)
/* removes abstract scanner interface 'sconfig' */
;
/* -------------- Specification of the external scanner interface ---------- */
void AS_setScanner(AbsScn_T sconfig, Abs_T scanner)
/* specifies the external 'scanner' of the abstract interface 'sconfig'
( see Scn_Stream )
*/
;
/*
An external defined scanner must provide the following interface
functions. They have to be assigned to the abstract scanner interface
before initializing the term generation. That module calls them
during the construction of the derivation tree.
*/
void AS_setFunNextTok(AbsScn_T sconfig, SF_scan nextTok)
/* specifies 'nextTok' as corresponding function for Stream_next
in the abstract interface 'sconfig'
*/
;
void AS_setFunTokID(AbsScn_T sconfig, SF_tok tokID)
/* specifies 'tokID' as corresponding function for Stream_ctid
in the abstract interface 'sconfig'
*/
;
void AS_setFunTokSym(AbsScn_T sconfig, SF_symbol tokSym)
/* specifies 'tokSym' as corresponding function for Stream_csym
in the abstract interface 'sconfig'
*/
;
void AS_setFunStreamSym(AbsScn_T sconfig, SF_symbol streamSym)
/* specifies 'streamSym' as corresponding function for Stream_cfil
in the abstract interface 'sconfig'
*/
;
void AS_setFunTokRow(AbsScn_T sconfig, SF_pos tokRow)
/* specifies 'tokRow' as corresponding function for Stream_clin
in the abstract interface 'sconfig'
*/
;
void AS_setFunTokCol(AbsScn_T sconfig, SF_pos tokCol)
/* specifies 'tokCol' as corresponding function for Stream_ccol
in the abstract interface 'sconfig'
*/
;
void AS_setFunUnicode(AbsScn_T sconfig, SF_flag unicode)
/* specifies 'tokCol' as corresponding function for Stream_ccol
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefEofID(AbsScn_T sconfig, SF_defID defEofID)
/* specifies 'defEofID' as corresponding function for Stream_defEofId
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefErrID(AbsScn_T sconfig, SF_defID defErrID)
/* specifies 'defErrID' as corresponding function for Stream_defErrId
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefTokID(AbsScn_T sconfig, SF_defTxtID defTokID)
/* specifies 'defTokID' as corresponding function for Stream_defTokId
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefDynKeyID(AbsScn_T sconfig, SF_defDynID defDynKeyID)
/* specifies 'defDynKeyID' as corresponding function for Stream_defDynKeyId
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefKeyID(AbsScn_T sconfig, SF_defTxtID defKeyID)
/* specifies 'defKeyID' as corresponding function for Stream_defKeyId
in the abstract interface 'sconfig'
*/
;
void AS_setFunDefWCKeyID(AbsScn_T sconfig, SF_defWCTxtID defWCKeyID)
/* specifies 'defWCKeyID' as corresponding function for Stream_defWCKeyId
in the abstract interface 'sconfig'
*/
;
/*
An external defined scanner must call the following handler
to construct an embedded language token.
This handler will be set by the term construction module.
*/
void AS_setETermInfo
(
AbsScn_T sconfig, Abs_T CurPTCfg, SIF_eTerm eTerm, SIF_eAccept eAccept
)
/* specifies 'eTerm' as embedded language token constructor and
'eAccept' as embedded language accept token recognizer
in the abstract interface 'sconfig'
*/
;
/* -------------- Accessing the external scanner interface ----------------- */
Abs_T AS_getScanner(AbsScn_T sconfig)
/* get the external scanner of the abstract interface 'sconfig' */
;
SF_scan AS_getFunNextTok(AbsScn_T sconfig)
/* get the corresponding function for Stream_next
in the abstract interface 'sconfig'
*/
;
SF_tok AS_getFunTokID(AbsScn_T sconfig)
/* get the corresponding function for Stream_ctid
in the abstract interface 'sconfig'
*/
;
SF_symbol AS_getFunTokSym(AbsScn_T sconfig)
/* get the corresponding function for Stream_csym
in the abstract interface 'sconfig'
*/
;
SF_symbol AS_getFunStreamSym(AbsScn_T sconfig)
/* get the corresponding function for Stream_cfil
in the abstract interface 'sconfig'
*/
;
SF_pos AS_getFunTokRow(AbsScn_T sconfig)
/* get the corresponding function for Stream_clin
in the abstract interface 'sconfig'
*/
;
SF_pos AS_getFunTokCol(AbsScn_T sconfig)
/* get the corresponding function for Stream_ccol
in the abstract interface 'sconfig'
*/
;
SF_flag AS_getFunUnicode(AbsScn_T sconfig)
/* get the corresponding function for Stream_ccol
in the abstract interface 'sconfig'
*/
;
SF_defID AS_getFunDefEofID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defEofId
in the abstract interface 'sconfig'
*/
;
SF_defID AS_getFunDefErrID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defErrId
in the abstract interface 'sconfig'
*/
;
SF_defTxtID AS_getFunDefTokID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defTokId
in the abstract interface 'sconfig'
*/
;
SF_defDynID AS_getFunDefDynKeyID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defDynKeyId
in the abstract interface 'sconfig'
*/
;
SF_defTxtID AS_getFunDefKeyID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defKeyId
in the abstract interface 'sconfig'
*/
;
SF_defWCTxtID AS_getFunDefWCKeyID(AbsScn_T sconfig)
/* get the corresponding function for Stream_defWCKeyId
in the abstract interface 'sconfig'
*/
;
SIF_eTerm AS_getFunETerm(AbsScn_T sconfig)
/* get the embedded language token constructor
from the abstract interface 'sconfig'
*/
;
SIF_eAccept AS_getEofETerm(AbsScn_T sconfig)
/* get the embedded language accept token recognizer
from the abstract interface 'sconfig'
*/
;
Abs_T AS_getCurPTCfg(AbsScn_T sconfig)
/* get the current parse term configuration
from the abstract interface 'sconfig'
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/olist.h 0000644 0001750 0001750 00000020074 12112434362 011517 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [olist.h] Type: Operational List */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef olist_INCL
#define olist_INCL
#include "standard.h"
#include "prim.h" /* for primitive types */
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------- Types ---------------------------------------- */
/*
This module implements an operational, double linked list data type.
In distinction from functional lists operational lists consist of
a header and the double linked elements.
Beside element type information the header contains references to the
first, last and current element.
*/
AbstractType(OL_Lst); /* Abstract operational list type */
AbstractType(OL_Obj); /* Abstract list element type */
/* ---------------------- Creation and basic access ------------------------- */
OL_Lst OL_create
( /* function parameter: */
OL_Obj (*copy)(OL_Obj obj), /* copies an element */
void (*del)(OL_Obj obj), /* frees an element */
c_bool (*equal)(OL_Obj lobj, OL_Obj robj) /* equality on elements */
)
#define OL_CREATE(type,cpy,del,equ) \
OL_create \
( \
(OL_Obj (*)(OL_Obj obj)) cpy, \
(void (*)(OL_Obj obj)) del, \
(c_bool (*)(OL_Obj lobj, OL_Obj robj)) equ \
)
#define OL_CREATE_ADT(type) OL_CREATE(type,primCopy,primFree,primEqual)
/** creates an operational list */
;
void OL_init(OL_Lst objlist)
#define OL_INIT OL_init
/* resets / initializes list 'objlist' */
;
INT OL_cnt(OL_Lst objlist)
#define OL_CNT OL_cnt
/* number of elements in list 'objlist' */
;
/* --------------------- List copy as reading cursor ------------------------ */
OL_Lst OL_copyL(OL_Lst dst, OL_Lst src)
#define OL_COPY_L OL_copyL
/* copies list 'src';
fills list 'dst' with references to elements in 'src'
*/
;
void OL_delC(OL_Lst objlist)
#define OL_DEL_C OL_delC
/* removes list 'objlist' only - without elements */
;
/* --------------------------- Get & Search --------------------------------- */
OL_Obj OL_first(OL_Lst objlist)
#define OL_FIRST(type,lst) ( ABS_CAST(type,OL_first(lst)) )
/* first element of list 'objlist' */
;
OL_Obj OL_last(OL_Lst objlist)
#define OL_LAST(type,lst) ( ABS_CAST(type,OL_last(lst)) )
/* last element of list 'objlist' */
;
OL_Obj OL_next(OL_Lst objlist)
#define OL_NEXT(type,lst) ( ABS_CAST(type,OL_next(lst)) )
/* next element of list 'objlist' */
;
OL_Obj OL_prev(OL_Lst objlist)
#define OL_PREV(type,lst) ( ABS_CAST(type,OL_prev(lst)) )
/* previous element of list 'objlist' */
;
OL_Obj OL_curr(OL_Lst objlist)
#define OL_CURR(type,lst) ( ABS_CAST(type,OL_curr(lst)) )
/* current element of list 'objlist' */
;
INT OL_find(OL_Lst objlist, OL_Obj obj, c_bool (*cmp)(OL_Obj lobj, OL_Obj obj))
#define OL_FIND_EQ(lst,obj) \
OL_find(lst,ABS_CAST(OL_Obj,obj),(c_bool (*)(OL_Obj lobj, OL_Obj Obj))NULL)
#define OL_FIND(lst,obj,cmp) \
OL_find(lst,ABS_CAST(OL_Obj,obj),(c_bool (*)(OL_Obj lobj, OL_Obj Obj)) cmp)
/* position of key element 'obj' in list 'objlist' or 0 ( linear search ) */
;
/* --------------------------- Insert & Update ------------------------------ */
OL_Obj OL_h_ins(OL_Lst objlist, OL_Obj newobj)
#define OL_H_INS(type,lst,obj) \
( ABS_CAST(type,OL_h_ins(lst,ABS_CAST(OL_Obj,obj))) )
/* inserts 'newobj' as first element in list 'objlist' */
;
OL_Obj OL_t_ins(OL_Lst objlist, OL_Obj newobj)
#define OL_T_INS(type,lst,obj) \
( ABS_CAST(type,OL_t_ins(lst,ABS_CAST(OL_Obj,obj))) )
/* inserts 'newobj' as last element in list 'objlist' */
;
OL_Obj OL_c_ins(OL_Lst objlist, OL_Obj newobj)
#define OL_C_INS(type,lst,obj) \
( ABS_CAST(type,OL_c_ins(lst,ABS_CAST(OL_Obj,obj))) )
/* inserts 'newobj' before current element in list 'objlist'
( or as last element, if 'objlist' is empty )
*/
;
OL_Obj OL_s_ins(OL_Lst objlist, OL_Obj newobj,
c_bool (*cmpLE)(OL_Obj lobj, OL_Obj newobj))
#define OL_S_INS(type,lst,obj,cmpLE) \
( \
ABS_CAST(type,OL_s_ins \
(lst,ABS_CAST(OL_Obj,obj), \
(c_bool (*)(OL_Obj lobj, OL_Obj newobj))cmpLE)) \
)
/* inserts element 'newobj' in list 'objlist' ( sorted ) */
;
OL_Obj OL_upd(OL_Lst objlist, OL_Obj newobj)
#define OL_UPD(type,lst,obj) \
( ABS_CAST(type,OL_upd(lst,ABS_CAST(OL_Obj,obj))) )
/* updates current element in list 'objlist' with 'newobj' */
;
/* ----------------------------- Copy & Append ------------------------------ */
OL_Lst OL_copy(OL_Lst objlist)
#define OL_COPY OL_copy
/* copies list 'objlist' */
;
OL_Lst OL_append(OL_Lst dst, OL_Lst src)
#define OL_APPEND OL_append
/* appends list 'src' to list 'dst'; 'src' won't be removed */
;
/* ------------------------------ Delete ------------------------------------ */
void OL_clear(OL_Lst objlist)
#define OL_CLEAR OL_clear
/* clears list 'objlist'; removes all elements */
;
void OL_delL(OL_Lst objlist)
#define OL_DEL_L OL_delL
/* removes list 'objlist */
;
void OL_delE(OL_Lst objlist)
#define OL_DEL_E OL_delE
/* removes current element in list 'objlist' */
;
/* ----------------------------- Printing ----------------------------------- */
void OL_print(OL_Lst objlist, void (*pMbr)(OL_Obj obj), int cols, int indent)
#define OL_PRINT(lst,pMbr,cols,ind) \
OL_print(lst,(void (*)(OL_Obj obj)) pMbr,(cols),(ind))
/* prints list 'objlist' to stdout */
;
void OL_print_ex
(
OL_Lst objlist,
void (*pMbr)(OL_Obj obj,Any_T any,int nl,c_bool last),
Any_T any, int cols, int indent
)
#define OL_PRINT_EX(lst,pMbr,any,cols,ind) \
OL_print_ex(lst, \
(void (*)(OL_Obj o,Any_T any,int nl,c_bool last))pMbr, \
(any),(cols),(ind))
/* prints list 'objlist' to stdout */
;
/* ---------------------- Predicates on lists & Mapping --------------------- */
c_bool OL_equal(OL_Lst left,OL_Lst right)
#define OL_EQUAL OL_equal
/* left = right ? */
;
StdCPtr OL_map
( /* function parameter: */
int argcnt, /* number of arguments */
void (*fun)(OL_Obj* objs, StdCPtr any), /* element map function */
StdCPtr any, /* any additional context */
OL_Lst objlist, ... /* operational lists */
)
#define OL_MAP_F OL_map
/** executes 'fun' on each element in all lists */
;
c_bool OL_forall
( /* function parameter: */
int argcnt, /* number of arguments */
c_bool (*fun)(OL_Obj* objs, StdCPtr any), /* element map function */
StdCPtr any, /* any additional context */
OL_Lst objlist, ... /* operational lists */
)
#define OL_FORALL_P OL_forall
/** executes 'fun' on each element in all lists;
* on false execution stops
*/
;
c_bool OL_exists
( /* function parameter: */
int argcnt, /* number of arguments */
c_bool (*fun)(OL_Obj* objs, StdCPtr any), /* element map function */
StdCPtr any, /* any additional context */
OL_Lst objlist, ... /* operational lists */
)
#define OL_EXISTS_P OL_exists
/** executes 'fun' on each element in all lists;
* on true execution stops
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/styp_cim.h 0000644 0001750 0001750 00000000506 12112434362 012212 0000000 0000000 /* [styp_cim.h] Context table for 'stypp' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef styp_cim_INCL
#define styp_cim_INCL
#include "ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void CTX_init_stypp(int argc, c_string argv[]); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/symbols.h 0000644 0001750 0001750 00000005073 12112434362 012057 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [symbols.h] Type: Symbol */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef symbols_INCL
#define symbols_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
This module implements the symbol type for a unique representation of strings
and the symbol table in which they are stored. One intention is the reduction
of place- and time-complexity when dealing with many identical strings.
Specification
1) forall String s : strcmp(s,symbolToString(stringToSymbol(s))) == 0.
2) forall Symbol s : equalSymbols(s,stringToSymbol(symbolToString(s)).
3) equalSymbols is an equality.
*/
/* ------------------------------ The Type -------------------------------- */
AbstractType( symbol ) /* Abstract symbol type */
;
/* ----------------------------- Init & Quit ------------------------------ */
void initSymbols(void); /* initializes the symbol table */
void freeSymbols(void); /* releases the symbol table */
/* ----------------------------- Conversion ------------------------------- */
symbol stringToSymbol(c_string str); /* converts string 'str' into a symbol */
symbol lstringToSymbol(c_string str)
/* converts ( lower case ) string 'str' into a symbol */
;
symbol ustringToSymbol(c_string str)
/* converts ( upper case ) string 'str' into a symbol */
;
c_string symbolToString(symbol sym)
/* string corresponding to symbol 'sym' */
;
symbol bstringToSymbol(c_bstring bstr)
/* converts binary string 'bstr' into a symbol */
;
c_bstring symbolToBString(symbol sym)
/* binary string corresponding to symbol 'sym' */
;
/* ------------------------------ Predicates ------------------------------ */
c_bool equalSymbols(symbol a, symbol b)
/* whether two symbols 'a' and 'b' are equal */
;
c_bool binarySymbol(symbol s)
/* whether symbol 's' represents a binary string */
;
/* ----------------------------- Debugging -------------------------------- */
void printSymbols(int indent); /* prints the symbol table to stdout */
long countSymbols(void); /* number of symbols in the symbol table */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/sink.h 0000644 0001750 0001750 00000004476 12112434362 011341 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [sink.h] Type: Sink */
/* */
/* Copyright (c) 1993 by Doelle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef sink_INCL
#define sink_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
This module [sink] implements a dynamic sink i.e. string stream.
It uses the printf-konform formatting facility.
Note: Float and double values aren't supported yet.
*/
/* ---------------------------- The Type ---------------------------------- */
AbstractType( Sink ); /* Abstract sink / string stream type */
/* ---------------------------- Basics ------------------------------------ */
Sink Sink_open(void); /* creates a new sink */
void Sink_putc(Sink s, char c); /* adds character 'c' to sink 's' */
void Sink_puts(Sink s, c_string str); /* adds string 'str' to sink 's' */
void Sink_puts_raw(Sink s, c_string str)
/* adds string 'str' in a printable format to sink 's' */
;
c_string Sink_close(Sink s)
/* closes and converts sink 's' into a string;
allocs memory
*/
;
c_bool Sink_empty(Sink s); /* whether sink 's' is empty */
/* ---------------------------- Printing ---------------------------------- */
void xultoa_aux(Sink dst, unsigned long value, int radix)
/* converts and adds long 'value' to sink 'dst' */
;
c_string xultoa(unsigned long value, int radix)
/* converts long 'value' into a string; allocs memory */
;
void Sink_vprintf(Sink sink, c_string format, va_list args)
/* like 'vfprintf'
The text resulting from 'format' and arguments 'args'
will be added to 'sink'.
*/
;
void Sink_printf(Sink sink, c_string format, ...)
/* like 'fprintf'
The text resulting from 'format' and arguments '...'
will be added to 'sink'.
*/
;
c_string Str_printf(c_string format, ...)
/* like 'sprintf'
with resulting string from 'format' and arguments '...';
allocs memory
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/mem_base.h 0000644 0001750 0001750 00000002255 12112434363 012137 0000000 0000000 /* -------------------------------------------------------------------------- */
/* */
/* [mem_base.h] Memory Management */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* -------------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef mem_base_INCL
#define mem_base_INCL
#include "sysbase0.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------------- Memory ----------------------------------- */
long ObjCount(void); /* allocated objects */
StdCPtr NewMem(long objsize)
/* creates an object of size 'objsize'; raises exception */
;
#if !defined(HAVE_CONFIG_H) || defined(HAVE_REALLOC)
StdCPtr ResizeMem(StdCPtr Any, long objsize)
/* resizes an object to size 'objsize'; raises exception */
;
#endif
void FreeMem(StdCPtr Any); /* frees object 'Any' */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/line_scn.h 0000644 0001750 0001750 00000015674 12112434362 012171 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [line_scn.h] Source Line Scanner */
/* & simple AWK Functionality */
/* */
/* Copyright (c) 1994 by Lars D\olle, Heike Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef line_scn_INCL
#define line_scn_INCL
/*
[line_scn] contains a set of functions for source analysis.
1. The primitive
| string Line_get(FILE *SysIn)
reads the next line from the source file 'SysIn' and returns it as a string.
'\x1a' (DOS) and '(-1)' (UNIX) are recognized as end of file.
The end of line characters '\n' eg. '\r\n' and trailing spaces will be removed.
2. Further this module provides a simple AWK-mechanism.
3. The primitive
| string Line_getCFunNam(string CDecl)
extracts the function name from a C-deklaration/definition.
4. The primitive
| string Line_replace(string txt, MAP(symbol,symbol) ReplaceRules)
supports simple text replacement. Each occurance of a key in the given text will
be replaced by the associated value.
5. The primitive
| bool Line_split(string txt, string pat, string* left, string* right)
supports simple text separation. If 'pat' is a substring of 'txt' the prefix
will be assigned to 'left' and the suffix to 'right'.
6. The following functions support the removement/extraction of HTML/XML-tags,
C-comments and spaces in a given text.
| string Line_withTag(string txt)
| string Line_withoutTag(string txt)
| string Line_withCCom(string txt)
| string Line_withCComText(string txt)
| string Line_withoutCCom(string txt)
| string Line_withoutWhite(string txt)
| string Line_clip[L|R](string txt)
7. Finally this module defines a set of functions for URI-Creation/Evaluation. ( RFC 2396 )
*/
#include "standard.h"
#include "symbols.h"
#include "hmap.h"
#include "otab.h"
#ifdef __cplusplus
extern "C" {
#endif
/* -------------------------- Single line scanner ------------------------- */
c_string Line_get(FILE *SysIn)
/* get a single line or NULL; allocs memory
All '\r', final '\n', trailing spaces and tabs
are removed and other tabs expanded.
Both (-1) and (0x1a) are treated as EOF-character.
*/
;
/* ------------------------ Split line & AWK -------------------------------- */
AbstractType( AWK ); /* Abstract AWK type */
ROW(c_string) StrToWords(c_string s)
/* get a row with all the words of line 's' */
;
void AWK_defKey(AWK awk, c_string key, void (*act)(ROW(c_string) wrd))
/* adds a line key / action pair to 'awk' */
;
AWK AWK_new(c_string Comment)
/* creates an AWK structure
parameter: comment key
*/
;
void AWK_free(AWK awk); /* frees 'awk' */
void AWK_apply(AWK awk, c_string FileName)
/* evaluates 'FileName' according to the rules in 'awk' */
;
/* -------------------------- Text substitution --------------------------- */
c_string Line_clipR(c_string txt)
/* removes trailing white space; allocs memory */
;
c_string Line_clipL(c_string txt)
/* removes leading white space; allocs memory */
;
c_string Line_clip(c_string txt)
/* removes trailing and leading white space; allocs memory */
;
c_string Line_withoutWhite(c_string txt)
/* removes white space; allocs memory */
;
c_string Line_withTok
(
c_string txt,
void (*getNextTokPos)(c_string s, c_string* ta, c_string* te)
)
/* get token text only or NULL; allocs memory */
;
c_string Line_withoutTok
(
c_string txt,
void (*getNextTokPos)(c_string s, c_string* ta, c_string* te)
)
/* get text without token or NULL; allocs memory */
;
c_string Line_withoutTag(c_string txt)
/* get text without HTML/XML-tags or NULL; allocs memory */
;
c_string Line_withCCom(c_string txt)
/* get C-comment only or NULL; allocs memory */
;
c_string Line_withCComText(c_string txt)
/* get C-comment text only or NULL; allocs memory */
;
c_string Line_withoutCCom(c_string txt)
/* get text without C-comment or NULL; allocs memory */
;
c_string Line_getCFunNam(c_string CDecl)
/* extracts C-function name or NULL; allocs memory
assertion: no comments in between 'CDecl'
evaluation from right to left:
... The module [prs_gen] performs two main tasks.
1) A set of functions will be used to dynamically create a BNF-like context
free grammar definition. ( reentrant )
2) The latter function create the corresponding parse table and nonterminal
classes.
The parse table is the input for the parse function.
The STYX system comes up with a macro preprocessing facility -
You can use this preprocessing facility if your regular grammar defines
the above kind of macros in the same way -
Note:
The reentrant version of the preprocessing module expects that the
preprocessor ( constructed by the function 'SPP_init_reentrant' )
will be added to the scan stream as value of the context variable 'SPP_premac'.
Identifier for the ( macro ) token names
*/
#define SPP_TOK_IDE 0 // Identifier
#define SPP_TOK_MACDFN 1 // Macro
#define SPP_TOK_MACSEP 2 // Delimiter
#define SPP_TOK_MACINC 3 // Include
#define SPP_TOK_MACCOND 4 // Condition
#define SPP_TOK_MACDEL 5 // Undefine
/*
Identifier for macro token keywords
*/
#define SPP_PAT_START 6 // #macro
#define SPP_PAT_END 7 // #end
#define SPP_PAT_IFDEF 8 // #ifdef
#define SPP_PAT_IFNDEF 9 // #ifndef
#define SPP_PAT_ELSE 10 // #else
#define SPP_PAT_INC 11 // #include
#define SPP_PAT_UNDEFINE 12 // #undefine
/*
Identifier for include path and character set
*/
#define SPP_INC_PATH 13
#define SPP_INC_CHARSET 14
/* -------------------- Macro Expansion ----------------------------------- */
void SPP_init(MAP(long,symbol) pPreParMap)
/* initializes STYX-konform macro preprocessing
'pPreParMap': re-definitions for macro token names,
initial macro token keywords,
include path and characterset
*/
;
SPP_T SPP_init_reentrant(MAP(long,symbol) pPreParMap)
/* reentrant version of SPP_init */
;
void SPP_addCtxMacro(symbol pMacNam)
/* adds ( lower case symbol ) 'pMacNam' as pre-defined macro */
;
void SPP_addCtxMacro_reentrant(SPP_T pPP, symbol pMacNam)
/* reentrant version of SPP_addCtxMacro */
;
void SPP_quit(void); /* terminates STYX-konform macro preprocessing */
void SPP_quit_reentrant(SPP_T pPP); /* reentrant version of SPP_quit */
int SPP_premac
(
Scn_Stream pStream, c_string cTokNam, c_string cTokVal, symbol* cMacVal
)
/* preprocesses current token of non-binary scan stream 'pStream'
'cTokNam': name of separated token
'cTokVal': value of separated token
'cMacVal': preprocessing result ( see [scn_base] )
( cTokNam, cTokVal: single byte or utf-8 characterset )
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/integer.h 0000644 0001750 0001750 00000010017 12112434362 012016 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [integer.h] Type: Integer */
/* */
/* Copyright (c) 1994 by Lars D\olle, Heike Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef integer_INCL
#define integer_INCL
#include "standard.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ---------------------------- The Type --------------------------------- */
/*
[integer] implements the algebraic operations for long integers with a
maximum number of MAX_LONG digits.
An integer number is represented by its sign, length and digits:
N.value = N.Sgn * Sum { N.Dig[i] * (IntBase^i) | i in [0 .. N.Len - 1] }
*/
AbstractType(Integer) // Abstract integer type
;
/* ---------------------------- Basics ----------------------------------- */
/*
In the following functions the integer operands won't be consumed and
the resulting integers have to be released.
*/
Integer Int_cons(int Sgn, int Len, c_byte Dig[])
/* constructs an integer from sign 'Sgn', length 'Len' and digits 'Dig' */
;
void Int_des(Integer x, int *Sgn, int *Len, c_byte **Dig)
/* destructs an integer into sign 'Sgn', length 'Len' and digits 'Dig' */
;
Integer Int_copy(Integer a); /* copies integer 'a' */
void Int_free(Integer a); /* frees integer 'a' */
void Int_show(Integer a); /* prints integer 'a' to stdout; for debugging */
/* --------------------------- Conversion --------------------------------- */
c_string Int_itoa(Integer a, int Base)
/* converts integer 'a' into a string; allocs memory */
;
c_bool Int_s_ok(c_string s, int Base)
/* whether string 's' represents an integer; not consuming 's' */
;
Integer Int_atoi(c_string sn, int Base)
/* converts string 'sn' into a number; not consuming 'sn' */
;
Integer Int_Cto(long a); /* converts long 'a' into an integer */
c_bool Int_okC(Integer n)
/* whether integer 'n' can be converted into a long */
;
long Int_toC(Integer n); /* converts integer 'n' into a long */
/* --------------------------- Comparison --------------------------------- */
c_bool Int_is0(Integer x); /* x == 0 ? */
int Int_cmp(Integer a, Integer b); /* a < b ? -1 : a == b ? 0 : +1 */
c_bool Int_eq(Integer a, Integer b); /* a == b ? */
c_bool Int_ne(Integer a, Integer b); /* a != b ? */
c_bool Int_lt(Integer a, Integer b); /* a < b ? */
c_bool Int_le(Integer a, Integer b); /* a <= b ? */
c_bool Int_gt(Integer a, Integer b); /* a > b ? */
c_bool Int_ge(Integer a, Integer b); /* a >= b ? */
/* ---------------------------- Arithmetic -------------------------------- */
int Int_sgn(Integer a); /* signum of integer 'a' */
Integer Int_abs(Integer a); /* absolute value |a| */
Integer Int_neg(Integer a); /* negation -a */
Integer Int_add(Integer a, Integer b); /* addition a + b */
Integer Int_sub(Integer a, Integer b); /* substraction a - b */
Integer Int_mlt(Integer a, Integer b); /* multiplication a * b */
Integer Int_quo(Integer a, Integer b); /* division a / b */
Integer Int_rem(Integer a, Integer b); /* remainder a % b */
void Int_quo_rem(Integer a, Integer b, Integer *quo, Integer *rem)
/* *quo = a/b; *rem = a%b */
;
Integer Int_gcd(Integer a, Integer b)
/* greatest common divisor of integer 'a' and 'b' */
;
Integer Int_exp(Integer b, long n); /* exponent b ^ n */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/ctx_app.h 0000644 0001750 0001750 00000003121 12112434362 012015 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [ctx_app.h] Current Program Context */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef ctx_app_INCL
#define ctx_app_INCL
#include "ctx_dfn.h"
#ifdef __cplusplus
extern "C" {
#endif
/* -------------------- current context: Set & Get ------------------------ */
CTX_T CTX_ctx_val(void); /* the current context */
void CTX_ctx_set(CTX_T ctx); /* make 'ctx' the current context */
/* --------------------- current context: Eval ---------------------------- */
/* The following functions define the program interface to their context variables.
*/
Abs_T CTX_eval(c_string Name, c_bool Index)
#define CTX_EVAL(typ,name) ABS_CAST(typ,CTX_eval(name,C_False))
#define CTX_INDEX(name) ((long)(CTX_eval(name,C_True)))
/* 'Index' --> finds index of 'Name' in context; (-1) if missing
otherwise --> finds value of 'Name' in context; the program aborts if missing
*/
;
int CTX_argcnt(void); /* number of variable arguments */
Abs_T CTX_argval(int idx)
#define CTX_ARGVAL(typ,idx) ABS_CAST(typ,CTX_argval(idx))
/* variable argument, indexed by 'idx' */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/NEWS 0000664 0001750 0001750 00000015740 12114656452 010160 0000000 0000000
Mar 3 2013 - release 2.0.1
+ introduction of dynamic tokens to handle context sensitive constructs like C's typedef
+ styx grammar extension in order to solve reduce reduce conflicts explicitely
+ introduction of numbered list productions nil#*, cons#*
+ grammar example for Lua (>= 5.1)
+ justification of pattern token matching
+ documentation complement
Mar 26 2011 - release 1.8.0
+ EBNF rules for lists and options
+ grammar examples for JSON and PHP 5.2
+ corrections/bugfixes regarding gcc 4.x, vs studio 2008
+ documentation complement
Nov 3 2009 - release 1.7.6
+ C# library with Styx runtime scanner
+ corrections/bugfixes regarding gcc 4.x
+ documentation complement
Jan 26 2007 - release 1.7.5
+ finalize C++ library
+ corrections/bugfixes regarding gcc 4.x
+ bugfix parse table export
+ documentation complement
============ release notes 1.2 - 1.7 ==============================================
Jan 10 2001 - initial release (1.2)
Mar 4 2001 - release 1.3
+ fixes panic mode error recovery
+ fixes token buffer restriction. The token length is now of type long.
+ hopefully fixes some configure problems on freeBSD (concerning libdl)
+ adds parsing support for binary files
May 5 2001 - release 1.4
+ The embedded preprocessing facility is now reentrant.
+ The unicode support has been extended.
Now the specification of unicode-keywords should be possible, too.
Mar 11 2002 - release 1.5
BUG FIXES
---------
+ fixes a bug in the production of the abstract interface.
Now the destructor functions for the start productions skip ignore-productions.
+ fixes a bug regarding the early reduction facility which sometimes causes an
infinite loop.
+ fixes a bug in the preprocessing facility.
( an uninitilized variable sometimes causes a segmentation fault )
+ fixes a bug in the function putBString of the module binimg.c.
+ The print/reporting functions in the scan, parse, term and pretty print modules
has been revised with respect to a more consistent unicode support.
+ fixes the incomplete generated file Makefile.am in release 1.3 and 1.4
+ Now the COPYING file should contain the correct GPL license.
ENHANCEMENTS
------------
+ The modules binimg.c and ptm_pp.c (persistence, pretty printing) are now reentrant.
+ The utility programs lim_test, pim_test and stypp has been revised. Now they all
support preprocessing and unicode as well as dynamic loadable user-defined handlers.
( Note: You have to link your handlers with the runtime library libxstyx.so )
+ The term generation module [ptm_gen] has been extended to cope with external scanners
and parsers.
+ The scanner & parser generation has been revised. In addition to the released runtime
library libdstyx.so the new library libxstyx.so also contains the generation functionality.
Beside an improved modularisation it is now possible to include this functionality in
other programs. ( Look at styx as an example. )
Nov 30 2002 - release 1.5.1
+ Automake conversion such that VPATH builds and dist* targets work.
+ Avoid duplication of libdstyx in libxstyx.
+ fixes a bug in the function printSymbols of the module symbols.c.
+ fixes a bug in tutorial04. 'prdps' evaluates a project definition [project.nmk] based on the
STYX grammar [cprj.sty].
It keeps track to the specified translation rules, targets, sources
and their dependencies.
Its main task is to produce a control file [project.nmk] for the
nanomake-facility 'prnmk'.
cod
Arguments
project : string -- project definition file [project.prj]
vargs : string -- project definition parameter
doc
cod
Options
diagnose : string = "" -- path of diagnose information file
changes : flag = true -- show files changed
lexsort : flag = false -- order rules by name ( default: by position )
strict : flag = false -- errors on inference failures ( else warnings )
multisrc : flag = false -- allow identical sources in multiple targets
warnings : flag = true -- print warnings
makeNANO : flag = true -- produce the control file [project.nmk]
makeLIST : flag = true -- produce a project list [project.lst]
replace : string = "" -- path output substitution: The option 'makeLIST' isn't implemented yet.
The option 'replace' can be used to keep the pathes in the control file
variable. If the old-pattern starts with the character '^' the following
sequence is interpreted as start sequence condition.
The path separators will be evaluated in the given order.
( option 'pathsep' )
cod
Environment
PRDPS : path -- pathes for the project definition files
doc
cod
styx-2.0.1/util/reformat.cmd 0000666 0001750 0001750 00000000464 07507042030 012730 0000000 0000000 # [reformat.cmd] command description for reformat.c
Program reformat -- reformats a source file
doc
'reformat' reformats a source file in order to get better listings.
cod
Arguments
FileName : path -- source file path
Options
PageLength : int = 65 -- line number per page
Environment
styx-2.0.1/util/genmak.cmd 0000666 0001750 0001750 00000001641 07507042030 012351 0000000 0000000 # [genmak.cmd] command description for [genmak.c]
Program genmak -- input creation for 'automake' and MS Visual Studio project files (VC++ 6)
doc
'genmak' processes the make files, generated by 'prdps'.
For Unix the result is a control file for the make facility 'automake'.
For Windows source, header and export definition files (VC++ 6) will be generated.
cod
Arguments
project : string -- generated project file (.mak)
Options
rootpath : string="" -- project root directories
xoutput : string="" -- Unix output file ( path without suffix )
woutput : string="" -- Windows output directory
targets : string="" -- targets to install/distribute
exclude : string="" -- exclude sources which matches pattern list
dynamic : flag=true -- create dynamic libraries
version : string="" -- version string ( for all dynamic libraries )
Environment
styx-2.0.1/util/prdps.c 0000666 0001750 0001750 00000345435 10536001556 011736 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [prdps.c] Dependence Analysis */
/* */
/* Copyright (c) 1996 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "list.h"
#include "otab.h"
#include "hmap.h"
#include "hset.h"
#include "symbols.h"
#include "glo_tab.h"
#include "pathes.h"
#include "dicts.h"
#include "sink.h"
#include "binimg.h"
#include "com_get.h"
#include "scn_base.h"
#include "scn_pre.h"
#include "ptm_gen.h"
#include "ptm.h"
#include "prjfun.h"
#include "cdps_lim.h"
#include "prdp_cim.h"
#include "cprj_int.h"
#include "cprj_lim.h"
#include "cprj_pim.h"
#include "reg_exp.h"
/* -------------------- Types, Constants & Globals ----------------------- */
#define CTX_PROJECT CTX_EVAL(string,"project")
#define CTX_DIAGNOSE CTX_EVAL(string,"diagnose")
#define CTX_LEXSORT CTX_EVAL(bool,"lexsort")
#define CTX_STRICT CTX_EVAL(bool,"strict")
#define CTX_MULTISRC CTX_EVAL(bool,"multisrc")
#define CTX_WARNINGS CTX_EVAL(bool,"warnings")
#define CTX_CHANGES CTX_EVAL(bool,"changes")
#define CTX_MKNANO CTX_EVAL(bool,"makeNANO")
#define CTX_MKLIST CTX_EVAL(bool,"makeLIST")
#define CTX_REPLACE CTX_EVAL(string,"replace")
#define CTX_PATHSEP CTX_EVAL(string,"pathsep")
#define CTX_PREMAC CTX_EVAL(string,"premac")
#define lex(a,b) ((a) ? (a) : (b))
/* Assumption:
The Macro and Source File Names are unique within the current
project definitions.
That means: Basename + Suffix can be treated as a Key.
Root Source Files can't be in Object Files.
Generierungsabh„ngigkeiten zwischen Regeln mssen explizit durch eine
entsprechende lexikalische Ordnung der Regelnamen sichergestellt sein.
*/
/* Function Type: DpsLib Init & Quit */
/*
init: RC=0 <==> OK
quit: RC=Memory Counter
*/
typedef long (*PFN_DpsLib)(void);
/* Function Type: Direct Dependency Evaluation */
/*
Elements of pDepFiles must be released
*/
typedef void (*PFN_Dps)
(
string szSrcPath,
StdCPtr pDepFiles,
PFN_AddDep pAddDepFun,
bool* pbRoot
);
/* Function Type: External Rule Evaluation */
typedef void (*PFN_Ext)
(
ROW(string) pDstPathes,
SET(string) pSrcPathes,
StdCPtr pDstSrcGroups,
PFN_AddGrp pAddGrpFun,
PFN_AddDst pAddDstFun,
PFN_AddSrc pAddSrcFun
);
/* Function Type: External File Comparison */
typedef int (*PFN_Cmp)(string szLftPath, string szRgtPath);
ConcreteType(PRJ_Type)
{
SET(symbol) pTypSfx; /* Suffixes of Source / Target Type */
SET(symbol) pIncSfx; /* Source Dependant Suffixes of Source Type */
symbol pObjSfx; /* Intermediate Target Suffix of Source Type or NULL */
symbol pFstSfx; /* First Source / Target Suffix */
};
ConcreteType(PRJ_Environ)
{
symbol pPrjDir; /* Project Directory ( NMK ) */
symbol pDstDir; /* Target Directory ( EXE/RES/LIB/DLL ) */
symbol pObjDir; /* Intermediate Directory ( OBJ ) */
symbol pDpsLib; /* Typ Repository / DPS Library */
MAP(symbol,PT_Term) pOExtDir; /* Opt. External Include/Library Directories */
SET(symbol) pExtDir; /* External Include/Library Directories */
MAP(symbol,symbol) pOExtLib; /* Opt. Ext. Libraries: File Name |--> Path */
MAP(symbol,symbol) pExtLib; /* (External) Libraries: File Name |--> Path */
MAP(symbol,ROW(symbol)) pTypCmd;
/* Source/Target Type |--> Command */
MAP(symbol,MAP(symbol,symbol)) pCmdPar;
/* Source/Target Type |--> Command Parameter */
};
/*
Optional external Libraries and Directories
belonging to the same Group have the same Path Term.
*/
ConcreteType(PRJ_Project)
{
MAP(symbol,PRJ_Type) pTypDfn; /* Source/Target Types */
PRJ_Environ pStdEnv; /* Standard Project Environment */
};
ConcreteType(PRJ_Rule)
{
symbol pName; /* Rule Name */
cprjRuleAttr pAttr; /* Rule Attribute */
symbol pSrcTyp; /* Source Type */
cprjSrcDfn pSrcDfn; /* Source Definition */
cprjDstDfn pDstDfn; /* Target Definition */
SET(symbol) pSrcDir; /* Source Directories */
MAP(symbol,symbol) pSrcPat; /* Source Directory Pattern */
MAP(symbol,SET(symbol)) pDepDfn; /* Rule Dependant |--> Target Suffixes */
ROW(symbol) pDepRow; /* ordered Rule Dependants */
SET(symbol) pNeeds; /* Rule-Closure */
SET(symbol) pTargets; /* Targets */
ROW(symbol) pDstRow; /* sorted Targets */
PRJ_Environ pRuleEnv; /* Rule Environment */
};
ConcreteType(PRJ_Source)
{
symbol pPath; /* Path */
symbol pFile; /* Filename */
symbol pType; /* Type */
long lTime; /* Last-modified time */
SET(symbol) pDepDfn; /* direct Source Dependants of this Type, */
/* Target Dependants (res,lib,...) */
SET(symbol) pNeeds; /* Source-Dependant-Closure */
bool bRoot; /* Root Source or Modul Source */
symbol pPrefix; /* Modul-Prefix or NULL ( -> Dep.Analyse ) */
};
ConcreteType(PRJ_Target)
{
symbol pPath; /* Path */
symbol pFile; /* Filename */
symbol pType; /* Type */
SET(symbol) pSources; /* Sources / Source-Closure */
SET(symbol) pNeeds; /* direct dependant Targets */
MAP(symbol,symbol) pExtLib; /* External Libraries: File Name |--> Path */
PRJ_Rule pRule; /* Target Rule ( --> Environment ) */
symbol pNext; /* Filename of next Target or NULL */
/* Translation Unit: Target List */
symbol pRoot; /* Filename of Master Target or NULL */
/* pSources,pNeeds only defined in */
/* Single/Master Targets */
ROW(symbol) pSrcRow; /* sorted Sources */
};
/* Preprocessing */
static SPP_T pPP = (SPP_T)NULL;
static MAP(long,symbol) pPreParMap = (MAP(_,_))NULL;
/* Diagnose */
static FILE* pFP_Diag = (FILE*)NULL;
/* Source Type |--> Dependency Evaluation Function */
static MAP(symbol,PFN_Dps) pDpsLib;
/* Sum of DPS Repository Memory Count */
static long lDpsLibMemCnt = 0;
/* Last Project File Modification Time */
static long lMaxPrjModTime = 0;
/* project definition file |--> project definition term */
static MAP(symbol,PT_Term) pPrjMap;
/* project definition */
static PRJ_Project pProject;
/* replace map */
static MAP(symbol,symbol) pReplaceMap;
/* macro name |--> expanded value */
static MAP(symbol,symbol) pMacMap;
/* source name |--> source definition (c|o h,rc,...) */
static MAP(symbol,PRJ_Source) pSrcMap, pPrevSrcMap;
/* target name |--> target definition (lib,res,dll,...) */
static MAP(symbol,PRJ_Target) pDstMap;
/* rule name |--> rule definition */
static MAP(symbol,PRJ_Rule) pRuleMap;
static MAP(symbol,long) pRuleIdxMap;
static ROW(symbol) pRuleRow; // Rules, sortiert
static void (*pfnDepError)(PT_Term t, string f, ...);
/* -------------------------- Auxiliary ----------------------------------- */
static void PRJ_dummyDepError(PT_Term t, string f, ...)
{
}
static bool PRJ_IsMetaChar(char cC)
{
return cC == '%' || cC == '$' || cC == '(' || cC == ')';
}
static bool PRJ_IsPatternChar(char cC)
{
return cC == '?' || cC == '*' || cC == '&';
}
static string PRJ_convPathPattern(string szPattern)
{ long lLen = strlen(szPattern), lI;
string szResult = (string)NULL;
for( lI=0; lI < lLen; ++lI )
{
if( szResult == (string)NULL )
{
if( szPattern[lI] == '&' )
{
szResult = StrCopy(szPattern); szResult[lI] = '?';
}
}
else
if( szResult[lI] == '&' ) szResult[lI] = '?';
}
return szResult;
}
static bool PRJ_getPathPattern
(
string szPath, string* pszPath, string* pszPattern
)
{ long lLen = strlen(szPath), lI;
for( lI=lLen-1; lI >= 0; --lI )
{
if( PRJ_IsPatternChar(szPath[lI]) )
{ string szTmp;
*pszPath = FilePrefix(szPath);
szTmp = szPath+strlen(*pszPath);
*pszPattern = StrCopy(szTmp+AbsolutePathSep(szTmp));
return True;
}
}
return False;
}
static string PRJ_getDstBaseByMask(string szSource, string szPattern)
/* target basename by source and directory pattern */
{ string szBase = BaseFile(szSource), szDstBase = (string)NULL;
long lLen = strlen(szPattern), lI;
if( strlen(szBase) == lLen )
{
szDstBase = StrCopy(szPattern);
for( lI=0; lI < lLen; ++lI )
if( szPattern[lI] == '&' ) szDstBase[lI] = szBase[lI];
}
FreeMem(szBase);
return szDstBase;
}
static bool PRJ_IsNumber(string s)
{ long lLen = strlen(s), lI;
for( lI=0; lI < lLen; ++lI )
if( ! isdigit(s[lI]) ) return False;
return True;
}
static void PRJ_getMacro(string szNam, string* pszMac)
{ symbol pNam = stringToSymbol(szNam), pVal;
*pszMac = (string)NULL;
if( MAP_defined(pMacMap,pNam) )
{
pVal = MAP_apply(symbol,pMacMap,pNam);
if( pVal != (symbol)NULL )
*pszMac = symbolToString(pVal);
}
}
static int PRJ_expandMacro(string szS, string* pszMac, bool bEnv)
{ string szTmp, szDft; int nI = 0, nP;
*pszMac = (string)NULL;
szTmp = StrCopy(szS);
if( szTmp != (string)NULL )
{
while( szS[nI] != '\0' && ! PRJ_IsMetaChar(szS[nI]) ) ++nI;
szTmp[nI] = '\0';
if( bEnv )
{
szDft = strstr(szTmp,":");
if( szDft != (string)NULL )
{
*szDft = '\0';
szDft += 1;
*pszMac = getenv(szTmp);
if( *pszMac == (string)NULL )
{
if( *szDft == '&' )
{
PRJ_getMacro(szDft+1,pszMac);
}
else
{
*pszMac = symbolToString(stringToSymbol(szDft));
}
}
}
else
{
*pszMac = getenv(szTmp);
}
}
else
if( PRJ_IsNumber(szTmp) && ( nP = atoi(szTmp) ) < CTX_argcnt() )
{
*pszMac = CTX_ARGVAL(string,nP);
}
else
{
PRJ_getMacro(szTmp,pszMac);
}
FreeMem(szTmp);
}
return nI;
}
static string PRJ_expandName(string szNam)
{ string szRes = (string)NULL, szS, szMac, szTmp;
if( szNam != (string)NULL )
{ Sink pSnk = Sink_open();
bool bOK = True;
szS = szNam;
while( *szS != '\0' )
{ char cC = *szS;
if( ! PRJ_IsMetaChar(cC) )
{
Sink_putc(pSnk,cC); szS += 1;
}
else
{
szS += 1;
if( cC == '%' )
{
szS += PRJ_expandMacro(szS,&szMac,True);
assert0((*szS=='%'),"");
szS += 1;
if( szMac != (string)NULL )
{
Sink_puts(pSnk,szMac);
}
else { bOK = False; break; }
}
else
if( cC == '$' )
{
if( *szS != '(' )
{
szS += PRJ_expandMacro(szS,&szMac,True);
if( szMac != (string)NULL )
{
Sink_puts(pSnk,szMac);
}
else { bOK = False; break; }
}
else
{
szS += 1;
szS += PRJ_expandMacro(szS,&szMac,False);
if( szMac != (string)NULL )
{
Sink_puts(pSnk,szMac);
}
else { bOK = False; break; }
assert2((*szS==')'),"end of macro %s, %s",szMac,szS);
szS += 1;
}
}
else //C_BUG;
{
Sink_putc(pSnk,cC);
}
}
}
szTmp = Sink_close(pSnk);
if( bOK && szTmp != (string)NULL )
{
szRes = szTmp;
}
else
if( szTmp != (string)NULL ) FreeMem(szTmp);
}
return szRes;
}
static symbol PRJ_ValueToSymbol(GLS_Tok pVal)
{ symbol pRes = (symbol)NULL;
string szTmp = GLS_Tok_string(pVal), szTmp2, szVal, szMac;
szVal = StrCopy(szTmp+1);
szTmp2 = szVal+strlen(szVal)-1;
while( *szTmp2 == '\r' || *szTmp2 == '\n' )
{
*szTmp2 = '\0'; --szTmp2;
}
//szVal[strlen(szVal)-2] = '\0';
szMac = ( *szTmp == '~' ) ? PRJ_expandName(szVal) : StrCopy(szVal);
if( szMac != (string)NULL )
{
pRes = stringToSymbol(szMac);
FreeMem(szMac);
}
else PT_error(pVal,"value specification: %s",szTmp);
FreeMem(szVal);
return pRes;
}
static symbol PRJ_NameToSymbol(GLS_Tok pVal)
{ symbol pRes = (symbol)NULL;
string szTmp = symbolToString(GLS_Tok_symbol(pVal)),
szMac = PRJ_expandName(szTmp);
if( szMac != (string)NULL )
{
pRes = stringToSymbol(szMac);
FreeMem(szMac);
}
else PT_error(pVal,"path specification: %s",szTmp);
return pRes;
}
static bool PRJ_IsRecursive(cprjSrcDfn pSrcDfn)
{ cprjSrcAttr pSrcAttr;
assert0(cprjSrcDfn_dfn(pSrcDfn,_,&pSrcAttr),"");
return cprjSrcAttr_rexp(pSrcAttr,_);
}
static GLS_Tok PRJ_getSrcPathes(cprjSrcDfn pSrcDfn)
{ GLS_Tok pSrcPathes;
assert0(cprjSrcDfn_dfn(pSrcDfn,&pSrcPathes,_),"");
return pSrcPathes;
}
static Reg_T PRJ_getRegExp(cprjSrcDfn pSrcDfn)
{ cprjSrcAttr pSrcAttr;
cprjRegExp pRegExp;
Reg_T pRScn = (Reg_T)NULL;
assert0(cprjSrcDfn_dfn(pSrcDfn,_,&pSrcAttr),"");
if( ! cprjSrcAttr_exp(pSrcAttr,&pRegExp) )
assert0( cprjSrcAttr_rexp(pSrcAttr,&pRegExp), "");
if( !cprjRegExp_nul(pRegExp) )
{ GLS_Tok pRTok;
assert0( cprjRegExp_exp(pRegExp,&pRTok), "");
assert0(pRScn = REG_CREATE(symbolToString(PRJ_ValueToSymbol(pRTok))),"");
}
return pRScn;
}
static bool PRJ_IsExecutable(cprjRuleAttr pRuleAttr)
{
return( cprjRuleAttr_exe(pRuleAttr) || cprjRuleAttr_ex2(pRuleAttr) );
}
static bool PRJ_NoSourceDerivedTargets(cprjRuleAttr pRuleAttr)
{
return( cprjRuleAttr_ex2(pRuleAttr) );
}
static bool PRJ_IsExternalTarget(cprjDstDfn pDstDfn)
{
return( cprjDstDfn_ext(pDstDfn) );
}
static bool PRJ_IsInternalTarget(cprjDstDfn pDstDfn, GLS_Tok* pType)
{
return( cprjDstDfn_int(pDstDfn,pType,_,_,_) );
}
static PRJ_Type PRJ_getTargetType(cprjDstDfn pDstDfn)
{ PRJ_Type pResult = (PRJ_Type)NULL;
GLS_Tok pDstTyp;
if( PRJ_IsInternalTarget(pDstDfn,&pDstTyp) &&
MAP_defined(pProject->pTypDfn,GLS_Tok_symbol(pDstTyp)) )
pResult = MAP_apply(PRJ_Type,pProject->pTypDfn,GLS_Tok_symbol(pDstTyp));
return pResult;
}
static PRJ_Type PRJ_getTargetTypeSym(cprjDstDfn pDstDfn)
{ symbol pResult = (symbol)NULL;
GLS_Tok pDstTyp;
if( PRJ_IsInternalTarget(pDstDfn,&pDstTyp) )
pResult = GLS_Tok_symbol(pDstTyp);
return pResult;
}
static symbol PRJ_getTargetPrefix(cprjDstDfn pDstDfn)
{ symbol pResult = (symbol)NULL;
cprjOptTPrefix pOptPrefix;
GLS_Tok pPrefix;
if( cprjDstDfn_int(pDstDfn,_,_,&pOptPrefix,_) &&
cprjOptTPrefix_pre(pOptPrefix,&pPrefix) )
pResult = GLS_Tok_symbol(pPrefix);
return pResult;
}
static symbol PRJ_getSourcePrefix(cprjDstDfn pDstDfn)
{ symbol pResult = (symbol)NULL;
cprjOptSPrefix pOptPrefix;
GLS_Tok pPrefix;
if( cprjDstDfn_int(pDstDfn,_,_,_,&pOptPrefix) &&
cprjOptSPrefix_pre(pOptPrefix,&pPrefix) )
pResult = GLS_Tok_symbol(pPrefix);
return pResult;
}
static bool PRJ_IsTargetByRoot(cprjDstDfn pDstDfn)
{ cprjDstName pDstName;
return( cprjDstDfn_int(pDstDfn,_,&pDstName,_,_) && cprjDstName_root(pDstName) );
}
static bool PRJ_IsTargetByDirectory(cprjDstDfn pDstDfn)
{ cprjDstName pDstName;
return( cprjDstDfn_int(pDstDfn,_,&pDstName,_,_) && cprjDstName_dir(pDstName) );
}
static bool PRJ_IsTargetBySource(cprjDstDfn pDstDfn)
{ cprjDstName pDstName;
return( cprjDstDfn_int(pDstDfn,_,&pDstName,_,_) && cprjDstName_src(pDstName) );
}
static bool PRJ_IsTargetByName(cprjDstDfn pDstDfn, GLS_Tok* pName)
{ cprjDstName pDstName;
return
(
cprjDstDfn_int(pDstDfn,_,&pDstName,_,_) && cprjDstName_nam(pDstName,pName)
);
}
static bool PRJ_IsInclude
(
symbol pIncSfx, symbol pSrcTyp,
SET(symbol) pIncSfxSet, symbol* pRefSrcTyp
)
/*
Evaluation Rule:
1) Member
2) Refernce
3) Dynamic (*)
else) False
*/
{
if( HS_MBR_ELM(pIncSfx,pIncSfxSet) )
{
if( pRefSrcTyp != (symbol*)NULL ) *pRefSrcTyp = pSrcTyp;
return True;
}
else
{ HS_Itr pItr;
symbol pSfx, pTyp;
string szSfx;
PRJ_Type pTypDfn;
HS_FORALL(pSfx,pItr,pIncSfxSet)
{
szSfx = symbolToString(pSfx);
if( *szSfx == '&' )
{
pTyp = stringToSymbol(szSfx+1);
pTypDfn = MAP_apply(PRJ_Type,pProject->pTypDfn,pTyp);
if( PRJ_IsInclude(pIncSfx,pTyp,pTypDfn->pIncSfx,pRefSrcTyp) )
{
HS_DROP_ITR(pItr); return True;
}
}
}
if( HS_MBR_ELM(stringToSymbol("*"),pIncSfxSet) )
{
if( pRefSrcTyp != (symbol*)NULL ) *pRefSrcTyp = pSrcTyp;
return True;
}
}
if( pRefSrcTyp != (symbol*)NULL ) *pRefSrcTyp = (symbol*)NULL;
return False;
}
static SET(string) PRJ_SymbolToStringSet
(
SET(string) pDstSet, SET(symbol) pSrcSet
)
{ SET(string) pResSet = ( pDstSet == (SET(string))NULL )
? HS_CREATE_ADTSET(string) : pDstSet;
HS_Itr pItr;
symbol pElm;
HS_FORALL(pElm,pItr,pSrcSet)
{
HS_SET_ELM(symbolToString(pElm),pResSet);
}
return pResSet;
}
static void PRJ_setPathSep(string szPathes, PIT pItr)
{ int nLen = strlen(CTX_PATHSEP), nI;
char szSep[2];
szSep[1] = '\0';
for( nI=0; nI < nLen; ++nI )
{
szSep[0] = CTX_PATHSEP[nI];
if( strstr(szPathes,szSep) != (string)NULL )
{
PIT_sep(pItr,szSep); return;
}
}
PIT_sep(pItr,";");
}
/* --------------------- DpsLib CallBack Functions ------------------------ */
static void PRJ_addGrp(StdCPtr pGBag, StdCPtr* ppTBag, StdCPtr* ppSBag)
{ MAP(ROW(symbol),SET(symbol)) pDstSrcGroups = (MAP(_,_))pGBag;
ROW(symbol) pTargets = OT_CREATE_ADT(symbol);
SET(symbol) pSources = HS_CREATE_ADTSET(symbol);
MAP_dfndom(pDstSrcGroups,pTargets,pSources);
*ppTBag = pTargets;
*ppSBag = pSources;
}
static void PRJ_addDst(StdCPtr pBag, string szDstFile, string szDstPath)
{ ROW(symbol) pTargets = (ROW(symbol))pBag;
OT_PUSH(stringToSymbol(szDstFile),pTargets);
OT_PUSH(stringToSymbol(szDstPath),pTargets);
}
static void PRJ_addSrc(StdCPtr pBag, string szSrcFile)
{ SET(symbol) pSources = (SET(symbol))pBag;
HS_SET_ELM(stringToSymbol(szSrcFile),pSources);
}
/* --------------------- Create & Release Ressources ---------------------- */
static PRJ_Type PRJ_newType(void)
{ PRJ_Type pType = (PRJ_Type)NewMem(SizeOf(PRJ_Type));
pType->pFstSfx = (symbol)NULL;
pType->pObjSfx = (symbol)NULL;
pType->pTypSfx = HS_CREATE_ADTSET(symbol);
pType->pIncSfx = HS_CREATE_ADTSET(symbol);
return pType;
}
static PRJ_Environ PRJ_newEnviron(void)
{ PRJ_Environ pEnviron = (PRJ_Environ)NewMem(SizeOf(PRJ_Environ));
pEnviron->pPrjDir = (symbol)NULL;
pEnviron->pDstDir = (symbol)NULL;
pEnviron->pObjDir = (symbol)NULL;
pEnviron->pDpsLib = (symbol)NULL;
pEnviron->pOExtDir = MAP_newPrimMap();
pEnviron->pExtDir = HS_CREATE_ADTSET(symbol);
pEnviron->pOExtLib = MAP_newPrimMap();
pEnviron->pExtLib = MAP_newPrimMap();
pEnviron->pTypCmd = MAP_newPrimMap();
pEnviron->pCmdPar = MAP_newPrimMap();
return pEnviron;
}
static void PRJ_unionEnviron(PRJ_Environ pTarget, PRJ_Environ pSource)
{ HS_Itr pSItr;
MAPIT pMItr;
symbol pFile, pDir, pType;
GLS_Tok pPathes;
ROW(symbol) pCmds;
MAP(symbol,symbol) pPars;
if( pTarget->pPrjDir == (symbol)NULL ) pTarget->pPrjDir = pSource->pPrjDir;
if( pTarget->pDstDir == (symbol)NULL ) pTarget->pDstDir = pSource->pDstDir;
if( pTarget->pObjDir == (symbol)NULL ) pTarget->pObjDir = pSource->pObjDir;
if( pTarget->pDpsLib == (symbol)NULL ) pTarget->pDpsLib = pSource->pDpsLib;
MAP_forItrAsg(pDir,pPathes,pMItr,pSource->pOExtDir)
if( ! MAP_defined(pTarget->pOExtDir,pDir) )
MAP_dfndom(pTarget->pOExtDir,pDir,pPathes);
HS_FORALL(pDir,pSItr,pSource->pExtDir) HS_SET_ELM(pDir,pTarget->pExtDir);
if( MAP_count(pTarget->pOExtLib) == 0 )
MAP_forItrAsg(pFile,pDir,pMItr,pSource->pOExtLib)
MAP_dfndom(pTarget->pOExtLib,pFile,pDir);
if( MAP_count(pTarget->pExtLib) == 0 )
MAP_forItrAsg(pFile,pDir,pMItr,pSource->pExtLib)
MAP_dfndom(pTarget->pExtLib,pFile,pDir);
MAP_forItrAsg(pType,pCmds,pMItr,pSource->pTypCmd)
{
if( ! MAP_defined(pTarget->pTypCmd,pType) )
{
MAP_dfndom(pTarget->pTypCmd,pType,OT_COPY(pCmds));
}
}
MAP_forItrAsg(pType,pPars,pMItr,pSource->pCmdPar)
{
if( ! MAP_defined(pTarget->pCmdPar,pType) )
{
MAP_dfndom(pTarget->pCmdPar,pType,MAP_prim_copy(pPars));
}
}
}
static PRJ_Project PRJ_newProject(void)
{ PRJ_Project pProject = (PRJ_Project)NewMem(SizeOf(PRJ_Project));
pProject->pTypDfn = MAP_newPrimMap();
pProject->pStdEnv = PRJ_newEnviron();
return pProject;
}
static PRJ_Rule PRJ_newRule(void)
{ PRJ_Rule pRule = (PRJ_Rule)NewMem(SizeOf(PRJ_Rule));
pRule->pName = (symbol)NULL;
pRule->pAttr = (cprjRuleAttr)NULL;
pRule->pSrcTyp = (symbol)NULL;
pRule->pSrcDfn = (cprjSrcDfn)NULL;
pRule->pDstDfn = (cprjDstDfn)NULL;
pRule->pSrcDir = HS_CREATE_ADTSET(symbol);
pRule->pSrcPat = MAP_newPrimMap();
pRule->pDepDfn = MAP_newPrimMap();
pRule->pDepRow = OT_CREATE_ADT(symbol);
pRule->pTargets = HS_CREATE_ADTSET(symbol);
pRule->pNeeds = HS_CREATE_ADTSET(symbol);
pRule->pRuleEnv = PRJ_newEnviron();
pRule->pDstRow = OT_CREATE_ADT(symbol);
return pRule;
}
static PRJ_Source PRJ_newSource(void)
{ PRJ_Source pSource = (PRJ_Source)NewMem(SizeOf(PRJ_Source));
pSource->pDepDfn = HS_CREATE_ADTSET(symbol);
pSource->pNeeds = HS_CREATE_ADTSET(symbol);
pSource->pPath = (symbol)NULL;
pSource->pFile = (symbol)NULL;
pSource->pType = (symbol)NULL;
pSource->lTime = 0;
pSource->bRoot = False;
pSource->pPrefix = (symbol)NULL;
return pSource;
}
static PRJ_Target PRJ_newTarget(PRJ_Rule pRule, SET(symbol) pSources)
{ PRJ_Target pTarget = (PRJ_Target)NewMem(SizeOf(PRJ_Target));
pTarget->pSources = pSources;
pTarget->pRule = pRule;
pTarget->pNeeds = pSources!=(SET(symbol))NULL
?HS_CREATE_ADTSET(symbol):(SET(symbol))NULL;
pTarget->pExtLib = pSources!=(SET(symbol))NULL
?MAP_newPrimMap():(MAP(symbol,symbol))NULL;
pTarget->pSrcRow = pSources!=(SET(symbol))NULL
?OT_CREATE_ADT(symbol):(ROW(symbol))NULL;
pTarget->pPath = (symbol)NULL;
pTarget->pFile = (symbol)NULL;
pTarget->pType = (symbol)NULL;
pTarget->pNext = (symbol)NULL;
pTarget->pRoot = (symbol)NULL;
return pTarget;
}
static void PRJ_freeType(PRJ_Type pType)
{
HS_DROP_SET(pType->pIncSfx);
HS_DROP_SET(pType->pTypSfx);
FreeMem(pType);
}
static void PRJ_freeEnviron(PRJ_Environ pEnviron)
{ MAPIT pItr; HMP_Dom pDom; HMP_Rng pRng;
MAP_freeMap(pEnviron->pOExtDir);
HS_DROP_SET(pEnviron->pExtDir);
MAP_freeMap(pEnviron->pOExtLib);
MAP_freeMap(pEnviron->pExtLib);
MAP_forItrAsg(pDom,pRng,pItr,pEnviron->pTypCmd) OT_DEL_T(pRng);
MAP_freeMap(pEnviron->pTypCmd);
MAP_forItrAsg(pDom,pRng,pItr,pEnviron->pCmdPar) MAP_freeMap(pRng);
MAP_freeMap(pEnviron->pCmdPar);
FreeMem(pEnviron);
}
static void PRJ_freeProject(PRJ_Project pProject)
{ MAPIT pItr; HMP_Dom pDom; HMP_Rng pRng;
MAP_forItrAsg(pDom,pRng,pItr,pProject->pTypDfn) PRJ_freeType(pRng);
MAP_freeMap(pProject->pTypDfn);
PRJ_freeEnviron(pProject->pStdEnv);
FreeMem(pProject);
}
static void PRJ_freeRule(PRJ_Rule pRule)
{ MAPIT pItr; HMP_Dom pDom; HMP_Rng pRng;
MAP_forItrAsg(pDom,pRng,pItr,pRule->pDepDfn) HS_DROP_SET(pRng);
MAP_freeMap(pRule->pDepDfn);
OT_DEL_T(pRule->pDepRow);
HS_DROP_SET(pRule->pSrcDir);
MAP_freeMap(pRule->pSrcPat);
HS_DROP_SET(pRule->pTargets);
HS_DROP_SET(pRule->pNeeds);
PRJ_freeEnviron(pRule->pRuleEnv);
OT_DEL_T(pRule->pDstRow);
FreeMem(pRule);
}
static void PRJ_freeSource(PRJ_Source pSource)
{
HS_DROP_SET(pSource->pDepDfn);
HS_DROP_SET(pSource->pNeeds);
FreeMem(pSource);
}
static void PRJ_freeTarget(PRJ_Target pTarget)
{
if( pTarget->pSources != (SET(symbol))NULL ) HS_DROP_SET(pTarget->pSources);
if( pTarget->pNeeds != (SET(symbol))NULL ) HS_DROP_SET(pTarget->pNeeds);
if( pTarget->pExtLib != (MAP(symbol,symbol))NULL )
MAP_freeMap(pTarget->pExtLib);
if( pTarget->pSrcRow != (ROW(symbol))NULL ) OT_DEL_T(pTarget->pSrcRow);
FreeMem(pTarget);
}
static void PRJ_newRessources(void)
{
pProject = PRJ_newProject();
pDpsLib = MAP_newPrimMap();
pPrjMap = MAP_newPrimMap();
pMacMap = MAP_newPrimMap();
pSrcMap = MAP_newPrimMap();
pPrevSrcMap = MAP_newPrimMap();
pDstMap = MAP_newPrimMap();
pRuleMap = MAP_newPrimMap();
pReplaceMap = MAP_newPrimMap();
pRuleIdxMap = MAP_newPrimMap();
pRuleRow = OT_CREATE_ADT(symbol);
}
static void PRJ_freeRessources(void)
{ MAPIT pItr; HMP_Dom pDom; HMP_Rng pRng;
OT_DEL_T(pRuleRow);
MAP_forItrAsg(pDom,pRng,pItr,pSrcMap)
{
if( ! MAP_defined(pPrevSrcMap,pDom) ||
((PRJ_Source)pRng) != MAP_apply(PRJ_Source,pPrevSrcMap,pDom) )
PRJ_freeSource(pRng);
}
MAP_freeMap(pSrcMap);
MAP_forItrAsg(pDom,pRng,pItr,pPrevSrcMap) PRJ_freeSource(pRng);
MAP_freeMap(pPrevSrcMap);
MAP_forItrAsg(pDom,pRng,pItr,pDstMap) PRJ_freeTarget(pRng);
MAP_freeMap(pDstMap);
MAP_freeMap(pMacMap);
MAP_forItrAsg(pDom,pRng,pItr,pRuleMap) PRJ_freeRule(pRng);
MAP_freeMap(pRuleMap);
MAP_freeMap(pRuleIdxMap);
MAP_forItrAsg(pDom,pRng,pItr,pPrjMap) PT_delT(pRng);
MAP_freeMap(pPrjMap);
MAP_freeMap(pDpsLib);
MAP_freeMap(pReplaceMap);
PRJ_freeProject(pProject);
}
/*forward*/
/**/ static void C_parse
(
string szSrcPath, StdCPtr pDepFiles,
PFN_AddDep pAddDepFun, bool* pbRoot
);
static void PRJ_initDpsLib(void)
{
MAP_dfndom(pDpsLib,stringToSymbol("C"),C_parse);
MAP_dfndom(pDpsLib,stringToSymbol("SRC"),C_parse);
MAP_dfndom(pDpsLib,stringToSymbol("MOC_S"),C_parse);
}
static void PRJ_init(int argc, string argv[])
{ PIT pItr; string s, r, t1, t2;
CTX_init_prdps(argc,argv);
initSymbols();
MAP_init();
Glo_init();
cprj_initSymbols();
PRJ_newRessources();
PRJ_initDpsLib();
if( CTX_STRICT ) pfnDepError = PT_error;
else
if( CTX_WARNINGS ) pfnDepError = PT_warn;
else pfnDepError = PRJ_dummyDepError;
s = CTX_REPLACE;
if( s != (string)NULL && strlen(s) > 0 )
{
pItr = PIT_make(s); PIT_sep(pItr,";");
while( ( t1 = PIT_read(pItr) ) != NULL )
{
r = StrCopy(t1);
t2 = strstr(r,"=");
if( t2 != (string)NULL )
{
*t2 = '\0';
if( *r == '^' ) // start sequence condition
{
MAP_ovrdom(pReplaceMap,stringToSymbol(""),stringToSymbol(t2+1));
MAP_ovrdom(pReplaceMap,(symbol)NULL,stringToSymbol(r+1));
}
else
MAP_ovrdom(pReplaceMap,stringToSymbol(r),stringToSymbol(t2+1));
}
FreeMem(r);
}
PIT_drop(pItr);
}
/* init preprocessing */
pPreParMap = MAP_newPrimMap();
MAP_dfndom(pPreParMap,SPP_TOK_IDE,stringToSymbol("Name"));
MAP_dfndom(pPreParMap,SPP_TOK_MACDFN,stringToSymbol("MMacDfn"));
pPP = SPP_init_reentrant(pPreParMap);
/* add pre-defined macros */
if( strlen(CTX_PREMAC) > 0 )
{
pItr = PIT_make(CTX_PREMAC); PIT_sep(pItr,",");
while( ( s = PIT_read(pItr) ) != NULL )
{
SPP_addCtxMacro_reentrant(pPP,lstringToSymbol(s));
}
PIT_drop(pItr);
}
}
static void PRJ_quit(void)
{
if( pPreParMap != (MAP(_,_))NULL ) MAP_freeMap(pPreParMap);
if( pPP != (SPP_T)NULL ) SPP_quit_reentrant(pPP);
PRJ_freeRessources();
cprj_quitSymbols();
Glo_quit();
MAP_quit();
freeSymbols();
CTX_quit();
}
/* ---------------------------- get & put --------------------------------- */
static void PRJ_get(void)
/* read source file image */
{ string szMstPrj = BaseFile(CTX_PROJECT),
szFile = MkPath
(
symbolToString(pProject->pStdEnv->pPrjDir),
szMstPrj,".dps",'d'
),
szPath;
if( IsPath(szFile) && lMaxPrjModTime < PathMTime(szFile) )
{ long lCnt, lCnt2, lI, lJ, lTime;
bool bRoot;
getBgn("",szFile,"");
getHeader("prdps",1,0);
getLong(&lCnt);
for( lI=0; lI < lCnt; ++lI )
{ PRJ_Source pSource = PRJ_newSource();
symbol pSymbol;
getSymbol(&pSymbol);
pSource->pPath = pSymbol;
getSymbol(&pSymbol);
pSource->pFile = pSymbol;
getSymbol(&pSymbol);
pSource->pType = pSymbol;
getLong(&lTime);
pSource->lTime = lTime;
getInt(&bRoot);
pSource->bRoot = bRoot;
getLong(&lCnt2);
if( lCnt2 > 0 )
{
getSymbol(&pSymbol);
pSource->pPrefix = pSymbol;
}
getLong(&lCnt2);
for( lJ=0; lJ < lCnt2; ++lJ )
{
getSymbol(&pSymbol);
HS_SET_ELM(pSymbol,pSource->pDepDfn);
}
szPath = MkPath
(
symbolToString(pSource->pPath),
symbolToString(pSource->pFile),"",'d'
);
if( IsPath(szPath) )
MAP_dfndom(pPrevSrcMap,pSource->pFile,pSource);
else
PRJ_freeSource(pSource);
FreeMem(szPath);
}
getEnd();
}
FreeMem(szMstPrj); FreeMem(szFile);
}
static void PRJ_put(void)
/* write source file image */
{ string szMstPrj = BaseFile(CTX_PROJECT),
szFile = MkPath
(
symbolToString(pProject->pStdEnv->pPrjDir),
szMstPrj,".dps",'d'
),
szHdr = Str_printf
(
"[%s.dps] binary file for 'prdps'\n",szMstPrj
);
MAPIT pMItr;
HS_Itr pSItr;
PRJ_Source pSource;
symbol pFile, pDepSym;
long lCnt = 0;
putBgn("",szFile,"");
putHeader(szHdr,"prdps",1,0);
putLong(MAP_count(pSrcMap));
MAP_forItrAsg(pFile,pSource,pMItr,pSrcMap)
{
putSymbol(pSource->pPath);
putSymbol(pSource->pFile);
putSymbol(pSource->pType);
putLong(pSource->lTime);
putInt(pSource->bRoot);
lCnt = pSource->pPrefix != (symbol)NULL;
putLong(lCnt);
if( lCnt > 0 ) putSymbol(pSource->pPrefix);
putLong(HS_CARD(pSource->pDepDfn));
HS_FORALL(pDepSym,pSItr,pSource->pDepDfn)
putSymbol(pDepSym);
}
putEnd();
FreeMem(szMstPrj); FreeMem(szFile); FreeMem(szHdr);
}
/* -------------------------- Analysis ------------------------------------ */
/* -------------------------- Dependencies -------------------------------- */
//TODO: report same error only once !!!
static void PRJ_printDepError(symbol pLft, symbol pRgt, PT_Term t)
{
if( t != (PT_Term)NULL )
{
if( pLft != pRgt )
(*pfnDepError)
(
t, "reflexive dependance between %s and %s",
symbolToString(pLft), symbolToString(pRgt)
);
}
else
{
if( pLft != pRgt && ( CTX_STRICT || CTX_WARNINGS ) )
fprintf
(
STDERR, "reflexive dependance between %s and %s\n",
symbolToString(pLft), symbolToString(pRgt)
);
if( CTX_STRICT )
PT_setErrorCnt(PT_errorCnt() + 1);
}
}
static int PRJ_cmpRules(OT_Obj pLft, OT_Obj pRgt)
{ PRJ_Rule pLftRule = MAP_apply(PRJ_Rule,pRuleMap,(symbol)pLft),
pRgtRule = MAP_apply(PRJ_Rule,pRuleMap,(symbol)pRgt);
if( CTX_LEXSORT ||
! PT_hasPos(pLftRule->pDstDfn) ||
! PT_hasPos(pRgtRule->pDstDfn) )
return
strcmp(symbolToString(pLftRule->pName),symbolToString(pRgtRule->pName));
else
return (int)(PT_row(pLftRule->pDstDfn) - PT_row(pRgtRule->pDstDfn));
}
static void PRJ_sortRules_aux(symbol pRuleSym, SET(symbol) pVisitSet)
{ PRJ_Rule pRule = MAP_apply(PRJ_Rule,pRuleMap,pRuleSym);
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
symbol pDepSym;
HS_Itr pItr;
HS_SET_ELM(pRuleSym,pVisitSet);
HS_FORALL(pDepSym,pItr,pRule->pNeeds)
{
if( MAP_defined(pRuleMap,pDepSym) )
{ PRJ_Rule pDepRule = MAP_apply(PRJ_Rule,pRuleMap,pDepSym);
if( pRule->pName != pDepRule->pName &&
HS_MBR_ELM(pRule->pName,pDepRule->pNeeds) &&
HS_MBR_ELM(pDepRule->pName,pRule->pNeeds) )
PRJ_printDepError(pRule->pName,pDepRule->pName,(PT_Term)NULL);
OT_S_INS(pTmp,pDepSym,PRJ_cmpRules);
}
}
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pDepSym = OT_GET(symbol,pTmp,lI);
if( ! HS_MBR_ELM(pDepSym,pVisitSet) )
PRJ_sortRules_aux(pDepSym,pVisitSet);
}
OT_PUSH(pRuleSym,pRuleRow);
OT_DEL_T(pTmp);
}
static void PRJ_sortRules(void)
/* sort build rules */
{ symbol pRuleSym;
SET(symbol) pVisitSet = HS_CREATE_ADTSET(symbol);
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
MAPIT pItr;
MAP_forItr(pRuleSym,pItr,pRuleMap)
OT_S_INS(pTmp,pRuleSym,PRJ_cmpRules);
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pRuleSym = OT_GET(symbol,pTmp,lI);
if( ! HS_MBR_ELM(pRuleSym,pVisitSet) )
PRJ_sortRules_aux(pRuleSym,pVisitSet);
}
lCnt = OT_CNT(pRuleRow);
for( lI=0; lI < lCnt; ++lI )
{
pRuleSym = OT_GET(symbol,pRuleRow,lI);
MAP_dfndom(pRuleIdxMap,pRuleSym,lI);
}
OT_DEL_T(pTmp);
HS_DROP_SET(pVisitSet);
}
static void PRJ_addRuleNeedsClosure(void)
/* build rule closure */
{ symbol pRuleSym, pRuleSym2;
PRJ_Rule pRule, pRule2;
MAPIT pItr;
HS_Itr pItr2;
long lCard;
bool bChanges = True;
while( bChanges == True )
{
bChanges = False;
MAP_forItrAsg(pRuleSym,pRule,pItr,pRuleMap)
{
lCard = HS_CARD(pRule->pNeeds);
if( lCard > 0 )
{ SET(symbol) pTmp = HS_COPY(pRule->pNeeds);
HS_FORALL(pRuleSym2,pItr2,pTmp)
{
if( pRuleSym != pRuleSym2 )
{
pRule2 = MAP_apply(PRJ_Rule,pRuleMap,pRuleSym2);
HS_UNION(pRule->pNeeds,pRule->pNeeds,pRule2->pNeeds);
if( HS_CARD(pRule->pNeeds) != lCard ) bChanges = True;
}
}
HS_DROP_SET(pTmp);
}
}
}
}
static int PRJ_cmpSources(OT_Obj pLft, OT_Obj pRgt)
{
return
strcmp(symbolToString((symbol)pLft),symbolToString((symbol)pRgt));
}
static void PRJ_sortTargetSources_aux
(
ROW(symbol) pSrcRow, symbol pSrcSym,
SET(symbol) pSrcSet, SET(symbol) pVisitSet
)
{ PRJ_Source pSource = MAP_apply(PRJ_Source,pSrcMap,pSrcSym);
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
symbol pDepSym;
HS_Itr pItr;
HS_SET_ELM(pSrcSym,pVisitSet);
HS_FORALL(pDepSym,pItr,pSource->pNeeds)
{
if( MAP_defined(pSrcMap,pDepSym) )
{ PRJ_Source pDepSource = MAP_apply(PRJ_Source,pSrcMap,pDepSym);
if( HS_MBR_ELM(pSource->pFile,pDepSource->pNeeds) &&
HS_MBR_ELM(pDepSource->pFile,pSource->pNeeds) )
{ bool bError = True;
if( pSource->pPrefix == pDepSource->pPrefix &&
pSource->pPrefix != (symbol)NULL )
{ string szPrefix = symbolToString(pSource->pPrefix);
if( strstr(symbolToString(pSource->pFile),szPrefix) &&
!strcmp(symbolToString(pSource->pFile)+strlen(szPrefix),
symbolToString(pDepSource->pFile)) )
bError = False;
else
if( strstr(symbolToString(pDepSource->pFile),szPrefix) &&
!strcmp(symbolToString(pDepSource->pFile)+strlen(szPrefix),
symbolToString(pSource->pFile)) )
bError = False;
}
if( bError )
PRJ_printDepError(pSource->pFile,pDepSource->pFile,(PT_Term)NULL);
}
OT_S_INS(pTmp,pDepSym,PRJ_cmpSources);
}
}
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pDepSym = OT_GET(symbol,pTmp,lI);
if( HS_MBR_ELM(pDepSym,pSrcSet) && ! HS_MBR_ELM(pDepSym,pVisitSet) )
PRJ_sortTargetSources_aux(pSrcRow,pDepSym,pSrcSet,pVisitSet);
}
OT_PUSH(pSrcSym,pSrcRow);
OT_DEL_T(pTmp);
}
static void PRJ_sortTargetSources(PRJ_Target pTarget, SET(symbol) pSorted)
/* sort not sorted target sources */
{ SET(symbol) pSrcSet = HS_CREATE_ADTSET(symbol),
pVisitSet = HS_CREATE_ADTSET(symbol);
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
symbol pSrcSym;
HS_Itr pItr;
HS_FORALL(pSrcSym,pItr,pTarget->pSources)
{
if( CTX_MULTISRC || ! HS_MBR_ELM(pSrcSym,pSorted) )
{
OT_S_INS(pTmp,pSrcSym,PRJ_cmpSources);
HS_SET_ELM(pSrcSym,pSrcSet);
HS_SET_ELM(pSrcSym,pSorted);
}
}
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pSrcSym = OT_GET(symbol,pTmp,lI);
if( ! HS_MBR_ELM(pSrcSym,pVisitSet) )
PRJ_sortTargetSources_aux(pTarget->pSrcRow,pSrcSym,pSrcSet,pVisitSet);
}
OT_DEL_T(pTmp);
HS_DROP_SET(pSrcSet);
HS_DROP_SET(pVisitSet);
}
static symbol PRJ_getSrcMod(PRJ_Source pSource, symbol pSrcModTyp, symbol pSrcModPrefix)
/* get source modul for include 'pSource' or null */
{ PRJ_Type pType = MAP_apply(PRJ_Type,pProject->pTypDfn,pSrcModTyp);
string szSuffix = FileSuffix(symbolToString(pSource->pFile)),
szExt = szSuffix + (*szSuffix=='.'),
szBase, szFile;
symbol pSrcMod = (symbol)NULL, pModSfx;
if( PRJ_IsInclude(
stringToSymbol(szExt),pSrcModTyp,pType->pIncSfx,(symbol*)NULL) )
{ HS_Itr pItr;
szBase = BaseFile(symbolToString(pSource->pFile));
HS_FORALL(pModSfx,pItr,pType->pTypSfx)
{
if( pSrcModPrefix != (symbol)NULL )
szFile = Str_printf("%s%s.%s",symbolToString(pSrcModPrefix),
szBase,symbolToString(pModSfx));
else
szFile = Str_printf("%s.%s",szBase,symbolToString(pModSfx));
pSrcMod = stringToSymbol(szFile);
if( MAP_defined(pSrcMap,pSrcMod) )
{
FreeMem(szFile);
HS_DROP_ITR(pItr); break;
}
else pSrcMod = (symbol)NULL;
FreeMem(szFile);
}
if( pSrcMod == (symbol)NULL && pType->pObjSfx != (symbol)NULL )
{
if( pSrcModPrefix != (symbol)NULL )
szFile = Str_printf("%s%s.%s",symbolToString(pSrcModPrefix),
szBase,symbolToString(pType->pObjSfx));
else
szFile = Str_printf("%s.%s",szBase,symbolToString(pType->pObjSfx));
pSrcMod = stringToSymbol(szFile);
if( ! MAP_defined(pSrcMap,pSrcMod) )
pSrcMod = (symbol)NULL;
FreeMem(szFile);
}
FreeMem(szBase);
}
FreeMem(szSuffix);
return pSrcMod;
}
static void PRJ_addSourceNeedsClosure(void)
/* build source closure */
{ symbol pSrcSym, pSrcSym2, pSrcSym3, pSuffix;
PRJ_Source pSource, pSource2, pSource3;
PRJ_Type pSrcTyp;
MAPIT pItr;
HS_Itr pItr2;
string szSuffix, szExt;
long lCard;
bool bChanges = True;
while( bChanges == True )
{
bChanges = False;
MAP_forItrAsg(pSrcSym,pSource,pItr,pSrcMap)
{
lCard = HS_CARD(pSource->pNeeds);
if( lCard > 0 )
{ SET(symbol) pTmp = HS_COPY(pSource->pNeeds);
pSrcTyp = MAP_apply(PRJ_Type,pProject->pTypDfn,pSource->pType);
szSuffix = FileSuffix(symbolToString(pSource->pFile));
szExt = szSuffix + (*szSuffix=='.');
pSuffix = stringToSymbol(szExt);
HS_FORALL(pSrcSym2,pItr2,pTmp)
{
if( MAP_defined(pSrcMap,pSrcSym2) )
{
pSource2 = MAP_apply(PRJ_Source,pSrcMap,pSrcSym2);
HS_UNION(pSource->pNeeds,pSource->pNeeds,pSource2->pNeeds);
if( pSource->pType == pSource2->pType &&
( HS_MBR_ELM(pSuffix,pSrcTyp->pTypSfx) ||
pSrcTyp->pObjSfx == pSuffix ) )
{
pSrcSym3 = PRJ_getSrcMod(pSource2,pSource->pType,(symbol)NULL);
if( pSrcSym3 != (symbol)NULL && pSrcSym2 != pSrcSym3 )
{
pSource3 = MAP_apply(PRJ_Source,pSrcMap,pSrcSym3);
HS_SET_ELM(pSrcSym3,pSource->pNeeds);
HS_UNION(pSource->pNeeds,pSource->pNeeds,pSource3->pNeeds);
}
if( pSource2->pPrefix != (symbol)NULL )
{
pSrcSym3 = PRJ_getSrcMod(pSource2,pSource->pType,pSource2->pPrefix);
if( pSrcSym3 != (symbol)NULL && pSrcSym2 != pSrcSym3 )
{
pSource3 = MAP_apply(PRJ_Source,pSrcMap,pSrcSym3);
HS_SET_ELM(pSrcSym3,pSource->pNeeds);
HS_UNION(pSource->pNeeds,pSource->pNeeds,pSource3->pNeeds);
}
}
}
if( HS_CARD(pSource->pNeeds) != lCard ) bChanges = True;
}
}
FreeMem(szSuffix);
HS_DROP_SET(pTmp);
}
}
}
if( pFP_Diag != (FILE*)NULL )
{
fprintf(pFP_Diag,"\n\n\n>>> Source-Closure:");
MAP_forItrAsg(pSrcSym,pSource,pItr,pSrcMap)
{
fprintf(pFP_Diag,"\n\n\t%s:",symbolToString(pSrcSym));
HS_FORALL(pSrcSym2,pItr2,pSource->pNeeds)
fprintf(pFP_Diag,"\n\t\t%s",symbolToString(pSrcSym2));
}
}
}
static SET(symbol) PRJ_collectIncludes(PRJ_Source pSource)
/* collect dependant include sources */
{ SET(symbol) pIncSet = HS_CREATE_ADTSET(symbol);
PRJ_Type pSrcTyp = MAP_apply(PRJ_Type,pProject->pTypDfn,pSource->pType);
PRJ_Source pDepSrc1, pDepSrc2;
HS_Itr pItr1, pItr2;
symbol pNeed1, pNeed2;
string szDepSfx1, szDepSfx2, szExt;
HS_FORALL(pNeed1,pItr1,pSource->pDepDfn)
{
if( MAP_defined(pSrcMap,pNeed1) && pSource->pFile != pNeed1 )
{
pDepSrc1 = MAP_apply(PRJ_Source,pSrcMap,pNeed1);
szDepSfx1 = FileSuffix(symbolToString(pNeed1));
szExt = szDepSfx1 + (*szDepSfx1=='.');
if( PRJ_IsInclude(
stringToSymbol(szExt),pSource->pType,
pSrcTyp->pIncSfx,(symbol*)NULL) )
{
HS_SET_ELM(pNeed1,pIncSet);
HS_FORALL(pNeed2,pItr2,pDepSrc1->pNeeds)
{
if( MAP_defined(pSrcMap,pNeed2) && pNeed1 != pNeed2 )
{
pDepSrc2 = MAP_apply(PRJ_Source,pSrcMap,pNeed2);
szDepSfx2 = FileSuffix(symbolToString(pNeed2));
szExt = szDepSfx2 + (*szDepSfx2=='.');
if( PRJ_IsInclude(
stringToSymbol(szExt),pSource->pType,
pSrcTyp->pIncSfx,(symbol*)NULL) )
HS_SET_ELM(pNeed2,pIncSet);
FreeMem(szDepSfx2);
}
}
}
FreeMem(szDepSfx1);
}
}
return pIncSet;
}
static bool PRJ_IsNeededTarget(symbol pTarget, SET(symbol) pNeeds)
{ HS_Itr pItr;
symbol pElm;
HS_FORALL(pElm,pItr,pNeeds)
{ PRJ_Target pDepTarget = MAP_apply(PRJ_Target,pDstMap,pElm);
if( pDepTarget->pRoot == pTarget )
{
HS_DROP_ITR(pItr); return True;
}
}
return False;
}
static PFN_Cmp pCurExtCmp = (PFN_Cmp)NULL;
static int PRJ_cmpTargets(OT_Obj pLft, OT_Obj pRgt)
{
return
strcmp(symbolToString((symbol)pLft),symbolToString((symbol)pRgt));
}
static int PRJ_cmpTargets_ext(OT_Obj pLft, OT_Obj pRgt)
{
return
( pCurExtCmp != (PFN_Cmp)NULL )
? (*pCurExtCmp)(symbolToString((symbol)pLft),symbolToString((symbol)pRgt))
: strcmp(symbolToString((symbol)pLft),symbolToString((symbol)pRgt));
}
static void PRJ_sortRuleTargets_aux
(
ROW(symbol) pDstRow, symbol pDstSym,
SET(symbol) pDstSet, SET(symbol) pVisitSet
)
{ PRJ_Target pTarget = MAP_apply(PRJ_Target,pDstMap,pDstSym),
pDepTarget, pRootTarget;
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
symbol pDepSym, pRoot;
HS_Itr pItr;
HS_SET_ELM(pDstSym,pVisitSet);
HS_FORALL(pDepSym,pItr,pTarget->pNeeds)
{
if( MAP_defined(pDstMap,pDepSym) )
{
pDepTarget = MAP_apply(PRJ_Target,pDstMap,pDepSym);
pRoot = ( pDepTarget->pRoot == (symbol)NULL )
? pDepSym : pDepTarget->pRoot;
pRootTarget = MAP_apply(PRJ_Target,pDstMap,pRoot);
if( PRJ_IsNeededTarget(pTarget->pFile,pRootTarget->pNeeds) &&
PRJ_IsNeededTarget(pDepTarget->pFile,pTarget->pNeeds) )
PRJ_printDepError(pTarget->pFile,pDepTarget->pFile,(PT_Term)NULL);
OT_S_INS(pTmp,pRoot,PRJ_cmpTargets);
}
}
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pDepSym = OT_GET(symbol,pTmp,lI);
if( HS_MBR_ELM(pDepSym,pDstSet) && ! HS_MBR_ELM(pDepSym,pVisitSet) )
PRJ_sortRuleTargets_aux(pDstRow,pDepSym,pDstSet,pVisitSet);
}
OT_PUSH(pDstSym,pDstRow);
OT_DEL_T(pTmp);
}
static void PRJ_sortRuleTargets(PRJ_Rule pRule)
/* sort rule root targets */
{ SET(symbol) pDstSet = HS_CREATE_ADTSET(symbol),
pVisitSet = HS_CREATE_ADTSET(symbol);
ROW(symbol) pTmp = OT_CREATE_ADT(symbol);
long lCnt, lI;
symbol pDstSym;
HS_Itr pItr;
int (*pCmpFun)(OT_Tab pLft, OT_Tab pRgt) = PRJ_cmpTargets;
if( PRJ_IsExternalTarget(pRule->pDstDfn) ) // externe Sortierung
{ string szExtFun = Str_printf
(
"%s_cmpTargets",symbolToString(pRule->pSrcTyp)
);
if( pRule->pRuleEnv->pDpsLib != (symbol)NULL )
pCurExtCmp = (PFN_Cmp)Glo_load
(
pRule->pRuleEnv->pDpsLib,stringToSymbol(szExtFun),True
);
pCmpFun = PRJ_cmpTargets_ext;
FreeMem(szExtFun);
}
HS_FORALL(pDstSym,pItr,pRule->pTargets)
{
if( MAP_apply(PRJ_Target,pDstMap,pDstSym)->pRoot == (symbol)NULL )
{
OT_S_INS(pTmp,pDstSym,pCmpFun);
HS_SET_ELM(pDstSym,pDstSet);
}
}
lCnt = OT_CNT(pTmp);
for( lI=0; lI < lCnt; ++lI )
{
pDstSym = OT_GET(symbol,pTmp,lI);
if( ! HS_MBR_ELM(pDstSym,pVisitSet) )
PRJ_sortRuleTargets_aux(pRule->pDstRow,pDstSym,pDstSet,pVisitSet);
}
OT_DEL_T(pTmp);
HS_DROP_SET(pDstSet);
HS_DROP_SET(pVisitSet);
pCurExtCmp = (PFN_Cmp)NULL;
}
static void PRJ_addTargetRootSourceClosure(void)
/* build root source closure for all targets with build rule 'byRoot' */
{ MAPIT pItr1;
symbol pRuleSym, pDstSym, pSrcSym, pDepSym, pSuffix, pPath, pFile;
PRJ_Rule pRule;
MAP_forItrAsg(pRuleSym,pRule,pItr1,pRuleMap)
{
if( PRJ_IsTargetByRoot(pRule->pDstDfn) )
{ HS_Itr pItr2, pItr3, pItr4;
PRJ_Type pSrcTyp = MAP_apply(PRJ_Type,pProject->pTypDfn,pRule->pSrcTyp);
HS_FORALL(pDstSym,pItr2,pRule->pTargets)
{ PRJ_Target pTarget = MAP_apply(PRJ_Target,pDstMap,pDstSym);
if( pTarget->pRoot == (symbol)NULL && HS_CARD(pTarget->pSources) > 0 )
{ SET(symbol) pTmp = HS_COPY(pTarget->pSources);
HS_FORALL(pSrcSym,pItr3,pTmp)
{ PRJ_Source pSource = MAP_apply(PRJ_Source,pSrcMap,pSrcSym);
HS_FORALL(pDepSym,pItr4,pSource->pNeeds)
{ string szDepSym = symbolToString(pDepSym),
szSuffix = FileSuffix(szDepSym),
szExt = szSuffix + (*szSuffix=='.'),
szPath = FilePrefix(szDepSym),
szTmp = szDepSym+strlen(szPath),
szFile = szTmp+AbsolutePathSep(szTmp);
pSuffix = stringToSymbol(szExt);
pFile = stringToSymbol(szFile);
if( MAP_defined(pSrcMap,pFile) )
{
pPath = MAP_apply(PRJ_Source,pSrcMap,pFile)->pPath;
if( ( HS_MBR_ELM(pSuffix,pSrcTyp->pTypSfx) ||
pSuffix == pSrcTyp->pObjSfx ) &&
HS_MBR_ELM(pPath,pRule->pSrcDir) )
HS_SET_ELM(pFile,pTarget->pSources);
}
FreeMem(szSuffix); FreeMem(szPath);
}
}
HS_DROP_SET(pTmp);
}
}
}
}
}
static void PRJ_addInternalTargetNeed
(
symbol pDepSrcFile, PRJ_Target pTarget, bool bInclude
)
/* add internal target need */
{ MAPIT pMItr;
HS_Itr pSItr;
symbol pRuleSym, pDstSym;
string szDepBase, szDstBase, szDstSfx, szExt;
SET(symbol) pSuffixes;
PRJ_Source pDepSource = MAP_apply(PRJ_Source,pSrcMap,pDepSrcFile);
bool bFound = False;
MAP_forItrAsg(pRuleSym,pSuffixes,pMItr,pTarget->pRule->pDepDfn)
{ PRJ_Rule pRule = MAP_apply(PRJ_Rule,pRuleMap,pRuleSym);
if( pRule->pSrcTyp == pDepSource->pType &&
HS_MBR_ELM(pDepSource->pPath,pRule->pSrcDir) )
{
if( PRJ_IsTargetByDirectory(pRule->pDstDfn) ||
PRJ_IsTargetBySource(pRule->pDstDfn) )
{
if( PRJ_IsTargetByDirectory(pRule->pDstDfn) )
{
if( MAP_defined(pRule->pSrcPat,pDepSource->pPath) )
{
szDepBase = PRJ_getDstBaseByMask
(
symbolToString(pDepSrcFile),
symbolToString
(
MAP_apply(symbol,pRule->pSrcPat,pDepSource->pPath)
)
);
}
else szDepBase = BaseFile(symbolToString(pDepSource->pPath));
}
else
{
szDepBase = BaseFile(symbolToString(pDepSrcFile));
}
if( szDepBase != (string)NULL )
{
HS_FORALL(pDstSym,pSItr,pRule->pTargets)
{ PRJ_Target pRuleTarget = MAP_apply(PRJ_Target,pDstMap,pDstSym);
if( pRuleTarget->pRoot != pTarget->pRoot ||
( pTarget->pRoot == (symbol)NULL && pDstSym != pTarget->pFile ) )
{
szDstBase = BaseFile(symbolToString(pDstSym));
szDstSfx = FileSuffix(symbolToString(pDstSym));
szExt = szDstSfx + (*szDstSfx=='.');
if( ! strcmp(szDepBase,szDstBase) &&
( HS_CARD(pSuffixes) == 0 ||
HS_MBR_ELM(stringToSymbol(szExt),pSuffixes) ) )
{
HS_SET_ELM(pDstSym,pTarget->pNeeds);
bFound = True;
}
FreeMem(szDstBase); FreeMem(szDstSfx);
}
}
FreeMem(szDepBase);
}
}
else
if( PRJ_IsTargetByName(pRule->pDstDfn, _) )
{
HS_FORALL(pDstSym,pSItr,pRule->pTargets)
{ PRJ_Target pRuleTarget = MAP_apply(PRJ_Target,pDstMap,pDstSym);
if( pRuleTarget->pRoot != pTarget->pRoot ||
( pTarget->pRoot == (symbol)NULL && pDstSym != pTarget->pFile ) )
{
szDstSfx = FileSuffix(symbolToString(pDstSym));
szExt = szDstSfx + (*szDstSfx=='.');
if( HS_CARD(pSuffixes) == 0 ||
HS_MBR_ELM(stringToSymbol(szExt),pSuffixes) )
{
HS_SET_ELM(pDstSym,pTarget->pNeeds);
bFound = True;
}
FreeMem(szDstSfx);
}
}
}
/* Baustelle
else
if( PRJ_IsTargetByRoot(pRule->pDstDfn) )
{
}
*/
if( bInclude ) bFound = True;
}
}
if( ! bFound )
{
(*pfnDepError)
(
pTarget->pRule->pDstDfn,"target for %s not found",
symbolToString(pDepSrcFile)
);
}
}
static symbol PRJ_getExtDir(symbol pPath, symbol pFile, PRJ_Rule pRule)
/* external directory symbol of 'pFile' or NULL */
{ symbol pResult = (symbol)NULL, pExtDir;
if( HS_MBR_ELM(pPath,pRule->pRuleEnv->pExtDir) ) pResult = pPath;
else
{ HS_Itr pItr;
HS_FORALL(pExtDir,pItr,pRule->pRuleEnv->pExtDir)
{ string szPath = MkPath
(
symbolToString(pExtDir),symbolToString(pFile),"",'d'
);
if( IsPath(szPath) )
{
pResult = pExtDir;
FreeMem(szPath);
HS_DROP_ITR(pItr); break;
}
FreeMem(szPath);
}
}
return pResult;
}
static void PRJ_addTargetNeed
(
PRJ_Source pSource, symbol pDepSym, PRJ_Target pTarget
)
/* add target need */
{ string szDepSym = symbolToString(pDepSym),
szSuffix = FileSuffix(szDepSym),
szExt = szSuffix + (*szSuffix=='.'),
szPath = FilePrefix(szDepSym),
szTmp = szDepSym+strlen(szPath),
szFile = szTmp+AbsolutePathSep(szTmp),
szDepBase, szDstBase;
symbol pSuffix = stringToSymbol(szExt),
pPath = stringToSymbol(szPath),
pFile = stringToSymbol(szFile),
pExtDir, pExtLib, pExtLibDir;
PRJ_Type pSrcTyp = MAP_apply
(
PRJ_Type,pProject->pTypDfn,pTarget->pRule->pSrcTyp
);
bool bInclude = PRJ_IsInclude
(
pSuffix,pTarget->pRule->pSrcTyp,
pSrcTyp->pIncSfx,(symbol*)NULL
);
if( MAP_defined(pSrcMap,pFile) )
{ PRJ_Source pDepSource = MAP_apply(PRJ_Source,pSrcMap,pFile);
if( PRJ_NoSourceDerivedTargets(pTarget->pRule->pAttr) )
/*do nothing*/;
else
if( pDepSource->pType != pTarget->pRule->pSrcTyp ||
! HS_MBR_ELM(pDepSource->pPath,pTarget->pRule->pSrcDir) )
{
PRJ_addInternalTargetNeed(pFile,pTarget,bInclude);
}
else
{
if( PRJ_IsTargetByDirectory(pTarget->pRule->pDstDfn) )
{
if( pSource->pPath != pDepSource->pPath )
PRJ_addInternalTargetNeed(pFile,pTarget,bInclude);
else
if( MAP_defined(pTarget->pRule->pSrcPat,pDepSource->pPath) )
{
szDepBase = PRJ_getDstBaseByMask
(
symbolToString(pFile),
symbolToString
(
MAP_apply
(
symbol,pTarget->pRule->pSrcPat,pDepSource->pPath
)
)
);
szDstBase = BaseFile(symbolToString(pTarget->pFile));
if( szDepBase == (string)NULL || strcmp(szDepBase,szDstBase) )
PRJ_addInternalTargetNeed(pFile,pTarget,bInclude);
if( szDepBase != (string)NULL ) FreeMem(szDepBase);
FreeMem(szDstBase);
}
}
else
if( PRJ_IsTargetBySource(pTarget->pRule->pDstDfn) )
{
szDepBase = BaseFile(szFile);
szDstBase = BaseFile(symbolToString(pTarget->pFile));
if( strcmp(szDepBase,szDstBase) )
PRJ_addInternalTargetNeed(pFile,pTarget,bInclude);
FreeMem(szDepBase); FreeMem(szDstBase);
}
/* equal source types and source path membership and
rule by name, by root, external
--> no dependant source-derivated target
*/
}
}
else
if( MAP_defined(pDstMap,pFile) ) // zusaetzliche Pfadpruefung ?!
{ PRJ_Target pDepTarget = MAP_apply(PRJ_Target,pDstMap,pFile);
if( pDepTarget->pType != pTarget->pRule->pSrcTyp )
HS_SET_ELM(pFile,pTarget->pNeeds);
else
(*pfnDepError)
(
pTarget->pRule->pDstDfn,"target dependant %s has source type",
symbolToString(pFile)
);
}
else
{
if( HS_MBR_ELM(pSuffix,pSrcTyp->pTypSfx) )
(*pfnDepError)
(
pTarget->pRule->pDstDfn,"external source %s not allowed",
symbolToString(pFile)
);
else
{
if( ! MAP_defined(pTarget->pRule->pRuleEnv->pExtLib,pFile) )
{
pExtDir = PRJ_getExtDir(pPath, pFile, pTarget->pRule);
if( pExtDir == (symbol)NULL && strlen(szPath) == 0 )
(*pfnDepError)
(
pTarget->pRule->pDstDfn, "path for %s not found",
symbolToString(pFile)
);
else
if( ! bInclude )
{
if( strlen(szPath) > 0 ) pExtDir = pPath;
if( ! MAP_defined(pTarget->pExtLib,pFile) )
MAP_dfndom(pTarget->pExtLib,pFile,pExtDir);
}
else // Inference of optional external Libraries
if( MAP_defined(pTarget->pRule->pRuleEnv->pOExtDir,pExtDir) )
{ MAPIT pItr;
MAP_forItrAsg
(
pExtLib,pExtLibDir,pItr,pTarget->pRule->pRuleEnv->pOExtLib
)
{
if( MAP_apply
(
PT_Term,pTarget->pRule->pRuleEnv->pOExtDir,pExtLibDir
)
== MAP_apply
(
PT_Term,pTarget->pRule->pRuleEnv->pOExtDir,pExtDir
)
&& ! MAP_defined(pTarget->pExtLib,pExtLib) )
MAP_dfndom(pTarget->pExtLib,pExtLib,pExtLibDir);
}
}
}
}
}
FreeMem(szSuffix); FreeMem(szPath);
}
static void PRJ_addTargetNeeds(void)
/* add target needs */
{ symbol pDstSym, pSrcSym, pDepSym, pLibFile;
PRJ_Target pTarget;
MAPIT pItr1, pItr2;
MAP_forItrAsg(pDstSym,pTarget,pItr1,pDstMap)
{
if( pTarget->pRoot == (symbol)NULL &&
PRJ_IsExecutable(pTarget->pRule->pAttr) )
{ HS_Itr pItr3, pItr4;
MAP_forItr(pLibFile,pItr2,pTarget->pRule->pRuleEnv->pExtLib)
{
if( MAP_defined(pDstMap,pLibFile) )
HS_SET_ELM(pLibFile,pTarget->pNeeds);
}
HS_FORALL(pSrcSym,pItr3,pTarget->pSources)
{ PRJ_Source pSource = MAP_apply(PRJ_Source,pSrcMap,pSrcSym);
HS_FORALL(pDepSym,pItr4,pSource->pNeeds)
{
if( ! HS_MBR_ELM(pDepSym,pTarget->pSources) )
{
PRJ_addTargetNeed(pSource, pDepSym, pTarget);
}
}
}
}
}
}
/* -------------------------- Standard Scanner ---------------------------- */
static void C_parse
(
string szSrcPath, StdCPtr pDepFiles,
PFN_AddDep pAddDepFun, bool* pbRoot
)
/* Dependency Scanner for Standard Source Type C */
{ string szTxt, szTmp, szFile;
int nLen, nI;
Scn_T pScn;
Scn_Stream pStream;
Scn_get_cdps(&pScn);
pStream = Stream_file(pScn, "", szSrcPath, "");
Stream_defEofId(pStream, -1);
Stream_defErrId(pStream, 0);
Stream_defTokId(pStream, "Include", 1);
Stream_defTokId(pStream, "Library", 2);
Stream_defTokId(pStream, "Resource", 3);
Stream_defTokId(pStream, "Program", 4);
*pbRoot = False;
for(Stream_next(pStream); Stream_ctid(pStream) >= 0; Stream_next(pStream))
{
szTxt = symbolToString(Stream_csym(pStream));
if (Stream_ctid(pStream) == 1 && Stream_ccol(pStream) == 1)
{
szTmp = strstr(szTxt,"\"");
if( szTmp != (string)NULL )
{
szTmp += 1;
nLen = strlen(szTmp);
for( nI=nLen-1; nI >=0; --nI ) if( szTmp[nI] == '"' ) break;
}
else
{
szTmp = strstr(szTxt,"<");
if( szTmp != (string)NULL )
{
szTmp += 1;
nLen = strlen(szTmp);
for( nI=nLen-1; nI >=0; --nI ) if( szTmp[nI] == '>' ) break;
}
}
if( szTmp != (string)NULL )
{
szFile = SubStrCopy(szTmp,nI);
(*pAddDepFun)(pDepFiles,szFile);
FreeMem(szFile);
}
}
else
if (Stream_ctid(pStream) == 2)
{
nLen = strlen(szTxt);
szFile = SubStrCopy(szTxt+7,nLen-9);
(*pAddDepFun)(pDepFiles,szFile);
FreeMem(szFile);
}
else
if (Stream_ctid(pStream) == 3)
{
nLen = strlen(szTxt);
szFile = SubStrCopy(szTxt+7,nLen-9);
(*pAddDepFun)(pDepFiles,szFile);
FreeMem(szFile);
}
else
if (Stream_ctid(pStream) == 4) *pbRoot = True;
}
Stream_close(pStream);
Stream_free(pStream);
Scn_free(pScn);
}
/* -------------------------- Pass 1 -------------------------------------- */
static void PRJ_addMacro(GLS_Tok pMacNam, cprjMacDfn pMacDfn)
/* add macro definition ( override previous definition ) */
{ cprjRelOp pRelOp;
GLS_Tok pMacVal1, pMacVal2, pName1, pName2;
string szName1, szName2;
symbol pVal = (symbol)NULL;
if( cprjMacDfn_val(pMacDfn,&pMacVal1) )
{
pVal = PRJ_ValueToSymbol(pMacVal1);
}
else
{
assert0
(
cprjMacDfn_cond(pMacDfn,&pName1,&pRelOp,&pName2,&pMacVal1,&pMacVal2),""
);
szName1 = PRJ_expandName(symbolToString(GLS_Tok_symbol(pName1)));
szName2 = PRJ_expandName(symbolToString(GLS_Tok_symbol(pName2)));
if( szName1 != (string)NULL && szName2 != (string)NULL )
{ bool bCond = False;
if( cprjRelOp_eq(pRelOp) )
bCond = ( ! strcmp(szName1,szName2) );
else
if( cprjRelOp_ne(pRelOp) )
bCond = strcmp(szName1,szName2);
else
if( cprjRelOp_le(pRelOp) )
bCond = ( strcmp(szName1,szName2) <= 0 );
else
if( cprjRelOp_lt(pRelOp) )
bCond = ( strcmp(szName1,szName2) < 0 );
else
if( cprjRelOp_ge(pRelOp) )
bCond = ( strcmp(szName1,szName2) >= 0 );
else
if( cprjRelOp_gt(pRelOp) )
bCond = ( strcmp(szName1,szName2) > 0 );
else C_BUG;
pVal = PRJ_ValueToSymbol(bCond?pMacVal1:pMacVal2);
}
else
PT_error
(
pMacDfn,"condition specification:\n %s\n %s",
symbolToString(GLS_Tok_symbol(pName1)),
symbolToString(GLS_Tok_symbol(pName2))
);
if( szName1 != (string)NULL ) FreeMem(szName1);
if( szName2 != (string)NULL ) FreeMem(szName2);
}
MAP_ovrdom(pMacMap,GLS_Tok_symbol(pMacNam),pVal);
}
static void PRJ_execCommand(GLS_Tok pCmdVal)
/* exec command ( prepocessing, e.g. ctoh ) */
{ symbol pVal = PRJ_ValueToSymbol(pCmdVal);
if( pVal != (symbol)NULL && strlen(symbolToString(pVal)) > 0 )
//{ int res = runprg(symbolToString(pVal),STD_CMD_WAIT);
{ int res = system(symbolToString(pVal));
if( res != 0 )
{
fprintf
(
STDERR,"'prdps' aborted due to error code (%s:%d).\n",
symbolToString(pVal), res
);
exit(1);
}
}
}
static void PRJ_addCommand
(
PRJ_Environ pEnviron, GLS_Tok pTypNam, GLS_Tok pCmdVal
)
/* add command definition */
{ ROW(symbol) pCmds;
symbol pVal;
if( ! MAP_defined(pEnviron->pTypCmd,GLS_Tok_symbol(pTypNam)) )
{
pCmds = OT_CREATE_ADT(symbol);
MAP_dfndom(pEnviron->pTypCmd,GLS_Tok_symbol(pTypNam),pCmds);
}
else
pCmds = MAP_apply(ROW(symbol),pEnviron->pTypCmd,GLS_Tok_symbol(pTypNam));
pVal = PRJ_ValueToSymbol(pCmdVal);
OT_PUSH(pVal,pCmds);
}
static void PRJ_addParameter
(
PRJ_Environ pEnviron, GLS_Tok pTypNam,
GLS_Tok pParNam, GLS_Tok pParVal
)
/* add command parameter definition */
{ MAP(symbol,symbol) pPars;
if( ! MAP_defined(pEnviron->pCmdPar,GLS_Tok_symbol(pTypNam)) )
{
pPars = MAP_newPrimMap();
MAP_dfndom(pEnviron->pCmdPar,GLS_Tok_symbol(pTypNam),pPars);
}
else
pPars = MAP_apply
(
MAP(symbol,symbol),pEnviron->pCmdPar,GLS_Tok_symbol(pTypNam)
);
MAP_ovrdom(pPars,GLS_Tok_symbol(pParNam),PRJ_ValueToSymbol(pParVal));
}
static void PRJ_addPrjDirectories(PRJ_Environ pEnviron, GLS_Tok pPrjDir)
/* add project directories */
{
if( pEnviron->pPrjDir == (symbol)NULL )
{
pEnviron->pPrjDir = PRJ_NameToSymbol(pPrjDir);
}
else PT_error(pPrjDir,"project directory already defined");
}
static void PRJ_addDstDirectories(PRJ_Environ pEnviron, GLS_Tok pDstDir)
/* add target directories */
{
if( pEnviron->pDstDir == (symbol)NULL )
{
pEnviron->pDstDir = PRJ_NameToSymbol(pDstDir);
}
else PT_error(pDstDir,"target directory/ies already defined");
}
static void PRJ_addObjDirectories(PRJ_Environ pEnviron, GLS_Tok pObjDir)
/* add object directories */
{
if( pEnviron->pObjDir == (symbol)NULL )
{
pEnviron->pObjDir = PRJ_NameToSymbol(pObjDir);
}
else PT_error(pObjDir,"object directory already defined");
}
static void PRJ_addRepository
(
PRJ_Environ pEnviron, GLS_Tok pDpsLib
)
/* add type repository */
{
if( pEnviron->pDpsLib == (symbol)NULL )
{
pEnviron->pDpsLib = PRJ_NameToSymbol(pDpsLib);
}
else PT_error(pDpsLib,"type repository already defined");
}
static void PRJ_addExtDirectories
(
PRJ_Environ pEnviron, GLS_Tok pPathes, bool bOptional
)
/* add external include and library directories */
{ PIT pItr; string szPath, szPathes; symbol pPath;
szPathes = PRJ_expandName(symbolToString(GLS_Tok_symbol(pPathes)));
if( szPathes != (string)NULL )
{
pItr = PIT_make(szPathes);
PRJ_setPathSep(szPathes,pItr);
while( ( szPath = PIT_read(pItr) ) != NULL )
{
pPath = stringToSymbol(szPath);
HS_SET_ELM(pPath,pEnviron->pExtDir);
if( bOptional )
if( ! MAP_defined(pEnviron->pOExtDir,pPath) )
MAP_dfndom(pEnviron->pOExtDir,pPath,pPathes);
}
PIT_drop(pItr); FreeMem(szPathes);
}
else
PT_error
(
pPathes,"path specification: %s",symbolToString(GLS_Tok_symbol(pPathes))
);
}
static void PRJ_addLibraries(PRJ_Environ pEnviron, GLS_Tok pPathes)
/* add ( external ) libraries */
{ PIT pItr; string szPath, szPathes;
szPathes = PRJ_expandName(symbolToString(GLS_Tok_symbol(pPathes)));
if( szPathes != (string)NULL )
{
pItr = PIT_make(szPathes);
PRJ_setPathSep(szPathes,pItr);
while( ( szPath = PIT_read(pItr) ) != NULL )
{ symbol pLib = stringToSymbol(szPath),
pDir = (symbol)NULL, pElm;
HS_Itr pItr;
HS_FORALL(pElm,pItr,pEnviron->pExtDir)
{
if( IsDirEntry(szPath,symbolToString(pElm)) )
{
pDir = pElm; HS_DROP_ITR(pItr); break;
}
}
if( pDir == (symbol)NULL && pEnviron != pProject->pStdEnv )
{
HS_FORALL(pElm,pItr,pProject->pStdEnv->pExtDir)
{
if( IsDirEntry(szPath,symbolToString(pElm)) )
{
pDir = pElm; HS_DROP_ITR(pItr); break;
}
}
}
// pDir = NULL --> internal Library
if( pDir == (symbol)NULL || ! MAP_defined(pEnviron->pOExtDir,pDir) )
MAP_dfndom(pEnviron->pExtLib,pLib,pDir);
else
MAP_dfndom(pEnviron->pOExtLib,pLib,pDir);
}
PIT_drop(pItr); FreeMem(szPathes);
}
else
PT_error
(
pPathes,"path specification: %s",symbolToString(GLS_Tok_symbol(pPathes))
);
}
static void PRJ_addType(cprjTypDfn pTypDfn)
/* add source / target type */
{ GLS_Tok pName, pSuffixes = (symbol)NULL, pSuffix;
assert0
(
cprjTypDfn_one(pTypDfn,&pName) ||
cprjTypDfn_two(pTypDfn,&pName,&pSuffixes),""
);
if( ! MAP_defined(pProject->pTypDfn,GLS_Tok_symbol(pName)) )
{ PRJ_Type pType = PRJ_newType();
MAP_dfndom(pProject->pTypDfn,GLS_Tok_symbol(pName),pType);
if( pSuffixes != (symbol)NULL )
{ PIT pItr1, pItr2; int nGroup = 0;
string szSuffix, szSuffixes, szSfxGroups;
szSfxGroups = PRJ_expandName(symbolToString(GLS_Tok_symbol(pSuffixes)));
if( szSfxGroups != (string)NULL )
{
pItr1 = PIT_make(szSfxGroups); PIT_sep(pItr1,";");
while( ( szSuffixes = PIT_read(pItr1) ) != NULL )
{
++nGroup;
if( strlen(szSuffixes) > 0 )
{
if( nGroup < 3 )
{ SET(symbol) pSet = ( nGroup == 1 )
? pType->pTypSfx : pType->pIncSfx;
pItr2 = PIT_make(szSuffixes); PIT_sep(pItr2,".");
while( ( szSuffix = PIT_read(pItr2) ) != NULL )
{
pSuffix = stringToSymbol(szSuffix);
if( pType->pFstSfx == (symbol)NULL )
pType->pFstSfx = pSuffix;
HS_SET_ELM(pSuffix,pSet);
if( *szSuffix == '&' )
{
if( pSet != pType->pIncSfx )
PT_error
(
pSuffixes,
" type references only in include section: %s",szSuffix
);
else
if( ! MAP_defined(
pProject->pTypDfn,stringToSymbol(szSuffix+1)) )
PT_error(pSuffixes, "type '%s' not found",szSuffix+1);
}
}
PIT_drop(pItr2);
}
else
if( nGroup == 3 )
pType->pObjSfx = stringToSymbol(szSuffixes);
}
}
if( nGroup > 3 )
PT_error
(
pSuffixes,"too many groups in suffix specification: %s",szSfxGroups
);
PIT_drop(pItr1); FreeMem(szSfxGroups);
}
else
PT_error
(
pSuffixes,"suffix specification: %s",
symbolToString(GLS_Tok_symbol(pSuffixes))
);
}
}
else
PT_error
(
pName,"type %s already defined", symbolToString(GLS_Tok_symbol(pName))
);
}
static bool PRJ_addRuleDepRule(PRJ_Rule pRule, string szDepExp)
/* add dependant rule */
{ bool bResult = False;
string szDepExpPart;
symbol pDepRuleSym;
SET(symbol) pSuffixes = (SET(symbol))NULL;
PIT pItr;
pItr = PIT_make(szDepExp); PIT_sep(pItr,".");
while( ( szDepExpPart = PIT_read(pItr) ) != NULL )
{
if( bResult == False )
{
pDepRuleSym = stringToSymbol(szDepExpPart);
if( MAP_defined(pRuleMap,pDepRuleSym) )
{ PRJ_Rule pDepRule = MAP_apply(PRJ_Rule,pRuleMap,pDepRuleSym);
bResult = True;
if( ! PRJ_IsTargetByRoot(pDepRule->pDstDfn) &&
! PRJ_IsExternalTarget(pDepRule->pDstDfn) )
{
if( ! MAP_defined(pRule->pDepDfn,pDepRuleSym) )
{
pSuffixes = HS_CREATE_ADTSET(symbol);
MAP_dfndom(pRule->pDepDfn,pDepRuleSym,pSuffixes);
HS_SET_ELM(pDepRuleSym,pRule->pNeeds);
OT_PUSH(pDepRuleSym,pRule->pDepRow);
}
else pSuffixes = MAP_apply(SET(symbol),pRule->pDepDfn,pDepRuleSym);
}
else
{
PT_error
(
pRule->pDstDfn,"rule %s not allowed as dependant",
symbolToString(pDepRule->pName)
);
break;
}
}
else break;
}
else HS_SET_ELM(stringToSymbol(szDepExpPart),pSuffixes);
}
PIT_drop(pItr);
return bResult;
}
static void PRJ_addRuleDepDfn(PRJ_Rule pRule, GLS_Tok pDepPathes)
/* add rule dependants */
{ PIT pItr;
string szPath, szPathes, szPathDir, szPat1, szPat2, szPat, szDir, szTmp;
szPathes = PRJ_expandName(symbolToString(GLS_Tok_symbol(pDepPathes)));
if( szPathes != (string)NULL )
{
pItr = PIT_make(szPathes);
PRJ_setPathSep(szPathes,pItr);
while( ( szPath = PIT_read(pItr) ) != NULL )
{
if( ! PRJ_addRuleDepRule(pRule,szPath) )
{
if( PRJ_getPathPattern(szPath,&szPathDir,&szPat1) )
/*
Beispiel:
e:\sp_entw\lvdb&&&& |-->
Verzeichnisse e:\sp_entw\lvdb???? und
Quelldateien ????&&&&. 'bin_dump' creates a dump of the binary image file 'Filename'.
cod
Arguments
Filename : path -- binary file
Options
Environment
styx-2.0.1/util/genmak.c 0000666 0001750 0001750 00000071431 07447343346 012055 0000000 0000000 /* [genmak.c] generates automake input 'cmdarg' translates a command description file [$CMDENV/Program.cmd] into
either a binary image file [$CIMENV/Program.cim] or a C-source module
[$CMDGEN/Program_cim.c].
A command description contains all the arguments and environment variables
necessary for program executes, and, moreover, the options known by the program.
The program accesses this information throuh the module [ctx_app].
The loading, verification and unloading of the current program context
can be achieved by the functions 'CTX_init' and 'CTX_quit' within the
module [ctx] or the corresponding functions of the generated C-module.
[cmd.sty] defines the syntax of a command description file [.cmd].
cod
Arguments
Command : name -- name of the command i.e. program
Options
version : flag = false -- entertainment
makeC : flag = false -- generates C-source instead of binary image [.cim]
shortform : flag = false -- use short form of language name
Environment
CMDENV : path = "." -- [.cmd] source directory
CIMENV : path = "." -- [.cim] target directory
CMDGEN : path = "." -- [.c] target directory
styx-2.0.1/util/sh_ctx.c 0000666 0001750 0001750 00000001266 07447343346 012102 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [sh_ctx.c] Shellscript context */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "ctx.h"
int main(int argc, string argv[])
{
assert0(argc>1,"Usage: sh_ctx command argument ...");
CTX_init(argc-1, &argv[1]);
CTX_sh_list();
CTX_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/util/cmddoc.cmd 0000666 0001750 0001750 00000001161 07507042030 012335 0000000 0000000 # [cmddoc.cmd] command description for [cmddoc.c]
Program cmddoc -- CMD Documentation Generator
doc
'cmddoc' produces a HTM-like documentation for a command description file [.cmd].
cod
Arguments
InFile : path -- path of the command description file
OutFile : path -- path of the target file
Options
Template : path = "/p/styx/pat/pcmddoc_us.htm" -- path list with template files
RefAlias : string = "&" -- alias for the first character of a pattern reference
recursiv : flag = false -- recursive pattern evaluation
Environment
PATH : path -- search path for binary images [.lim,.pim]
styx-2.0.1/util/com.cmd 0000666 0001750 0001750 00000000406 07507042030 011663 0000000 0000000 # [com.cmd] command description for [com.c]
Program com -- extended ls utility
doc
'com' lists files and file header comments.
cod
Arguments
vargs : string -- files / directories
Options
r : flag = false -- recursive
Environment
styx-2.0.1/util/reformat.c 0000666 0001750 0001750 00000006642 07623660713 012430 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [reformat.c] Reformats Sources */
/* */
/* Copyright (c) 1994 by Lars D\olle, Heike Manns */
/* ------------------------------------------------------------------------ */
#ifdef DOCUMENT
Zusammenfassung
"reformat" fuegt '\f'-Zeichen an geeigneten Stellen ein.
Parameter
| reformat Filename
#endif
#include "stdosx.h"
#include "pathes.h"
#include "line_scn.h"
#include "otab.h"
#include "refo_cim.h"
FILE *SysIn;
FILE *SysOut;
long srclin;
long pagenr;
#define PageLength CTX_EVAL(int,"PageLength")
ROW(ROW(string)) blocks;
bool is_section(ROW(string) blk)
/* whether a block starts a section */
/* rule: first line contains "-----" */
{ string s; int i,len;
if (OT_CNT(blk) < 1) return False;
s=OT_GET(string,blk,0);
len = strlen(s);
if (*s != 0 && *s != ' ')
for (i = 0; i < len-5; i++)
if (!strncmp(s+i,"-----",5))
return True;
return False;
}
ROW(string) getBlock(void)
/* read a block */
{ string lin; long len;
ROW(string) tab = OT_CREATE(string,primCopy,FreeMem,primEqual);
Skip:
lin = Line_get(SysIn);
if (lin == NULL)
goto Done;
len = strlen(lin);
if (len == 0)
{
FreeMem(lin);
goto Skip;
}
Line:
OT_T_INS(tab,lin);
lin = Line_get(SysIn);
if (lin == NULL)
goto Done;
len = strlen(lin);
if (len == 0)
{
FreeMem(lin);
goto Done;
}
goto Line;
Done:
return tab;
}
void printPage(int nr_of_blocks)
{ int i;
printf("%4ld | ",srclin);
if (pagenr > 1)
{
fprintf(SysOut,"\f\n");
printf(" "); srclin += 1;
}
for (i = 0; i < nr_of_blocks; i++)
{ ROW(string) r = OT_GET(ROW(string),blocks,i);
long j,cnt = OT_CNT(r);
if (i > 0)
{
fprintf(SysOut,"\n");
printf(" "); srclin+=1;
}
for (j = 0; j < cnt; j++)
{
fprintf(SysOut,"%s\n",OT_GET(string,r,j));
printf("*"); srclin+=1;
}
OT_DEL_T(r);
}
OT_DEL_ES(blocks,0,nr_of_blocks);
pagenr += 1;
printf("\n");
}
void addBlock(ROW(string) block)
{ int i; long sum = OT_CNT(blocks), cnt = sum+1, pos = 0;
bool posfound = False;
OT_PUSH(block,blocks);
for (i = 0; i < cnt; i++)
{
sum += OT_CNT(OT_GET(ROW(string),blocks,i));
if (i > 0 && !posfound && is_section(OT_GET(ROW(string),blocks,i)))
{
posfound = OT_CNT(OT_GET(ROW(string),blocks,i)) > 1;
pos = i;
}
}
if (posfound || sum >= PageLength)
printPage((int)(pos ? pos : cnt-1));
}
void reformat(void)
{ ROW(string) tmp;
blocks = OT_CREATE_ADT(ROW(string));
for(tmp = getBlock(); OT_CNT(tmp) > 0; tmp = getBlock())
addBlock(tmp);
OT_DEL_T(tmp);
if (OT_CNT(blocks)>0) printPage((int)OT_CNT(blocks));
OT_DEL_T(blocks);
}
#define tnam "reformat.$$$"
#define fnam CTX_EVAL(string,"FileName")
int main(int argc, string argv[])
{
CTX_init_reformat(argc,argv);
SysIn = OpnFile(fnam,"rt");
SysOut = OpnFile(tnam,"wt");
srclin = 1;
pagenr = 1;
/**/printf("File : '%s'\n",fnam);
/**/printf("Line | ---------+---------+---------+---------");
/**/printf("+---------+---------+---------+--\n");
reformat();
printf("%4ld pages\n",pagenr-1);
fclose(SysOut);
fclose(SysIn);
remove(fnam); rename(tnam,fnam);
CTX_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/util/t.c 0000666 0001750 0001750 00000011022 11150275265 011032 0000000 0000000 #include "stdosx.h"
#include "gstream.h"
#include "scn_imp.h"
#include "symbols.h"
#if defined( _MSDOS ) || defined( _WIN32 )
#define CS_LATIN1 "850"
#else
#define CS_LATIN1 "LATIN1"
#endif
int xfmain(int c, char* argv[])
{
if( SCN_CHAR_SET_SIZE < 0 )
printf("<%u\n",SCN_CHAR_SET_SIZE);
else
printf(">=%u\n",SCN_CHAR_SET_SIZE);
return(0);
}
int fmain(int c, char* argv[])
{ FILE* fp = fopen(argv[1],"rb");
char buf[500];
char lbuf[500];
string x;
wc_char wbuf[500];
wchar_t* w = L"Das ist ein Test !ÄÜÖ";
wchar_t* wx;
c_string s = "Das ist ein Test !ÄÜÖ";
int rc1, rc2, rc3, rc4, l, ll, i, sl = 22, wsl=22*4, tl = 500, wtl = 500*4;
CSConv_T conv1 = GS_csconv_new("WCHAR_T"/*CS_ID_WCHAR*/,CS_LATIN1);
CSConv_T conv2 = GS_csconv_new("WCHAR_T","WCHAR_T"/*CS_ID_WCHAR,CS_ID_WCHAR*/);
CSConv_T conv3 = GS_csconv_new(CS_ID_MBYTE/*"UTF-8"*/,"WCHAR_T"/*CS_ID_WCHAR*/);
CSConv_T conv4 = GS_csconv_new(CS_LATIN1/*"UTF-8"*/,CS_ID_MBYTE);
GStream_T gstream = GS_stream_file_new(fp,CS_LATIN1,False);
assert1(fp != NULL,"open %s failed",argv[1]);
assert0(gstream != NULL,"stream create failed");
/**/
wbuf[0] = L'\0';
buf[0] = '\0';
l = wtl;
rc1 = GS_csconv_string(conv1,s,sl,(c_string)wbuf,&l);
if( rc1 >= 0 )
{
wbuf[l] = L'\0';
printf("\nSTR-CNV-1=%S\n",wbuf);
for( i=0; i < 18; ++i )
printf("\nWBUF[i]=%ld\n",(long int)wbuf[i]);
}
else
printf("STR-CNV-1-ERR %d\n",rc1);
wbuf[0] = L'\0';
buf[0] = '\0';
l = wtl;
rc2 = GS_csconv_string(conv2,(c_string)w,wsl,(c_string)wbuf,&l);
if( rc2 >= 0 )
{
wbuf[l] = L'\0';
printf("\nSTR-CNV-2=%S\n",wbuf);
for( i=0; i < 18; ++i )
printf("\nWBUF[i]=%ld\n",(long int)wbuf[i]);
}
else
printf("STR-CNV-2-ERR %d\n",rc2);
wbuf[0] = L'\0';
buf[0] = '\0';
l = tl;
rc3 = GS_csconv_string(conv3,(c_string)w,wsl,buf,&l);
if( rc3 >= 0 )
{
buf[l] = '\0';
printf("\nSTR-CNV-3=%s\n",buf);
}
else
printf("STR-CNV-3-ERR %d\n",rc3);
lbuf[0] = '\0';
ll = tl;
rc4 = GS_csconv_string(conv4,(c_string)buf,l,lbuf,&ll);
if( rc4 >= 0 )
{
lbuf[l] = '\0';
printf("\nSTR-CNV-4=%s\n",lbuf);
}
else
printf("STR-CNV-4-ERR %d\n",rc4);
for( i=0; i < 18; ++i )
printf("\nW[i]=%C\n",w[i]);
x = GS_ucs4_to_utf8(w);
if( x != NULL )
{
for( i=0; i < strlen(x); ++i )
{
printf("\nx[i]=%d\n",x[i]);
}
printf("\nx=%s\n",buf);
wx = GS_utf8_to_ucs4(x);
if( wx != NULL && WCStrLen(w) == (l=WCStrLen(wx)) )
{
for( i=0; i < l; ++i )
{
if( w[i] != wx[i] )
{
printf("Verschieden: %d\n",i);
break;
}
}
if( i >= l ) printf("OK !\n");
}
else printf("Fehler: %s\n",wx != NULL ? "Länge" : "NULL");
if( wx != NULL ) FreeMem(wx);
FreeMem(x);
}
/**/
/*
rc = GS_stream_get_wcrc(gstream);
for( i=0; rc > 0; )
{
printf("WCHAR %ld=%08x %C\n",++i,rc,rc);
rc = GS_stream_get_wcrc(gstream);
}
*/
GS_csconv_free(conv1);
GS_csconv_free(conv2);
GS_csconv_free(conv3);
GS_csconv_free(conv4);
GS_stream_file_free(gstream);
if( fp != NULL ) fclose(fp);
//printf("\nW=%S\n",w);
return 0;
}
int lmain(int argc, char* argv[])
{ long long int x = 30560;
long y = x >> 16;
short z = x >> 16;
long yy = x >> 0;
short zz = x >> 0;
printf("SIZE=%ld\n",sizeof(long long int));
printf("LONG-HI=%ld\n",y);
printf("LONG-LO=%ld\n",yy);
printf("SHORT-HI=%d\n",z);
printf("SHORT-LO=%d\n",zz);
return 0;
}
int bmain(int argc, char* argv[])
{ FILE* fp = fopen("udp.src","w");
unsigned short psrc, pdst, len, crc;
char* text = "hallo welt !";
psrc = 25;
pdst = 33667;
len = 8 + 13;
crc = 12345;
if( fp != NULL )
{
if( fwrite(&psrc,1,2,fp) != 2 )
{
printf("error\n"); return 1;
}
if( fwrite(&pdst,1,2,fp) != 2 )
{
printf("error\n"); return 1;
}
if( fwrite(&len,1,2,fp) != 2 )
{
printf("error\n"); return 1;
}
if( fwrite(&crc,1,2,fp) != 2 )
{
printf("error\n"); return 1;
}
if( fwrite(text,1,13,fp) != 13 )
{
printf("error\n"); return 1;
}
fclose(fp);
}
else
{
printf("error\n"); return 1;
}
printf("OK\n");
return 0;
}
int main(int argc, char* argv[])
{ string s = "äöü-Umlaute";
int l = strlen(s),i;
symbol sy;
initSymbols();
fprint_raw(STDOUT,s,-1);
NL;
for(i=0; i ") == cmdbuf )
{
*list = parameters; *cnt = cnt_parameters; return 3;
}
else return 0;
}
// forward
static int evalStrExp(string cmdbuf, string resbuf);
static int evalNumExp(string cmdbuf, int* result);
static int evalBoolExp(string cmdbuf, bool* result);
static int evalSpace(string cmdbuf)
// RC = Anzahl verarbeiteter Bytes
{ string s = cmdbuf; int pos = 0;
while( s[pos] == ' ' || s[pos] == '\n' ) pos += 1;
return pos;
}
static int skipArg(string cmdbuf)
// RC = Anzahl verarbeiteter Bytes oder -1
{ string s = cmdbuf, t, v;
int pos = -1, tmp = 0;
t = strstr(s,"");
if( t != (string)NULL )
{
s = t + 3; ++tmp;
while( True )
{
v = strstr(s,"");
if( v == (string)NULL ) break;
t = strstr(s,"");
if( t == (string)NULL || t - v > 0 )
{
s = v + 4; --tmp;
if( tmp == 0 ) // OK
{
pos = s - cmdbuf; break;
}
}
else
{
s = t + 3; ++tmp;
}
}
}
return pos;
}
static int evalNumArg(string cmdbuf, int* result)
// RC = Anzahl verarbeiteter Bytes oder -1
{ char buf[CMDLEN+1]; int pos;
buf[0] = '\0';
if( strstr(cmdbuf,"") == cmdbuf )
{
pos = skipArg(cmdbuf);
if( pos > 0 )
{
CmdStrCat(buf, cmdbuf+3);
buf[pos-7] = '\0';
if( evalNumExp(buf,result) > 0 ) return pos;
}
return -1;
}
return 0;
}
static int evalBoolArg(string cmdbuf, bool* result)
// RC = Anzahl verarbeiteter Bytes oder -1
{ char buf[CMDLEN+1]; int pos;
buf[0] = '\0';
if( strstr(cmdbuf,"") == cmdbuf )
{
pos = skipArg(cmdbuf);
if( pos > 0 )
{
CmdStrCat(buf, cmdbuf+3);
buf[pos-7] = '\0';
if( evalBoolExp(buf,result) > 0 ) return pos;
}
return -1;
}
return 0;
}
static int evalStrArg(string cmdbuf, string resbuf)
// RC = Anzahl verarbeiteter Bytes oder -1
{ char buf[CMDLEN+1]; int pos;
buf[0] = '\0';
if( strstr(cmdbuf,"") == cmdbuf )
{
pos = skipArg(cmdbuf);
if( pos > 0 )
{
CmdStrCat(buf, cmdbuf+3);
buf[pos-7] = '\0';
if( evalStrExp(buf,resbuf) > 0 ) return pos;
}
return -1;
}
return 0;
}
static int evalFun_read(string cmdbuf, string resbuf)
// RC = Anzahl verarbeiteter Bytes oder -1
{ char buf[CMDLEN+1];
char line[BUFLEN+1];
string s = cmdbuf;
int pos, tmp;
buf[0] = '\0';
if( strstr(cmdbuf," This module [ctx] provides functions for the definition of a program context and
the verification of the current commandline against the current program context.
The definition interface will be used by the CMD Compiler
which parses and evaluates a command decription file [.cmd], constructs a program context
out of it and finally makes it persistent.
The application interface will be used by the applications and the generated
program specific context modules.
The module [hpat] provides some functionality for the evaluation of
template files based on the context-free grammar [hpat.sty].
It is used by the STYX reference generator.
Pattern types */
/*DOC_INTERFACE*/
#define HPAT_REF_LIST 0 // pattern list
#define HPAT_REF_PAT 1 // pattern
#define HPAT_REF_PAR 2 // pattern parameter
AbstractType(HPat_T); // Abstract template type
/*! Callback function types */
/*DOC_INTERFACE*/
// pattern reference evaluation function
typedef c_bool (*PFN_Pat)(HPat_T pHPat);
/*DOC_INTERFACE*/
// print function
typedef void (*PFN_PatPrint)(HPat_T pHPat, c_string szTxt);
/*DOC_INTERFACE*/
// replacement specification pattern load function
typedef StdCPtr (*PFN_PatLoad)(GLS_Lst(hpatContent) pLst);
// replacement specification apply function
typedef c_string (*PFN_PatOpr)(c_string szTxt, StdCPtr pData);
// replacement specification free function
typedef void (*PFN_PatFree)(StdCPtr pData);
// documentation pattern type ( implementation )
ConcreteType(HPat_T_IMP)
{
MAP(symbol,PT_Term) pPatTreeMap; // template trees
MAP(symbol,PT_Term) pPatMap; // patterns
MAP(symbol,ROW(symbol)) pListPatMap; // list patterns
MAP(symbol,PFN_Pat) pPatFunMap; // pattern reference |-->
// generation function
MAP(symbol,_) pFunDfnMap; // special pattern |--> special content
MAP(symbol,ROW(symbol)) pFunRefMap; // special patterns <--| apply reference
MAP(symbol,long) pPatTypMap; // pattern reference |--> type
SET(symbol) pRefIdSet; // referenced patterns
PLR_Tab pTab; // hpat parse table
Scn_T pScn; // hpat scanner
PT_Term pFirstTree; // first template tree
Abs_T pDocCtx; // documentation context
PFN_PatPrint pPrint; // print text function
symbol pRefAlias; // reference alias
};
// current pattern context
static HPat_T_IMP pCurHPat = (HPat_T_IMP)NULL;
// supported special pattern functions
static MAP(symbol,ROW(_)) pSpecialFunMap;
/*I-------------------------- Special Functions -------------------------- */
c_string HP_pat_to_txt(GLS_Lst(hpatContent) pLst)
/* template term list 'pLst' to string; allocs memory */
{ GLS_Lst(hpatContent) pItr, pPatLst;
Sink pSnk = Sink_open();
GLS_FORALL(pItr,pLst)
{ hpatContent pContent = GLS_FIRST(hpatContent,pItr);
GLS_Tok pOther, pPatRef, pPatHdr, pPatEnd;
if( hpatContent_else(pContent,&pOther) )
Sink_printf(pSnk,"%s",GLS_Tok_string(pOther));
else
if( hpatContent_pat(pContent,&pPatHdr,&pPatLst,&pPatEnd) )
{ c_string szPat;
Sink_printf(pSnk,"%s",GLS_Tok_string(pPatHdr));
szPat = HP_pat_to_txt(pPatLst);
Sink_printf(pSnk,"%s",szPat);
FreeMem(szPat);
Sink_printf(pSnk,"%s",GLS_Tok_string(pPatEnd));
}
else
if( hpatContent_ref(pContent,&pPatRef) )
Sink_printf(pSnk,"%s",GLS_Tok_string(pPatRef));
}
return Sink_close(pSnk);
}
static symbol HP_get_patid(GLS_Tok pPatHdr)
{ c_string szPatHdr = GLS_Tok_string(pPatHdr),
szS = szPatHdr, szId;
Sink pSnk = Sink_open();
symbol pId = (symbol)NULL;
while( *szS != '\0' && ! isspace(*szS) ) ++szS;
while( *szS != '\0' && isspace(*szS) ) ++szS;
while( *szS != '\0' && *szS != '>' && ! isspace(*szS) )
{
Sink_putc(pSnk,*szS); ++szS;
}
szId = Sink_close(pSnk);
pId = stringToSymbol(szId);
FreeMem(szId);
return pId;
}
static StdCPtr HP_load_fun_replace(GLS_Lst(hpatContent) pLst)
{ GLS_Lst(hpatContent) pItr, pPatLst;
MAP(symbol,symbol) pReplaceMap = MAP_newPrimMap();
ROW(symbol) pKeyRow = OT_CREATE_ADT(symbol),
pTxtRow = OT_CREATE_ADT(symbol);
long lCnt, lI;
GLS_FORALL(pItr,pLst)
{ hpatContent pContent = GLS_FIRST(hpatContent,pItr);
GLS_Tok pPatHdr;
if( hpatContent_pat(pContent,&pPatHdr,&pPatLst,_) )
{ c_string szTxt;
symbol pKey;
pKey = HP_get_patid(pPatHdr);
szTxt = HP_pat_to_txt(pPatLst);
OT_PUSH(pKey,pKeyRow);
OT_PUSH(stringToSymbol(szTxt),pTxtRow);
FreeMem(szTxt);
}
}
lCnt = OT_CNT(pKeyRow);
if( (lCnt % 2) == 0 )
{
for( lI=0; lI < lCnt; lI+=2 )
{
if( OT_GET(symbol,pKeyRow,lI) == OT_GET(symbol,pKeyRow,lI+1) )
{
MAP_dfndom
(
pReplaceMap,OT_GET(symbol,pTxtRow,lI),OT_GET(symbol,pTxtRow,lI+1)
);
}
else
{
MAP_freeMap(pReplaceMap);
pReplaceMap = (MAP(symbol,symbol))NULL;
break;
}
}
}
else
{
MAP_freeMap(pReplaceMap);
pReplaceMap = (MAP(symbol,symbol))NULL;
}
OT_DEL_T(pKeyRow);
OT_DEL_T(pTxtRow);
return pReplaceMap;
}
static c_string HP_apply_fun_replace(c_string szTxt, StdCPtr pData)
{
return Line_replace(szTxt,(MAP(symbol,symbol))pData);
}
static void HP_free_fun_replace(StdCPtr pData)
{
MAP_freeMap((MAP(symbol,symbol))pData);
}
/*I------------------------- Init & Quit -------------------------------- */
void HP_init(void)
/* initializes template evaluation module */
{ ROW(_) pFunRow = OT_CREATE_ADT(_);
hpat_initSymbols();
pSpecialFunMap = MAP_newPrimMap();
MAP_dfndom(pSpecialFunMap,stringToSymbol(HPAT_FUN_REPLACE),pFunRow);
OT_PUSH(HP_load_fun_replace,pFunRow);
OT_PUSH(HP_apply_fun_replace,pFunRow);
OT_PUSH(HP_free_fun_replace,pFunRow);
}
void HP_quit(void)
/* terminates template evaluation module */
{ MAPIT pItr;
symbol pPatSym;
ROW(_) pFunRow;
MAP_forItrAsg(pPatSym,pFunRow,pItr,pSpecialFunMap)
OT_DEL_T(pFunRow);
MAP_freeMap(pSpecialFunMap);
hpat_quitSymbols();
}
/*I------------------------- Create & Dispose --------------------------- */
HPat_T HP_create(void)
/* creates a template evaluation object */
{ HPat_T_IMP pHPat = New(HPat_T_IMP);
pHPat->pPatTreeMap = MAP_newPrimMap();
pHPat->pPatMap = MAP_newPrimMap();
pHPat->pListPatMap = MAP_newPrimMap();
pHPat->pPatFunMap = MAP_newPrimMap();
pHPat->pPatTypMap = MAP_newPrimMap();
pHPat->pRefIdSet = HS_CREATE_ADTSET(symbol);
pHPat->pFunDfnMap = MAP_newPrimMap();
pHPat->pFunRefMap = MAP_newPrimMap();
Scn_get_hpat(&pHPat->pScn);
pHPat->pTab = PLR_get_hpat();
pHPat->pFirstTree = (PT_Term)NULL;
pHPat->pDocCtx = (Abs_T)NULL;
pHPat->pPrint = (PFN_PatPrint)NULL;
pHPat->pRefAlias = (symbol)NULL;
return (HPat_T)pHPat;
}
void HP_drop(HPat_T pHP)
/* frees template evaluation object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
MAPIT pItr;
PT_Term pTree;
ROW(symbol) pRow;
symbol pSym;
StdCPtr pData;
MAP_forItrAsg(pSym,pTree,pItr,pHPat->pPatTreeMap)
{
if( pTree != (PT_Term)NULL ) PT_delT(pTree);
}
MAP_freeMap(pHPat->pPatTreeMap);
MAP_freeMap(pHPat->pPatMap);
MAP_forItrAsg(pSym,pRow,pItr,pHPat->pListPatMap) OT_DEL_T(pRow);
MAP_freeMap(pHPat->pListPatMap);
MAP_freeMap(pHPat->pPatFunMap);
MAP_freeMap(pHPat->pPatTypMap);
HS_DROP_SET(pHPat->pRefIdSet);
MAP_forItrAsg(pSym,pData,pItr,pHPat->pFunDfnMap)
{ PFN_PatFree pPatFree;
pPatFree = OT_GET(PFN_PatFree,MAP_apply(ROW(_),pSpecialFunMap,pSym),2);
(*pPatFree)(pData);
}
MAP_freeMap(pHPat->pFunDfnMap);
MAP_forItrAsg(pSym,pRow,pItr,pHPat->pFunRefMap) OT_DEL_T(pRow);
MAP_freeMap(pHPat->pFunRefMap);
if( pHPat->pScn != (Scn_T)NULL ) Scn_free(pHPat->pScn);
PLR_delTab(pHPat->pTab);
FreeMem(pHPat);
}
/*I------------------------- Get & Set ---------------------------------- */
void HP_setContext(HPat_T pHP, Abs_T pDocCtx)
/* sets evaluation context 'pDocCtx' in template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
pHPat->pDocCtx = pDocCtx;
}
Abs_T HP_getContext(HPat_T pHP)
/* evaluation context of template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
return pHPat->pDocCtx;
}
void HP_setPrintFun(HPat_T pHP, PFN_PatPrint pPrint)
/* sets print function 'pPrint' in template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
pHPat->pPrint = pPrint;
}
PFN_PatPrint HP_getPrintFun(HPat_T pHP)
/* print function of template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
return pHPat->pPrint;
}
void HP_setRefAlias(HPat_T pHP, symbol pRefAlias)
/* sets reference alias 'pRefAlias' in template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
pHPat->pRefAlias = pRefAlias;
}
symbol HP_getRefAlias(HPat_T pHP)
/* reference alias of template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
return pHPat->pRefAlias;
}
void HP_addPatSpec
(
HPat_T pHP, symbol pPat, PFN_Pat pPatFun, long lPatTyp
)
/* adds/overwrites evaluation function 'pPatFun'
for pattern 'pPat' of type 'lPatTyp'
to template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
MAP_ovrdom(pHPat->pPatFunMap,pPat,pPatFun);
MAP_ovrdom(pHPat->pPatTypMap,pPat,lPatTyp);
}
PFN_Pat HP_getPatFun(HPat_T pHP, symbol pPat)
/* evaluation function for pattern 'pPat'
in template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
if( MAP_defined(pHPat->pPatFunMap,pPat) )
return MAP_apply(PFN_Pat,pHPat->pPatFunMap,pPat);
else return (PFN_Pat)NULL;
}
ROW(symbol) HP_getListPatRow(HPat_T pHP, symbol pListPat)
/* member patterns of pattern list 'pListPat'
in template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
if( MAP_defined(pHPat->pListPatMap,pListPat) )
return MAP_apply(ROW(symbol),pHPat->pListPatMap,pListPat);
else return (ROW(symbol))NULL;
}
void HP_setScanner(HPat_T pHP, Scn_T pScn)
/* sets external scanner 'pScn' in template object 'pHP'
( will be removed by HP_drop )
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
if( pHPat->pScn != (Scn_T)NULL ) Scn_free(pHPat->pScn);
pHPat->pScn = pScn;
}
Scn_T HP_getScanner(HPat_T pHP)
/* pattern scanner of template object 'pHP' */
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
return pHPat->pScn;
}
symbol HP_getPatRef(GLS_Tok pPatRef)
/* symbol of pattern refernce token 'pPatRef' */
{ c_string szPatRef = StrCopy(GLS_Tok_string(pPatRef)+1);
symbol pResult;
szPatRef[strlen(szPatRef)-1] = '\0';
pResult = stringToSymbol(szPatRef);
FreeMem(szPatRef);
return pResult;
}
c_bool HP_addSpecialFun
(
symbol pPatSym,
PFN_PatLoad pPatLoad,
PFN_PatOpr pPatOpr,
PFN_PatFree pPatFree
)
/* adds special evaluation functions for
replacement specification pattern 'pPatSym'
'pPatLoad': loads replacement specification
'pPatOpr' : applies replacement specification
'pPatFree': frees replacement specification
( RC = ok/error )
*/
{
if( ! MAP_defined(pSpecialFunMap,pPatSym) )
{ ROW(_) pFunRow = OT_CREATE_ADT(_);
MAP_dfndom(pSpecialFunMap,pPatSym,pFunRow);
OT_PUSH(pPatLoad,pFunRow);
OT_PUSH(pPatOpr,pFunRow);
OT_PUSH(pPatFree,pFunRow);
return C_True;
}
else return C_False;
}
/*I------------------------- Load & Check ------------------------------- */
static symbol HP_add_pat(HPat_T_IMP pHPat, hpatContent pContent)
/* add template pattern */
{ GLS_Tok pPatHdr;
symbol pFunSym = (symbol)NULL;
if( hpatContent_pat(pContent,&pPatHdr,_,_) )
{ c_string szPatHdr = GLS_Tok_string(pPatHdr),
szS = szPatHdr, szId;
Sink pSnk = Sink_open();
symbol pId, pPatId;
while( *szS != '\0' && ! isspace(*szS) ) ++szS;
while( *szS != '\0' && isspace(*szS) ) ++szS;
while( *szS != '\0' && *szS != '>' && ! isspace(*szS) )
{
Sink_putc(pSnk,*szS); ++szS;
}
szId = Sink_close(pSnk);
pId = stringToSymbol(szId);
FreeMem(szId);
if( ! MAP_defined(pHPat->pPatMap,pId) &&
! MAP_defined(pHPat->pFunDfnMap,pId) )
{
if( MAP_defined(pSpecialFunMap,pId) )
pFunSym = pId;
else MAP_dfndom(pHPat->pPatMap,pId,pContent);
while( *szS != '\0' && isspace(*szS) ) ++szS;
if( *szS != '>' )
{ ROW(symbol) pPatIdRow = (ROW(symbol))NULL;
if( pFunSym == (symbol)NULL )
{
pPatIdRow = OT_CREATE_ADT(symbol);
MAP_dfndom(pHPat->pListPatMap,pId,pPatIdRow);
}
while( *szS != '\0' && *szS != '>' )
{
pSnk = Sink_open();
while( *szS != '\0' && *szS != '>' && ! isspace(*szS) )
{
Sink_putc(pSnk,*szS); ++szS;
}
szId = Sink_close(pSnk);
pPatId = stringToSymbol(szId);
FreeMem(szId);
if( pFunSym == (symbol)NULL )
OT_PUSH(pPatId,pPatIdRow);
else
{ ROW(symbol) pRefRow;
if( MAP_defined(pHPat->pFunRefMap,pPatId) )
pRefRow = MAP_apply(ROW(symbol),pHPat->pFunRefMap,pPatId);
else
{
pRefRow = OT_CREATE_ADT(symbol);
MAP_dfndom(pHPat->pFunRefMap,pPatId,pRefRow);
}
OT_PUSH(pId,pRefRow);
}
while( *szS != '\0' && isspace(*szS) ) ++szS;
}
}
}
else PT_error(pPatHdr,"pattern '%s' already defined",symbolToString(pId));
}
return pFunSym;
}
static void HP_load_content
(
HPat_T_IMP pHPat, GLS_Lst(hpatContent) pLst, c_bool bRecursive
)
/* load pattern content */
{ GLS_Lst(hpatContent) pItr, pPatLst;
GLS_FORALL(pItr,pLst)
{ hpatContent pContent = GLS_FIRST(hpatContent,pItr);
GLS_Tok pPatRef;
if( hpatContent_pat(pContent,_,&pPatLst,_) )
{ symbol pFunSym = HP_add_pat(pHPat,pContent);
if( pFunSym != (symbol)NULL )
{ PFN_PatLoad pPatLoad;
StdCPtr pData;
pPatLoad = OT_GET
(
PFN_PatLoad,MAP_apply(ROW(_),pSpecialFunMap,pFunSym),0
);
pData = (*pPatLoad)(pPatLst);
if( pData != (StdCPtr)NULL )
{
MAP_dfndom(pHPat->pFunDfnMap,pFunSym,pData);
}
else
{
PT_error
(
pContent,"load of pattern '%s' failed",symbolToString(pFunSym)
);
}
}
else
if( bRecursive ) HP_load_content(pHPat,pPatLst,bRecursive);
}
else
if( hpatContent_ref(pContent,&pPatRef) )
{ symbol pRefId = HP_getPatRef(pPatRef);
if( MAP_defined(pHPat->pPatFunMap,pRefId) &&
MAP_defined(pHPat->pPatTypMap,pRefId) &&
MAP_apply(long,pHPat->pPatTypMap,pRefId) != HPAT_REF_PAR )
HS_SET_ELM(pRefId,pHPat->pRefIdSet);
}
}
}
static int HP_premac
(
Scn_Stream pStream, string cTokNam, string cTokVal, symbol* cMacVal
)
/* pre-process token */
{ symbol pValSym = stringToSymbol(cTokVal);
if( !strcmp(cTokNam,HPAT_TOK_PATREF) && pCurHPat->pRefAlias == pValSym )
{
*cMacVal = (symbol)HPAT_PREFIX_PATREF;
return SCN_FLG_RescanChar;
}
else
{
*cMacVal = pValSym;
return SCN_FLG_RescanNone;
}
}
c_bool HP_load
(
HPat_T pHP, Scn_Stream pStream, symbol pSrcId,
symbol pRootPat, c_bool bRecursive
)
/* loads template pattern from scan stream 'pStream'
into template object 'pHP'
'pSrcId' : optional source identifier
'pRootPat' : root pattern for evaluation
'bRecursive': recursive evaluation
( RC = ok/error )
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
PT_Cfg pCfg;
PT_Term pTree;
symbol pStreamId;
pStreamId = Stream_cfil(pStream);
if( pHPat->pRefAlias != (symbol)NULL )
{
pCurHPat = pHPat;
Stream_premac_set(pStream, HP_premac);
}
Stream_concat_other(pStream);
pCfg = PT_init(pHPat->pTab,pStream);
pTree = PT_PARSE(pCfg,"");
if( pHPat->pRefAlias != (symbol)NULL )
pCurHPat = (HPat_T_IMP)NULL;
PT_setErrorCnt(PT_errorCnt() + PT_synErrorCnt(pCfg));
PT_quit(pCfg);
Stream_close(pStream);
Stream_free(pStream);
if( pSrcId != (symbol)NULL )
MAP_dfndom(pHPat->pPatTreeMap,pSrcId,pTree);
else MAP_dfndom(pHPat->pPatTreeMap,pStreamId,pTree);
if( PT_errorCnt() == 0 )
{ GLS_Lst(hpatContent) pLst;
hpatHPatDoc pSrc;
if( pHPat->pFirstTree == (PT_Term)NULL )
pHPat->pFirstTree = pTree;
hpat_Start_HPatDoc(pTree,&pSrc);
hpatHPatDoc_dfn(pSrc,&pLst);
HP_load_content(pHPat,pLst,bRecursive);
if( pRootPat != (symbol)NULL )
{
if( MAP_defined(pHPat->pPatFunMap,pRootPat) &&
MAP_defined(pHPat->pPatTypMap,pRootPat) &&
MAP_apply(long,pHPat->pPatTypMap,pRootPat) != HPAT_REF_PAR )
HS_SET_ELM(pRootPat,pHPat->pRefIdSet);
else PT_error(pTree,"root pattern '%s'",symbolToString(pRootPat));
}
}
return PT_errorCnt() == 0;
}
c_bool HP_check(HPat_T pHP)
/* checks loaded template pattern in template object 'pHP'
( RC = ok/error )
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
HS_Itr pSItr;
MAPIT pMItr;
ROW(symbol) pRow;
PT_Term pTree;
symbol pPatId, pRefId;
MAP_forItrAsg(pPatId,pRow,pMItr,pHPat->pListPatMap)
{ long lCnt = OT_CNT(pRow), lI;
for( lI=0; lI < lCnt; ++lI )
{
pRefId = OT_GET(symbol,pRow,lI);
if( ! MAP_defined(pHPat->pPatMap,pRefId) )
{
pTree = MAP_apply(PT_Term,pHPat->pPatMap,pPatId);
PT_error(pTree,"missing pattern '%s'",symbolToString(pRefId));
}
}
}
HS_FORALL(pRefId,pSItr,pHPat->pRefIdSet)
{ long lPatTyp = MAP_apply(long,pHPat->pPatTypMap,pRefId);
if( lPatTyp == HPAT_REF_LIST && ! MAP_defined(pHPat->pListPatMap,pRefId) )
PT_error
(
pHPat->pFirstTree,"missing list pattern '%s'",symbolToString(pRefId)
);
else
if( lPatTyp == HPAT_REF_PAT && ! MAP_defined(pHPat->pPatMap,pRefId) )
PT_error(pHPat->pFirstTree,"missing pattern '%s'",symbolToString(pRefId));
}
return PT_errorCnt() == 0;
}
/*I------------------------- Output Generation -------------------------- */
/*forward*/ void HP_gendoc_pat(HPat_T pHP, symbol pPatSym);
void HP_gendoc_ref(HPat_T pHP, GLS_Tok pPatRef)
/* evaluates and prints reference token 'pPatRef'
according template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
symbol pRefSym = HP_getPatRef(pPatRef);
if( MAP_defined(pHPat->pPatFunMap,pRefSym) )
{ PFN_Pat pPatFun = MAP_apply(PFN_Pat,pHPat->pPatFunMap,pRefSym);
if( ! (*pPatFun)(pHP) )
PT_error(pPatRef,"misplaced reference '%s'",symbolToString(pRefSym));
}
else
if( MAP_defined(pHPat->pPatMap,pRefSym) &&
! MAP_defined(pHPat->pListPatMap,pRefSym) )
HP_gendoc_pat(pHP,pRefSym);
else
if( pHPat->pPrint != (PFN_PatPrint)NULL )
(*pHPat->pPrint)(pHP,GLS_Tok_string(pPatRef));
}
static void HP_gendoc_content(HPat_T_IMP pHPat, GLS_Lst(hpatContent) pLst)
/* generate content */
{ hpatContent pTxt;
GLS_Lst(hpatContent) pSubLst, pItr;
GLS_FORALL(pItr,pLst)
{ GLS_Tok pPatRef, pPatHdr, pPatEnd, pOther;
pTxt = GLS_FIRST(hpatContent,pItr);
if( hpatContent_ref(pTxt,&pPatRef) )
HP_gendoc_ref(pHPat,pPatRef);
else
if( hpatContent_else(pTxt,&pOther) && pHPat->pPrint != (PFN_PatPrint)NULL )
(*pHPat->pPrint)(pHPat,GLS_Tok_string(pOther));
else
if( hpatContent_pat(pTxt,&pPatHdr,&pSubLst,&pPatEnd) )
{
if( pHPat->pPrint != (PFN_PatPrint)NULL )
(*pHPat->pPrint)(pHPat,GLS_Tok_string(pPatHdr));
HP_gendoc_content(pHPat,pSubLst);
if( pHPat->pPrint != (PFN_PatPrint)NULL )
(*pHPat->pPrint)(pHPat,GLS_Tok_string(pPatEnd));
}
}
}
c_bool HP_fun_defined(HPat_T pHP, symbol pRefSym)
/* whether template object 'pHP' contains a
replacement specification for pattern 'pRefSym'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
return MAP_defined(pHPat->pFunRefMap,pRefSym);
}
c_string HP_fun_apply(HPat_T pHP, symbol pRefSym, c_string szTxt)
/* applies the replacement specification for pattern 'pRefSym'
in template object 'pHP' to text 'szText'
RC = szTxt, if no functions defined, else result text
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
c_string szRes = szTxt, szTmp;
if( MAP_defined(pHPat->pFunRefMap,pRefSym) )
{ ROW(symbol) pFunRow = MAP_apply(ROW(symbol),pHPat->pFunRefMap,pRefSym);
long lCnt = OT_CNT(pFunRow), lI;
for( lI=0; lI < lCnt; ++lI )
{ symbol pPatSym = OT_GET(symbol,pFunRow,lI);
PFN_PatOpr pPatOpr;
pPatOpr = OT_GET(PFN_PatOpr,MAP_apply(ROW(_),pSpecialFunMap,pPatSym),1);
szTmp = (*pPatOpr)(szRes,MAP_apply(StdCPtr,pHPat->pFunDfnMap,pPatSym));
if( szRes != szTxt ) FreeMem(szRes);
szRes = szTmp;
}
}
return szRes;
}
void HP_gendoc_pat(HPat_T pHP, symbol pPatSym)
/* evaluates and prints pattern 'pPatSym'
according template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
if( MAP_defined(pHPat->pPatMap,pPatSym) )
{ hpatContent pPat = MAP_apply(hpatContent,pHPat->pPatMap,pPatSym);
GLS_Lst(hpatContent) pLst;
assert0(hpatContent_pat(pPat,_,&pLst,_), "");
HP_gendoc_content(pHPat,pLst);
}
}
void HP_gendoc_src(HPat_T pHP, symbol pSrcId)
/* evaluates and prints template 'pSrcId'
according template object 'pHP'
*/
{ HPat_T_IMP pHPat = (HPat_T_IMP)pHP;
if( MAP_defined(pHPat->pPatTreeMap,pSrcId) )
{ PT_Term pTree = MAP_apply(PT_Term,pHPat->pPatTreeMap,pSrcId);
hpatHPatDoc pSrc;
GLS_Lst(hpatContent) pLst;
hpat_Start_HPatDoc(pTree,&pSrc);
hpatHPatDoc_dfn(pSrc,&pLst);
HP_gendoc_content(pHPat,pLst);
}
}
styx-2.0.1/libutil/dict.c 0000666 0001750 0001750 00000016534 07440772216 012223 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [dict.c] Type: Dictionary */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "standard.h"
#include "pathes.h"
/*!!
[dict] provides platform-independant access to directories and their entries.
Supported platforms are Unix and Windows.
*/
/* ---------------- Common Types, Constants & Globals --------------------- */
/*I---------------------- Types ------------------------------------------- */
AbstractType(Dir); /* Abstract directory type */
AbstractType(Dentry); /* Abstract directory entry type */
#define DICT_D_IMP(d) ((Dir_IMP)(d))
#define DICT_E_IMP(e) ((Dir_IMP)(e))
/*INTERFACE_OFF*/
/* ---------------------- Types and Constants ----------------------------- */
#if defined( _MSDOS ) && ! defined( _WIN32 )
#include 'pim_test' parses the given source file and lists the derivation tree on stdout.
The source file must be conform with the language parameter. It uses the image files
of the parser and scanner tables, [Language.lim] and [Language.pim].
In case you specify a start symbol the parsing process starts from this nonterminal,
provided it is defined in [Language.sty].
By default the parser takes the first start nonterminal.
cod
Arguments
#include pgm_arg.inc
Options
#include pgm_sopt.inc
#include pgm_popt.inc
tree : flag = true -- create a derivation tree
#include pgm_odoc.inc
Environment
BINSTYX : path = "PATH" -- search environment for [Language.pim] and [Language.lim]
styx-2.0.1/pgm/pgm_odoc.inc 0000666 0001750 0001750 00000002234 07600567367 012534 0000000 0000000
doc
The options 'prepar' and 'premac' are only useful with styx-like preprocessing.
If your language uses the same preprocessing directives as specified in [styx.sty],
but differnt macro token identifiers and keywords, the option 'prepar' can be used to
enable preprocessing and specify the differences as a comma separated list:
The option 'premac' supports pre-defined macros in connection with
styx-like preprocessing.
Dynamic library support is a prerequisite for the user-defined callback handler.
cod
styx-2.0.1/pgm/lim_test.cmd 0000666 0001750 0001750 00000001304 10373405111 012527 0000000 0000000 # [lim_test.cmd] command description for lim_test.c
Program lim_test -- Scanner test program
doc
'lim_test' scans the given source file and lists the tokens on stdout.
The source file must be conform with the language parameter. It uses the image file
of the scanner table [Language.lim].
The current version doesn't support the embedded language facility.
cod
Arguments
#include pgm_arg.inc
Options
#include pgm_sopt.inc
tokens : flag = true -- create list of all scanned tokens
symbols : flag = false -- create list of all symbols in the internal symbol table
#include pgm_odoc.inc
Environment
BINSTYX : path = "PATH" -- search environment for [Language.lim]
styx-2.0.1/pgm/stydoc.cmd 0000666 0001750 0001750 00000002355 10373405111 012223 0000000 0000000 # [stydoc.cmd] command description for stydoc.c
Program stydoc -- STYX Documentation Generator
doc
'stydoc' produces a HTML-like reference documentation for a STYX grammar [.sty].
Comments not starting with ';;' will also be included.
cod
Arguments
InFile : path -- path of the STYX grammar [.sty]
Template : path -- path of the template file (eg. tstydoc_us.htm)
doc
The target file 'OutFile' should contain the language name so that
embedded languages can be referenced, too.
cod
Options
OutFile : path = "" -- path of the target file (default: stdout)
StyxPath : path = "." -- path of STYX grammar include files
RefAlias : string = "&" -- alias for the first character of a pattern reference
recursiv : flag = false -- recursive pattern evaluation
prodcom : flag = false -- print production comments
keepNTs : string = "" -- NTs which shouldn't be expanded ( NT ; ... )
noClass : string = "" -- split NT Classes ( NT ; ... )
exProds : string = "" -- hide NT Productions ( NT . Prod ; ... )
ignRRef : string = "" -- ignore recursive references ( NT ; ... )
Environment
BINSTYX : path = "PATH" -- search environment for the parse table image [.pim]
styx-2.0.1/pgm/pim_test.c 0000666 0001750 0001750 00000004213 10161654703 012224 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [pim_test.c] Parser Test */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "pgm_base.h"
#include "pgm_sopt.h"
#include "pgm_popt.h"
#include "pim__cim.h"
#define language CTX_EVAL(string,"Language")
#define filename CTX_EVAL(string,"FileName")
#define binmode CTX_EVAL(bool,"binmode")
#define tree CTX_EVAL(bool,"tree")
#define binpath CTX_EVAL(string,"BINSTYX")
int main(int argc, string argv[])
{ PLR_Tab PTab; Scn_T Scn; Scn_Stream cStream;
PT_Cfg PCfg; PT_Term PTree;
/* init module */
PGM_init(argc,argv,CTX_init_pim_test);
/* init pre-processing */
PGM_initPreprocessing(prepar,premac,cset);
/* create & init scan & parse tables */
PGM_initTables(binpath,language,&PTab,&Scn);
/* create & init scan stream */
cStream = PGM_initScanStream
(
Scn,filename,prepar,prefun,binmode,cset,
skipset,CTX_EVAL(bool,"lookahead"),False
);
/* init parse configuration */
PCfg = PGM_initParsing(cStream,PTab);
/* parse and construct tree */
/* early --> print tree */
PTree = PGM_parse(PCfg,start,shiftfun,reducefun,early,xaron);
if( early )
{
while( PTree != (PT_Term)NULL )
{
if( tree ) PGM_printTree(PTree,cset,wprint);
PT_delT(PTree);
PTree = PGM_parse(PCfg,start,shiftfun,reducefun,early,xaron);
}
}
/* quit parse configuration */
PT_quit(PCfg);
/* print derivation tree */
if( tree ) PGM_printTree(PTree,cset,wprint);
/* release derivation tree */
if( PTree != (PT_Term)NULL ) PT_delT(PTree);
/* release scan stream, scan & parse tables */
PGM_quitScanStream(cStream);
PGM_quitTables(PTab,Scn);
/* quit preprocessing */
PGM_quitPreprocessing(prepar);
/* quit module */
PGM_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/styx.cmd 0000666 0001750 0001750 00000006135 10373405111 011725 0000000 0000000 # [styx.cmd] command description for [styx.c]
Program styx -- A combined parser and scanner generator
doc
'styx' translates the token and syntax description for a language in [$SPESTYX/Language.sty]
into scanner and parser tables and a functional interface to the abstract derivation tree.
The generated tables have to be applied to the actual scanner and parser function which are part of the
styx library. The result of the parser function will be a derivation tree which can be accessed through
the above mentioned interface.
cod
Arguments
Language : name -- language name
Options
diagnose : flag = false -- additional diagnose and information
verbose : flag = false -- progress information
conflicts : flag = true -- prevent parse table generation in case of conflicts
makeIMG : flag = false -- create binary table images
makeINT : flag = false -- create interface c source
makeANT : flag = false -- create abstract interface c source
makeC : flag = false -- create table c sources
export : flag = false -- export table definitions
exportTMPL: string = "" -- export template file
shortform : flag = false -- use short form of language name
doc
Dependant on the given options different source and image files will be created:
");
t = dline + 3 + pretag;
while ( t < t1 )
{
fprintf(SysDoc,"%c",*t); ++t;
}
}
else
{
snk = Sink_open();
if( pretag )
Sink_printf(snk," %s\n",dline+3);
comblk = True;
}
FreeMem(dline);
}
else
if( beginswith("#ifndef") && strstr(line,"_INCL") != (string)NULL )
/* skip */;
else
if( beginswith("#define") && strstr(line,"_INCL") != (string)NULL )
/* skip */;
else
if( strstr(line,"/*_INCL*/") != (string)NULL ||
strstr(line,"//_INCL") != (string)NULL )
/* skip */;
else
if( beginswith("/* -") || beginswith("/* =") ||
beginswith("#include") || beginswith("AbstractType") )
{
dline = replaceDocBlock(line);
writeDocBlock(SysDoc, dline, True);
FreeMem(dline);
}
else
{
dline = replaceDocBlock(line);
fprintf(SysDoc," 'ctoh' creates the corresponding header files for all given c source files
which represent modules, i.e. don't contain the function 'main'.
The lines below show the general structure of the generated header files:
The header file will only be produced if there are differences to the previous one.
Within each c modul there may be certain groups of lines, called blocks,
which belong to the interface. If nothing else is mentioned each interface block starts
with a word and is followed either by an empty line or the curly bracket '{' at line position 0
which both marks the end of the block. In the interface copy the curly bracket '{' is replaced
by a semicolon ';'. The body within the curly brackets and the curly bracket '}' will be skipped.
Function definition block The basic idea is that a function definition block starts with a word that
is not marked as non-function or non-interface related, i.e. the result type name.
The header definition ends with the first empty line or the curly bracket '{' at
line position 0. The latter will be replaced with a semicolon ';' in the copy for the interface.
The function body will be skipped.
Non-interface related block Blocks whose first Line start with on of the following words don't belong to the interface
and will be skipped:
'static', 'ConcreteType', 'ConcreteImp', 'struct', 'union' und 'typedef', 'inline',
'class', 'template'
Beside that a member function definition block, recognized by the pattern 'name::name'
will be skipped.
C source file header block The first block will allways be copied. Within this block the suffix of the file name
will be patched from '.c' to '.h'.
Include block The first block whose lines starts with an #include-directive will be copied. In order
to copy the necessary #include-directives they must be places first in the c source file,
separated by an empty line from the rest.
Comment block Comment lines starting with '/*I-' or '/*I=' are interface-related and thus copied. The
Character 'I' will be replaced with a space character. Further comment blocks starting with '/*!'
will be copied.
Explicit interface block ( 1 ) '/*DOC_INTERFACE*/' is a second variant which in addition copies the block to the [.htm]
documentation file if the option 'DPATH' is given.
Explicit interface block ( 2 ) Alternative '/*DOC_INTERFACE_COPY_ON*/' and '/*DOC_INTERFACE_COPY_OFF*/' can be used for
additional documentation purposes.
Explicit interface-only block Documentation block A documentation block is non-interface related and will be skipped.
Therefore the macro name
can't be defined in another context.
Interface layout Blocks where the first line starts with a letter and ends with ')'
and the second line starts with '/*' or '{' will be recognized as function
definitions and layouted in one line.
The comment line '/*INTERFACE_GROUP*/' produces an empty line.
Starting point of the Signature Generall the signature starts after the first include-block or before
the first function definition. The comment line '/*INTERFACE_LINKAGE_ON*/
forces the creation of the opening linkage block.
The options '-exp' and '-api' are not used in a linux environment.
cod
Environment
styx-2.0.1/pgm/stydoc.c 0000666 0001750 0001750 00000173301 12116733136 011712 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [stydoc.c] STYX Documentation Generator */
/* */
/* Copyright (c) 1999 by D\olle, Manns, Steffen */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "scn_base.h"
#include "scn_pre.h"
#include "prs.h"
#include "ptm.h"
#include "ptm_gen.h"
#include "cfg_abs.h"
#include "symbols.h"
#include "hmap.h"
#include "hset.h"
#include "sink.h"
#include "line_scn.h"
#include "pathes.h"
#include "hpat.h"
#include "styx_int.h"
#include "styx_lim.h"
#include "styx_pim.h"
#include "styd_cim.h"
/* ------------------------- Macros, Types & Globals ---------------------- */
#define infile CTX_EVAL(c_string,"InFile")
#define outfile CTX_EVAL(c_string,"OutFile")
#define styxpath CTX_EVAL(c_string,"StyxPath")
#define template CTX_EVAL(c_string,"Template")
#define refalias CTX_EVAL(c_string,"RefAlias")
#define recursiv CTX_EVAL(c_bool,"recursiv")
#define prodcom CTX_EVAL(c_bool,"prodcom")
#define nts_to_keep CTX_EVAL(c_string,"keepNTs")
#define cls_to_split CTX_EVAL(c_string,"noClass")
#define excl_prods CTX_EVAL(c_string,"exProds")
#define ign_rref CTX_EVAL(c_string,"ignRRef")
#define binpath CTX_EVAL(string,"BINSTYX")
/* STYX Documentation Pattern */
#define SD_PAT_CFGDFN stringToSymbol("cfgdfn")
#define SD_PAT_COMSEC stringToSymbol("comsec")
#define SD_PAT_TKMSEC stringToSymbol("tkmsec")
#define SD_PAT_NTMSEC stringToSymbol("ntmsec")
#define SD_PAT_PRDSEC stringToSymbol("prdsec")
#define SD_PAT_MBRSEC stringToSymbol("mbrsec")
#define SD_PAT_CFGID stringToSymbol("cfgid")
#define SD_PAT_DFNID stringToSymbol("dfnid")
#define SD_PAT_DFNREF stringToSymbol("dfnref")
#define SD_PAT_LANREF stringToSymbol("lanref")
#define SD_PAT_DFNCAT stringToSymbol("dfncat")
#define SD_PAT_DFNOPT stringToSymbol("dfnopt")
#define SD_PAT_MBRID stringToSymbol("mbrid")
#define SD_PAT_DFNCOM stringToSymbol("dfncom")
#define SD_PAT_GRPCOM stringToSymbol("grpcom")
#define SD_PAT_BOTCOM stringToSymbol("botcom")
#define SD_PAT_OPTCOM stringToSymbol("optgrpcom")
#define SD_PAT_NEWLINE stringToSymbol("nl")
ConcreteType(StyDoc_T)
{
PT_Term pTree; // STYX derivation tree of 'infile'
MAP(symbol,ROW(PT_Term)) pDfnCom; // comments of token, nonterminal
// and production definitions
MAP(symbol,ROW(PT_Term)) pGrpCom; // post definition --> group comments
PLR_Tab pTab; // language parse table
int* aPol; // nonterminal/class types
SET(int)* aNtm; // nonterminal partition
SET(int)* aPrd; // nonterminal productions
MAP(symbol,styxQlxDfn) pGMap; // group symbol |--> definition
MAP(symbol,styxQlxDfn) pTMap; // token symbol |--> definition
MAP(symbol,long) pNTMap; // nonterminal symbol |--> index
MAP(symbol,symbol) pClsMap; // nonterminal symbol |--> class symbol
SET(symbol) pLSet; // embedded languages
ROW(_) pDocBase; // language documentation base:
// ROW( T/NT symbol,
// ROW(ROW(T/NTGroup/Value symbol)) )
HPat_T pHPat; // template pattern
// generation context
FILE* pSysOut; // output fp
long lDocIdx; // 0 .. pDocBase.Count/2-1 oder -1
long lMbrIdx; // 0 .. pDocBase.pCurRow.Count-1 or -1
long lComIdx; // current start index into comment row
ROW(symbol) pCurRow; // 0 .. pDocBase.lDocIdx.Count-1 or -1
};
static SET(symbol) pNTsToKeep;
static SET(symbol) pClsToSplit;
static SET(symbol) pIgnRecRef;
static MAP(symbol,SET(symbol)) pExcludedProds;
static c_bool bConcreteCfg = C_False;
/* ------------------------- Auxiliary ------------------------------------ */
static c_string SD_com_string
(
ROW(PT_Term) pComments, long* lIdx
)
/* comment token --> string */
{ c_string szResult = (string)NULL;
long lCnt = OT_CNT(pComments), lDiff, lI = *lIdx;
Sink pSnk = Sink_open();
for( ; *lIdx < lCnt; ++(*lIdx) )
{ PT_Term t = OT_GET(PT_Term,pComments,*lIdx), p;
if( !PT_isComment(t) )
{
++(*lIdx); break;
}
else
{
if( *lIdx > lI )
{
p = OT_GET(PT_Term,pComments,(*lIdx)-1);
lDiff = PT_row(t) - PT_row(p);
if( lDiff >= 2 )
Sink_printf(pSnk,"\n\n");
else
if( lDiff == 1 )
Sink_printf(pSnk,"\n");
}
Sink_printf(pSnk,"\n%s",GLS_Tok_string(t)+1);
}
}
szResult = Sink_close(pSnk);
return szResult;
}
static long SD_getIgnNTIdx(long lPrdIdx, StyDoc_T pStyDoc)
{ long lMbrCnt, lSym, lTyp, lI;
lMbrCnt = PLR_prodSymCnt(pStyDoc->pTab,lPrdIdx);
for( lI=0; lI < lMbrCnt; ++lI )
{
lSym = PLR_prodSymbol(pStyDoc->pTab,lPrdIdx,lI);
lTyp = PLR_symType(pStyDoc->pTab,lSym);
if( CFG_NTM(lTyp) ) return lSym - PLR_tokenCnt(pStyDoc->pTab);
}
C_BUG; return -1;
}
static c_bool SD_IsLLProd(long lPrdIdx, StyDoc_T pStyDoc)
{ long lTCnt = PLR_tokenCnt(pStyDoc->pTab),
lNTIdx = PLR_prodNonTerm(pStyDoc->pTab,lPrdIdx);
return( lNTIdx == PLR_prodSymbol(pStyDoc->pTab,lPrdIdx,0) - lTCnt );
}
static c_bool SD_IsNTUnion(ROW(symbol) pNTLine)
{ long lCnt = OT_CNT(pNTLine), lI;
for( lI=0; lI < lCnt; ++lI )
{ c_string szSymbol = symbolToString(OT_GET(symbol,pNTLine,lI));
if( ! strcmp(szSymbol,"\"|\"") ) return C_True;
}
return C_False;
}
static bool SD_IsNTRecRef(long lNTIdx, StyDoc_T pStyDoc)
{ long lClsIdx = PLR_ntClassId(pStyDoc->pTab,lNTIdx),
lSym = lNTIdx + PLR_tokenCnt(pStyDoc->pTab),
lClsSym = lClsIdx + PLR_tokenCnt(pStyDoc->pTab);
c_string szSym = PLR_symName(pStyDoc->pTab,lSym),
szClsSym = PLR_symName(pStyDoc->pTab,lClsSym);
symbol pSym = stringToSymbol(szSym),
pClsSym = stringToSymbol(szClsSym);
return ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_RECREF) &&
! HS_MBR_ELM(pSym,pIgnRecRef) &&
! HS_MBR_ELM(pClsSym,pIgnRecRef);
}
static c_bool SD_IsNTSequence(ROW(symbol) pNTLine)
{ long lCnt = OT_CNT(pNTLine);
if( lCnt > 1 )
{ c_string szSymbol = symbolToString(OT_GET(symbol,pNTLine,0));
if( ( ! strncmp(szSymbol,"\"(\"",3) ||
! strncmp(szSymbol,"\"{\"",3) ||
! strncmp(szSymbol,"\"[\"",3) ) &&
( atol(szSymbol+3) + 2 == lCnt ||
( atol(szSymbol+3) + 2 == lCnt - 1 &&
!strcmp(symbolToString(OT_GET(symbol,pNTLine,lCnt-1)),"\"+\"") ) ) )
return C_True;
else
if( lCnt == 2 &&
! strcmp(symbolToString(OT_GET(symbol,pNTLine,1)),"\"+\"") )
return C_True;
return C_False;
}
else return C_True;
}
static ROW(symbol) SD_rowToNTSeq
(
c_bool bCond, c_string szSeq,
ROW(symbol) pDstRow, ROW(symbol) pSrcRow
)
{ ROW(symbol) pResRow = pDstRow;
if( bCond )
{ c_string szSym;
if( pDstRow == pSrcRow ) pResRow = OT_CREATE_ADT(symbol);
szSym = Str_printf("\"%c\"%ld",szSeq[0],OT_CNT(pSrcRow));
OT_PUSH(stringToSymbol(szSym),pResRow);
FreeMem(szSym);
OT_APPEND(pResRow,pSrcRow);
szSym = Str_printf("\"%c\"",szSeq[1]);
OT_PUSH(stringToSymbol(szSym),pResRow);
FreeMem(szSym);
if( pDstRow == pSrcRow ) OT_DEL_T(pDstRow);
}
else
if( pDstRow != pSrcRow ) OT_APPEND(pResRow,pSrcRow);
return pResRow;
}
static ROW(symbol) SD_symbolToNTSeq
(
c_bool bCond, c_string szSeq,
ROW(symbol) pDstRow, symbol pSrcSym
)
{
if( bCond )
{ c_string szSym = Str_printf("\"%c\"1",szSeq[0]);
OT_PUSH(stringToSymbol(szSym),pDstRow);
FreeMem(szSym);
OT_PUSH(pSrcSym,pDstRow);
szSym = Str_printf("\"%c\"",szSeq[1]);
OT_PUSH(stringToSymbol(szSym),pDstRow);
FreeMem(szSym);
}
else OT_PUSH(pSrcSym,pDstRow);
return pDstRow;
}
static c_bool SD_IsNTMetaSym(symbol pNTSym, symbol* ppMetaSym)
{ c_string szNTSym = symbolToString(pNTSym),
szS = szNTSym;
if( *szS == '"' )
{ char szBuffer[STD_BUFFLEN+1];
int nI = 0;
for( szS++; *szS != '"' && *szS != '\0'; ++nI, ++szS )
szBuffer[nI] = *szS;
szBuffer[nI] = '\0';
if( ppMetaSym != (symbol*)NULL )
*ppMetaSym = stringToSymbol(szBuffer);
return C_True;
}
else return C_False;
}
static c_bool SD_IsTMetaSym(symbol pTSym)
// Meta-Symbols: ()|+{}[]<>-/, and ..
{ c_string szMetaSet = "(){}[]<>|+-/,",
szTSym = symbolToString(pTSym);
if( strlen(szTSym) == 1 )
return strstr(szMetaSet,szTSym) != (c_string)NULL;
if( strlen(szTSym) == 2 )
return !strcmp(szTSym,"..") ||
!strcmp(szTSym,">=") ||
!strcmp(szTSym,"<=") ||
!strcmp(szTSym,"");
return C_False;
}
/* ------------------------- Init & Quit ---------------------------------- */
static void SD_init(int argc, c_string argv[])
/* init STYX documentation generation */
{ c_string szS, szT;
PIT pItr;
CTX_init_stydoc(argc,argv);
initSymbols();
MAP_init();
styx_initSymbols();
HP_init();
pClsToSplit = HS_CREATE_ADTSET(symbol);
if( !strcmp(cls_to_split,"--all--") )
bConcreteCfg = C_True;
else
if( strlen(cls_to_split) > 0 )
{
pItr = PIT_make(cls_to_split);
while( ( szS = PIT_read(pItr) ) != NULL )
HS_SET_ELM(stringToSymbol(szS),pClsToSplit);
PIT_drop(pItr);
}
pNTsToKeep = HS_CREATE_ADTSET(symbol);
if( !bConcreteCfg && strlen(nts_to_keep) > 0 )
{
pItr = PIT_make(nts_to_keep);
while( ( szS = PIT_read(pItr) ) != NULL )
HS_SET_ELM(stringToSymbol(szS),pNTsToKeep);
PIT_drop(pItr);
}
pIgnRecRef = HS_CREATE_ADTSET(symbol);
if( !bConcreteCfg && strlen(ign_rref) > 0 )
{
pItr = PIT_make(ign_rref);
while( ( szS = PIT_read(pItr) ) != NULL )
HS_SET_ELM(stringToSymbol(szS),pIgnRecRef);
PIT_drop(pItr);
}
pExcludedProds = MAP_newPrimMap();
if( strlen(excl_prods) > 0 )
{
pItr = PIT_make(excl_prods);
while( ( szS = PIT_read(pItr) ) != NULL )
{
szT = strstr(szS,".");
if( szT != (c_string)NULL )
{ symbol pNTSym, pProdSym;
SET(symbol) pProdSet;
*szT = '\0';
pNTSym = stringToSymbol(szS);
pProdSym = stringToSymbol(szT+1);
*szT = '.';
if( MAP_defined(pExcludedProds,pNTSym) )
pProdSet = MAP_apply(SET(symbol),pExcludedProds,pNTSym);
else
{
pProdSet = HS_CREATE_ADTSET(symbol);
MAP_dfndom(pExcludedProds,pNTSym,pProdSet);
}
HS_SET_ELM(pProdSym,pProdSet);
}
}
PIT_drop(pItr);
}
}
static void SD_quit(void)
/* quit STYX documentation generation */
{ MAPIT pItr;
SET(symbol) pProdSet;
symbol pNTSym;
MAP_forItrAsg(pNTSym,pProdSet,pItr,pExcludedProds)
HS_DROP_SET(pProdSet);
MAP_freeMap(pExcludedProds);
HS_DROP_SET(pNTsToKeep);
HS_DROP_SET(pClsToSplit);
HS_DROP_SET(pIgnRecRef);
HP_quit();
styx_quitSymbols();
MAP_quit();
freeSymbols();
CTX_quit();
}
static StyDoc_T SD_init_base(void)
/* init documentation base */
{ StyDoc_T pStyDoc = New(StyDoc_T);
pStyDoc->pDfnCom = MAP_newPrimMap();
pStyDoc->pGrpCom = MAP_newPrimMap();
pStyDoc->pTree = (PT_Term)NULL;
pStyDoc->pTab = (PLR_Tab)NULL;
pStyDoc->aPol = (int*)NULL;
pStyDoc->aNtm = (SET(int)*)NULL;
pStyDoc->aPrd = (SET(int)*)NULL;
pStyDoc->pGMap = MAP_newPrimMap();
pStyDoc->pTMap = MAP_newPrimMap();
pStyDoc->pNTMap = MAP_newPrimMap();
pStyDoc->pClsMap = MAP_newPrimMap();
pStyDoc->pLSet = HS_CREATE_ADTSET(symbol);
pStyDoc->pDocBase = OT_CREATE_ADT(_);
pStyDoc->pHPat = (HPat_T)NULL;
pStyDoc->pSysOut = (FILE*)NULL;
pStyDoc->lDocIdx = -1;
pStyDoc->lComIdx = -1;
pStyDoc->lMbrIdx = -1;
pStyDoc->pCurRow = (ROW(symbol))NULL;
return pStyDoc;
}
/* ------------------------- Output Generation ---------------------------- */
static void SD_gendoc_raw(StyDoc_T pStyDoc)
/* generate raw documentation - without template */
{ long lCnt = OT_CNT(pStyDoc->pDocBase)/2, lI, lJ, lK;
fprintf(pStyDoc->pSysOut,"\n%s - CFG Section\n",PLR_language(pStyDoc->pTab));
for( lI=0; lI < lCnt; ++lI )
{ ROW(ROW(symbol)) pLines = OT_GET
(
ROW(ROW(symbol)),
pStyDoc->pDocBase,pStyDoc->lDocIdx*2+1
);
symbol pSym = OT_GET
(
symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2
),
pMbrSym;
if( lI >= MAP_count(pStyDoc->pTMap) &&
MAP_defined(pStyDoc->pClsMap,pSym) )
pSym = MAP_apply(symbol,pStyDoc->pClsMap,pSym);
if( lI == 0 )
fprintf(pStyDoc->pSysOut,"\nToken Section\n");
else
if( lI == MAP_count(pStyDoc->pTMap) )
fprintf(pStyDoc->pSysOut,"\nNonterminal Section\n");
fprintf(pStyDoc->pSysOut,"\n");
for( lJ=0; lJ < OT_CNT(pLines); ++lJ )
{ ROW(symbol) pCurRow = OT_GET(ROW(symbol),pLines,lJ);
fprintf(pStyDoc->pSysOut,"\n\t%s ::",symbolToString(pSym));
for( lK=0; lK < OT_CNT(pCurRow); ++lK )
{
pMbrSym = OT_GET(symbol,pCurRow,lK);
if( lI >= MAP_count(pStyDoc->pTMap) &&
MAP_defined(pStyDoc->pClsMap,pMbrSym) )
pMbrSym = MAP_apply(symbol,pStyDoc->pClsMap,pMbrSym);
fprintf(pStyDoc->pSysOut," %s",symbolToString(pMbrSym));
}
}
}
}
static void SD_gendoc_txt(HPat_T pHPat, c_string szTxt)
/* generate documentation according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
fprintf(pStyDoc->pSysOut,"%s",szTxt);
}
static c_bool SD_gendoc_dref(HPat_T pHPat)
/* generate definition reference according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
pStyDoc->lComIdx = 0;
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( pStyDoc->lDocIdx >= MAP_count(pStyDoc->pTMap) )
{
if( MAP_defined(pStyDoc->pClsMap,pSym) )
pSym = MAP_apply(symbol,pStyDoc->pClsMap,pSym);
}
fprintf(pStyDoc->pSysOut,"%s",symbolToString(pSym));
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_did(HPat_T pHPat)
/* generate definition id according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
pStyDoc->lComIdx = 0;
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( pStyDoc->lDocIdx < MAP_count(pStyDoc->pTMap) )
{ styxQlxDfn pQDfn = MAP_apply(styxQlxDfn,pStyDoc->pTMap,pSym);
styxQlxGrp pSGrp, pDGrp; GLS_Tok pSId, pDId;
assert0( styxQlxDfn_defn(pQDfn,_,_,&pSGrp,_,&pDGrp,_), "" );
if( styxQlxGrp_non(pSGrp) && styxQlxGrp_non(pDGrp) )
fprintf(pStyDoc->pSysOut,"%s",symbolToString(pSym));
else
{ Sink pSnk = Sink_open(); c_string szID;
if( styxQlxGrp_grp(pSGrp,&pSId) )
{
Sink_printf(pSnk,"%s:",GLS_Tok_string(pSId));
}
Sink_printf(pSnk,"%s",symbolToString(pSym));
if( styxQlxGrp_grp(pDGrp,&pDId) )
{
Sink_printf(pSnk,":%s",GLS_Tok_string(pDId));
}
else
if( styxQlxGrp_igrp(pDGrp) )
{
Sink_printf(pSnk,":[initial]");
}
else
if( styxQlxGrp_pgrp(pDGrp,&pDId) )
{
Sink_printf(pSnk,":[push], %s",GLS_Tok_string(pDId));
}
else
if( styxQlxGrp_pigrp(pDGrp) )
{
Sink_printf(pSnk,":[push], [initial]");
}
else
if( styxQlxGrp_pop(pDGrp) )
{
Sink_printf(pSnk,":[pop]");
}
szID = Sink_close(pSnk);
fprintf(pStyDoc->pSysOut,"%s",szID);
FreeMem(szID);
}
}
else
{
if( MAP_defined(pStyDoc->pClsMap,pSym) )
pSym = MAP_apply(symbol,pStyDoc->pClsMap,pSym);
fprintf(pStyDoc->pSysOut,"%s",symbolToString(pSym));
}
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_lref(HPat_T pHPat)
/* generate embedded language reference according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 &&
pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 &&
pStyDoc->pCurRow != (ROW(symbol))NULL &&
pStyDoc->lMbrIdx >= 0 &&
pStyDoc->lMbrIdx < OT_CNT(pStyDoc->pCurRow) )
{ symbol pMbrSym = OT_GET(symbol,pStyDoc->pCurRow,pStyDoc->lMbrIdx);
if( strlen(outfile) > 0 )
{ MAP(symbol,symbol) pReplaceMap = MAP_newPrimMap();
c_string szPath = FilePrefix(outfile), szFile;
MAP_dfndom
(
pReplaceMap,stringToSymbol(PLR_language(pStyDoc->pTab)),pMbrSym
);
szFile = Line_replace(outfile+strlen(szPath),pReplaceMap);
fprintf(pStyDoc->pSysOut,"%s%s",szPath,szFile);
MAP_freeMap(pReplaceMap);
FreeMem(szPath); FreeMem(szFile);
}
else
fprintf(pStyDoc->pSysOut,"#%s",symbolToString(pMbrSym));
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_dcom(HPat_T pHPat)
/* generate definition comment according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( MAP_defined(pStyDoc->pDfnCom,pSym) &&
( pStyDoc->lComIdx == 0 || prodcom ) )
{ ROW(PT_Term) pComments = MAP_apply(ROW(PT_Term),pStyDoc->pDfnCom,pSym);
string szCom = SD_com_string(pComments,&pStyDoc->lComIdx);
if( szCom && HP_fun_defined(pHPat,SD_PAT_DFNCOM) )
{ c_string szRCom = HP_fun_apply(pHPat,SD_PAT_DFNCOM,szCom);
if( szCom != szRCom )
{
FreeMem(szCom); szCom = szRCom;
}
}
HP_gendoc_pat(pHPat,SD_PAT_NEWLINE);
fprintf(pStyDoc->pSysOut,"%s",szCom);
if( szCom != (string)NULL ) FreeMem(szCom);
}
else fprintf(pStyDoc->pSysOut," ");
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_ocom(HPat_T pHPat)
/* generate group comment section according template or "" */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
pStyDoc->lComIdx = 0;
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( MAP_defined(pStyDoc->pGrpCom,pSym) )
{
HP_gendoc_pat(pHPat,SD_PAT_COMSEC);
}
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_gcom(HPat_T pHPat)
/* generate group comment according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
pStyDoc->lComIdx = 0;
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( MAP_defined(pStyDoc->pGrpCom,pSym) )
{ ROW(PT_Term) pComments = MAP_apply(ROW(PT_Term),pStyDoc->pGrpCom,pSym);
string szCom = SD_com_string(pComments,&pStyDoc->lComIdx);
if( szCom && HP_fun_defined(pHPat,SD_PAT_GRPCOM) )
{ c_string szRCom = HP_fun_apply(pHPat,SD_PAT_GRPCOM,szCom);
if( szCom != szRCom )
{
FreeMem(szCom); szCom = szRCom;
}
}
fprintf(pStyDoc->pSysOut,"%s",szCom);
if( szCom != (string)NULL ) FreeMem(szCom);
}
else fprintf(pStyDoc->pSysOut," ");
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_bcom(HPat_T pHPat)
/* generate last group comment according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
pStyDoc->lComIdx = 0;
if( MAP_defined(pStyDoc->pGrpCom,NULL) )
{ ROW(PT_Term) pComments = MAP_apply(ROW(PT_Term),pStyDoc->pGrpCom,NULL);
string szCom = SD_com_string(pComments,&pStyDoc->lComIdx);
if( szCom && HP_fun_defined(pHPat,SD_PAT_BOTCOM) )
{ c_string szRCom = HP_fun_apply(pHPat,SD_PAT_BOTCOM,szCom);
if( szCom != szRCom )
{
FreeMem(szCom); szCom = szRCom;
}
}
fprintf(pStyDoc->pSysOut,"%s",szCom);
if( szCom != (string)NULL ) FreeMem(szCom);
}
else fprintf(pStyDoc->pSysOut," ");
return C_True;
}
static c_bool SD_gendoc_dcat(HPat_T pHPat)
/* generate definition category according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( pStyDoc->lDocIdx < MAP_count(pStyDoc->pTMap) )
{ styxQlxDfn pQDfn = MAP_apply(styxQlxDfn,pStyDoc->pTMap,pSym);
styxQlxCat pQCat;
assert0( styxQlxDfn_defn(pQDfn,&pQCat,_,_,_,_,_), "" );
if( styxQlxCat_letC(pQCat) ) fprintf(pStyDoc->pSysOut,"let");
else
if( styxQlxCat_comC(pQCat) ) fprintf(pStyDoc->pSysOut,"com");
else
if( styxQlxCat_ignC(pQCat) ) fprintf(pStyDoc->pSysOut,"ign");
else
if( styxQlxCat_tokC(pQCat) ) fprintf(pStyDoc->pSysOut,"tok");
else
if( styxQlxCat_lanC(pQCat) ) fprintf(pStyDoc->pSysOut,"lan");
else
if( styxQlxCat_indC(pQCat) ) fprintf(pStyDoc->pSysOut,"ind");
}
else
{ long lNTIdx = MAP_apply(long,pStyDoc->pNTMap,pSym);
if( ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_START) )
fprintf(pStyDoc->pSysOut,"start");
else fprintf(pStyDoc->pSysOut,"let");
}
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_dopt(HPat_T pHPat)
/* generate definition option according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 && pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ symbol pSym = OT_GET(symbol,pStyDoc->pDocBase,pStyDoc->lDocIdx*2);
if( pStyDoc->lDocIdx < MAP_count(pStyDoc->pTMap) )
{ styxQlxDfn pQDfn = MAP_apply(styxQlxDfn,pStyDoc->pTMap,pSym);
styxQlxCat pQOpt;
assert0( styxQlxDfn_defn(pQDfn,_,&pQOpt,_,_,_,_), "" );
if( styxQlxOpt_ignca(pQOpt) ) fprintf(pStyDoc->pSysOut,"[I]");
}
else
{ long lNTIdx = MAP_apply(long,pStyDoc->pNTMap,pSym);
if( PLR_isErrorNt(pStyDoc->pTab,lNTIdx) )
fprintf(pStyDoc->pSysOut,"[E]");
}
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_mid(HPat_T pHPat)
/* generate member id according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 &&
pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 &&
pStyDoc->pCurRow != (ROW(symbol))NULL &&
pStyDoc->lMbrIdx >= 0 &&
pStyDoc->lMbrIdx < OT_CNT(pStyDoc->pCurRow) )
{ symbol pMbrSym = OT_GET(symbol,pStyDoc->pCurRow,pStyDoc->lMbrIdx),
pDocSym = pMbrSym;
if( pStyDoc->lDocIdx >= MAP_count(pStyDoc->pTMap) )
{
if( ! SD_IsNTMetaSym(pMbrSym,&pDocSym) )
{
if( MAP_defined(pStyDoc->pClsMap,pDocSym) )
pDocSym = MAP_apply(symbol,pStyDoc->pClsMap,pDocSym);
}
}
if( !HP_fun_defined(pHPat,SD_PAT_MBRID) )
fprintf(pStyDoc->pSysOut,"%s",symbolToString(pDocSym));
else
{ c_string szRes = HP_fun_apply
(
pHPat,SD_PAT_MBRID,symbolToString(pDocSym)
);
fprintf(pStyDoc->pSysOut,"%s",szRes);
if( szRes != symbolToString(pDocSym) ) FreeMem(szRes);
}
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_cid(HPat_T pHPat)
/* generate language id according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
fprintf(pStyDoc->pSysOut,"%s",PLR_language(pStyDoc->pTab));
return C_True;
}
static c_bool SD_gendoc_dsec(HPat_T pHPat, symbol pSec)
/* generate definition section according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
long lCnt = ( pSec == SD_PAT_TKMSEC )
? MAP_count(pStyDoc->pTMap)
: OT_CNT(pStyDoc->pDocBase)/2,
lBgn = ( pSec == SD_PAT_TKMSEC )
? 0 : MAP_count(pStyDoc->pTMap),
lDocIdx, lMbrIdx, lI, lJ;
ROW(symbol) pRow = HP_getListPatRow(pHPat,pSec), pCurRow;
symbol pDfn = OT_GET(symbol,pRow,0);
lDocIdx = pStyDoc->lDocIdx;
lMbrIdx = pStyDoc->lMbrIdx;
pCurRow = pStyDoc->pCurRow;
for( lI=lBgn, lJ=0; lI < lCnt; ++lI, ++lJ )
{ ROW(ROW(symbol)) pLines = OT_GET(ROW(ROW(symbol)),pStyDoc->pDocBase,2*lI+1);
if( lJ > 0 )
{
HP_gendoc_pat(pHPat,pSec);
if( OT_CNT(pRow) > lJ ) pDfn = OT_GET(symbol,pRow,lJ);
}
pStyDoc->lDocIdx = lI;
pStyDoc->lMbrIdx = -1;
pStyDoc->pCurRow = ( lI < MAP_count(pStyDoc->pTMap) )
? OT_GET(ROW(symbol),pLines,0) : (ROW(symbol))NULL;
HP_gendoc_pat(pHPat,pDfn);
}
pStyDoc->lDocIdx = lDocIdx;
pStyDoc->lMbrIdx = lMbrIdx;
pStyDoc->pCurRow = pCurRow;
return C_True;
}
static c_bool SD_gendoc_tsec(HPat_T pHPat)
/* generate token section according template */
{
return SD_gendoc_dsec(pHPat,SD_PAT_TKMSEC);
}
static c_bool SD_gendoc_nsec(HPat_T pHPat)
/* generate nonterminal section according template */
{
return SD_gendoc_dsec(pHPat,SD_PAT_NTMSEC);
}
static c_bool SD_gendoc_psec(HPat_T pHPat)
/* generate production section according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 &&
pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 )
{ ROW(ROW(symbol)) pLines = OT_GET
(
ROW(ROW(symbol)),
pStyDoc->pDocBase,pStyDoc->lDocIdx*2+1
);
ROW(symbol) pRow = HP_getListPatRow(pHPat,SD_PAT_PRDSEC), pCurRow;
symbol pDfn = OT_GET(symbol,pRow,0);
long lCnt = OT_CNT(pLines), lI;
pCurRow = pStyDoc->pCurRow;
for( lI=0; lI < lCnt; ++lI )
{
if( lI > 0 )
{
HP_gendoc_pat(pHPat,SD_PAT_PRDSEC);
if( OT_CNT(pRow) > lI ) pDfn = OT_GET(symbol,pRow,lI);
}
pStyDoc->pCurRow = OT_GET(ROW(symbol),pLines,lI);
HP_gendoc_pat(pHPat,pDfn);
}
pStyDoc->pCurRow = pCurRow;
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_msec(HPat_T pHPat)
/* generate member section according template */
{ StyDoc_T pStyDoc = (StyDoc_T)HP_getContext(pHPat);
if( pStyDoc->lDocIdx >= 0 &&
pStyDoc->lDocIdx < OT_CNT(pStyDoc->pDocBase)/2 &&
pStyDoc->pCurRow != (ROW(symbol))NULL )
{ ROW(symbol) pPRow = HP_getListPatRow(pHPat,SD_PAT_MBRSEC);
symbol pRPat = OT_GET(symbol,pPRow,0),
pMPat = OT_CNT(pPRow) >= 2 ? OT_GET(symbol,pPRow,1) : pRPat,
pVPat = OT_CNT(pPRow) >= 3 ? OT_GET(symbol,pPRow,2) : pMPat,
pLPat = OT_CNT(pPRow) >= 4 ? OT_GET(symbol,pPRow,3) : pRPat,
pMbrSym;
long lCnt = OT_CNT(pStyDoc->pCurRow), lMbrIdx, lI;
lMbrIdx = pStyDoc->lMbrIdx;
for( lI=0; lI < lCnt; ++lI )
{
if( lI > 0 ) HP_gendoc_pat(pHPat,SD_PAT_MBRSEC);
pMbrSym = OT_GET(symbol,pStyDoc->pCurRow,lI);
pStyDoc->lMbrIdx = lI;
if( HS_MBR_ELM(pMbrSym,pStyDoc->pLSet) )
{
HP_gendoc_pat(pHPat,pLPat);
}
else
if( MAP_defined(pStyDoc->pNTMap,pMbrSym) ||
MAP_defined(pStyDoc->pTMap,pMbrSym) )
{
HP_gendoc_pat(pHPat,pRPat);
}
else
if( pStyDoc->lDocIdx < MAP_count(pStyDoc->pTMap) )
{
if( SD_IsTMetaSym(pMbrSym) )
HP_gendoc_pat(pHPat,pMPat);
else HP_gendoc_pat(pHPat,pVPat);
}
else
{
if( SD_IsNTMetaSym(pMbrSym,(symbol*)NULL) ||
!strcmp(symbolToString(pMbrSym),PLR_TOK_Other) )
HP_gendoc_pat(pHPat,pMPat);
else HP_gendoc_pat(pHPat,pVPat);
}
}
pStyDoc->lMbrIdx = lMbrIdx;
return C_True;
}
return C_False;
}
static c_bool SD_gendoc_cfg(HPat_T pHPat)
/* generate documentation according template */
{
HP_gendoc_pat(pHPat,SD_PAT_CFGDFN);
return C_True;
}
/* ------------------------- Load & Unload -------------------------------- */
#define IS_QEXP_UDC(e) ( styxExp_union(e,_,_) \
|| styxExp_diff(e,_,_) \
|| styxExp_conc(e,_,_) )
static void SD_collectSubExps(styxExp e, SET(styxExp) pSubExps)
// collection of sub expression ( ... )
{ PT_Itr it;
PT_FORALL(it,e)
{ PT_Term t = PT_termIT(it), p;
if (PT_stateIT(it) == PT_PRAE)
{ styxExp exp;
if (styx_Exp(t,&exp) && ignProd(symbolToString(PT_product(exp))))
{
p = PT_parts(exp);
while( p != (PT_Term)NULL && !PT_isNonTerm(p) )
{
if( PT_isKey(p) && !strcmp(symbolToString(PT_value(p)),"(") )
{
p = PT_ign_Skip(exp);
if( p != (PT_Term)NULL ) HS_SET_ELM(p,pSubExps);
}
p = PT_next(p);
}
}
}
}
}
static void SD_evalQExp(styxExp e, ROW(symbol) l, SET(styxExp) pSubExps)
// Meta-Symbols: ()|+{}[]- and ..
{ styxExp exp1, exp2, exp3; styxLimit limit; GLS_Tok tok;
if( styxExp_quot(e,&exp1,&exp2) )
{
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol("/"),l);
SD_evalQExp(exp2,l,pSubExps);
}
else
if( styxExp_dyck(e,&exp1,&exp2,&exp3) )
{
OT_PUSH(stringToSymbol("<"),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(">"),l);
SD_evalQExp(exp2,l,pSubExps);
OT_PUSH(stringToSymbol("<"),l);
SD_evalQExp(exp3,l,pSubExps);
OT_PUSH(stringToSymbol(">"),l);
}
else
if( styxExp_spat(e,&exp1,&tok,&exp2) || styxExp_epat(e,&exp1,&tok,&exp2) )
{
if( styxExp_spat(e,_,_,_) )
OT_PUSH(stringToSymbol("<="),l);
else
OT_PUSH(stringToSymbol(""),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(">"),l);
OT_PUSH(GLS_Tok_symbol(tok),l);
OT_PUSH(stringToSymbol("<"),l);
SD_evalQExp(exp2,l,pSubExps);
OT_PUSH(stringToSymbol(">"),l);
}
else
if( styxExp_union(e,&exp1,&exp2) )
{
if( HS_MBR_ELM(exp1,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol("|"),l);
if( HS_MBR_ELM(exp2,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp2,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp2,l,pSubExps);
}
else
if( styxExp_diff(e,&exp1,&exp2) )
{
if( HS_MBR_ELM(exp1,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol("-"),l);
if( HS_MBR_ELM(exp2,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp2,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp2,l,pSubExps);
}
else
if( styxExp_conc(e,&exp1,&exp2) )
{
if( HS_MBR_ELM(exp1,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp1,l,pSubExps);
if( HS_MBR_ELM(exp2,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp2,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp2,l,pSubExps);
}
else
if( styxExp_opt(e,&exp1) )
{
OT_PUSH(stringToSymbol("["),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol("]"),l);
}
else
if( styxExp_star(e,&exp1) || styxExp_plus0(e,&exp1) )
{
OT_PUSH(stringToSymbol("{"),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol("}"),l);
}
else
if( styxExp_plus(e,&exp1) || styxExp_plusn(e,&exp1,&limit) )
{
if( HS_MBR_ELM(exp1,pSubExps) )
{
OT_PUSH(stringToSymbol("("),l);
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(")"),l);
}
else SD_evalQExp(exp1,l,pSubExps);
if( styxExp_plus(e,_) )
OT_PUSH(stringToSymbol("+"),l);
else
{ styxOptNat optnat;
if( styxLimit_ntime(limit,&tok) )
OT_PUSH(GLS_Tok_symbol(tok),l);
else
if( styxLimit_range(limit,&tok,&optnat) )
{
if( styxOptNat_non(optnat) )
{
OT_PUSH(stringToSymbol(">="),l);
OT_PUSH(GLS_Tok_symbol(tok),l);
}
else
{
OT_PUSH(GLS_Tok_symbol(tok),l);
OT_PUSH(stringToSymbol(","),l);
assert( styxOptNat_nat(optnat,&tok), "");
OT_PUSH(GLS_Tok_symbol(tok),l);
}
}
}
}
else
if( styxExp_range(e,&exp1,&exp2) )
{
SD_evalQExp(exp1,l,pSubExps);
OT_PUSH(stringToSymbol(".."),l);
SD_evalQExp(exp2,l,pSubExps);
}
else
if( styxExp_set(e,&tok) )
{
OT_PUSH(GLS_Tok_symbol(tok),l);
}
else
if( styxExp_sequ(e,&tok) )
{
OT_PUSH(GLS_Tok_symbol(tok),l);
}
else
if( styxExp_ident(e,&tok) )
{
OT_PUSH(GLS_Tok_symbol(tok),l);
}
else
if( !styxExp_non(e) ) C_BUG;
}
static void SD_load_com(StyDoc_T pStyDoc)
/* load comments */
{ PT_Itr pItr; GLS_Tok pIde;
ROW(PT_Term) pComments = NULL;
ROW(PT_Term) pGrpComments = NULL;
long lRow = 0, lDRow = 0;
PT_FORALL(pItr,pStyDoc->pTree)
{ PT_Term t = PT_termIT(pItr), c;
if (PT_stateIT(pItr) == PT_PRAE)
{
if( PT_hasPos(t) )
{
lRow = PT_row(t);
if( PT_isComment(t) && strstr(GLS_Tok_string(t),";;") == NULL )
{
if( pComments == NULL )
{
if( pGrpComments == NULL )
{
pGrpComments = OT_CREATE_ADT(PT_Term);
}
OT_PUSH(t,pGrpComments);
}
else
{
if( lDRow == lRow || lDRow + 1 == lRow )
OT_PUSH(t,pComments);
else
{
if( OT_CNT(pComments) > 0 )
{
c = OT_TOP(PT_Term,pComments);
if( lRow == (long)(PT_row(c) + 1) )
OT_PUSH(t,pComments);
else
{
if( pGrpComments == NULL )
{
pGrpComments = OT_CREATE_ADT(PT_Term);
}
OT_PUSH(t,pGrpComments);
}
}
else
{
if( pGrpComments == NULL )
{
pGrpComments = OT_CREATE_ADT(PT_Term);
}
OT_PUSH(t,pGrpComments);
}
}
}
}
else
if( PT_isNonTerm(t) )
{
if( styx_QlxDfn(t,_) )
{
assert0( styxQlxDfn_defn((styxQlxDfn)t,_,_,_,&pIde,_,_)
|| styxQlxDfn_igrp((styxQlxDfn)t,&pIde)
|| styxQlxDfn_xgrp((styxQlxDfn)t,&pIde)
|| styxQlxDfn_tgrp((styxQlxDfn)t,&pIde)
|| styxQlxDfn_mgrp((styxQlxDfn)t,&pIde,_), "");
if( !MAP_defined(pStyDoc->pDfnCom,GLS_Tok_symbol(pIde)) )
{
pComments = OT_CREATE_ADT(PT_Term);
MAP_dfndom(pStyDoc->pDfnCom,GLS_Tok_symbol(pIde),pComments);
if( pGrpComments != NULL )
{
MAP_dfndom(pStyDoc->pGrpCom,GLS_Tok_symbol(pIde),pGrpComments);
pGrpComments = NULL;
}
lDRow = lRow;
}
}
else
if( styx_Dfn(t,_) )
{
styxDfn_defn((styxDfn)t,_,_,&pIde,_);
if( !MAP_defined(pStyDoc->pDfnCom,GLS_Tok_symbol(pIde)) )
{
pComments = OT_CREATE_ADT(PT_Term);
MAP_dfndom(pStyDoc->pDfnCom,GLS_Tok_symbol(pIde),pComments);
if( pGrpComments != NULL )
{
MAP_dfndom(pStyDoc->pGrpCom,GLS_Tok_symbol(pIde),pGrpComments);
pGrpComments = NULL;
}
lDRow = lRow;
}
}
else
if( styx_Prd(t,_) )
{
styxPrd_prod((styxPrd)t,_,&pIde,_);
OT_PUSH(pIde,pComments);
if( pGrpComments != NULL )
{
OT_APPEND(pComments,pGrpComments);
OT_DEL_T(pGrpComments);
pGrpComments = NULL;
}
lDRow = lRow;
}
}
}
}
}
if( pGrpComments != NULL )
MAP_dfndom(pStyDoc->pGrpCom,NULL,pGrpComments);
}
static void SD_load_lex(GLS_Lst(styxQlxDfn) pQDfns, StyDoc_T pStyDoc)
/* load documentation base for lexical analysis */
{ GLS_Lst(styxQlxDfn) pItr;
GLS_Tok pIde, pLan;
styxQlxGrp pQGrp;
styxQlxDfn pQDfn;
styxQlxCat pQCat;
styxExp pQExp;
symbol pTSym;
c_string szETok;
GLS_FORALL(pItr,pQDfns) // token map
{
pQDfn = GLS_FIRST(styxQlxDfn,pItr);
if( styxQlxDfn_defn(pQDfn,&pQCat,_,&pQGrp,&pIde,_,_) )
{
if( styxQlxCat_lanC(pQCat) )
{
assert0(styxQlxGrp_grp(pQGrp,&pLan),"");
HS_SET_ELM(GLS_Tok_symbol(pLan),pStyDoc->pLSet);
szETok = Str_printf("%s%s",GLS_Tok_string(pLan),GLS_Tok_string(pIde));
pTSym = stringToSymbol(szETok);
FreeMem(szETok);
}
else pTSym = GLS_Tok_symbol(pIde);
if( ! MAP_defined(pStyDoc->pTMap,pTSym) )
MAP_dfndom(pStyDoc->pTMap,pTSym,pQDfn);
}
else
if( styxQlxDfn_igrp(pQDfn,&pIde) || styxQlxDfn_xgrp(pQDfn,&pIde) ||
styxQlxDfn_tgrp(pQDfn,&pIde) ||
styxQlxDfn_mgrp(pQDfn,&pIde,_) )
{
if( ! MAP_defined(pStyDoc->pGMap,GLS_Tok_symbol(pIde)) )
MAP_dfndom(pStyDoc->pGMap,GLS_Tok_symbol(pIde),pQDfn);
}
}
GLS_FORALL(pItr,pQDfns) // token document base
{ ROW(ROW(symbol)) pTLines;
ROW(symbol) pTLine;
SET(styxExp) pSubExps;
pQDfn = GLS_FIRST(styxQlxDfn,pItr);
if( styxQlxDfn_defn(pQDfn,&pQCat,_,&pQGrp,&pIde,_,&pQExp) )
{
pTLines = OT_CREATE(ROW(symbol),primCopy,OT_delT,primEqual);
pTLine = OT_CREATE_ADT(symbol);
if( !styxQlxCat_lanC(pQCat) )
pTSym = GLS_Tok_symbol(pIde);
else
{
assert0(styxQlxGrp_grp(pQGrp,&pLan),"");
szETok = Str_printf("%s%s",GLS_Tok_string(pLan),GLS_Tok_string(pIde));
pTSym = stringToSymbol(szETok);
FreeMem(szETok);
}
OT_PUSH(pTSym,pStyDoc->pDocBase);
OT_PUSH(pTLines,pStyDoc->pDocBase);
OT_PUSH(pTLine,pTLines);
if( !styxQlxCat_lanC(pQCat) )
{
pSubExps = HS_CREATE_ADTSET(styxExp);
SD_collectSubExps(pQExp,pSubExps);
SD_evalQExp(pQExp,pTLine,pSubExps);
HS_DROP_SET(pSubExps);
}
else
{
OT_PUSH(GLS_Tok_symbol(pLan),pTLine);
}
}
}
}
// Meta-Symbols in Productions are enclosed with ".
/**/static long SD_load_ntgroup
(
long lNTIdx, MAP(long,ROW(ROW(symbol))) pEBNF,
StyDoc_T pStyDoc
);
static c_bool SD_splitClass(StyDoc_T pStyDoc, long lClsIdx)
/* create separate rules for each nonterminal */
{ symbol pClsSym = stringToSymbol(PLR_symName
(
pStyDoc->pTab, PLR_tokenCnt(pStyDoc->pTab) + lClsIdx
));
return HS_MBR_ELM(pClsSym,pClsToSplit);
}
static ROW(symbol) SD_load_ntprod
(
long lNTIdx, long lPrdIdx, long lDocIdx, c_bool bNTList,
MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* load documentation base for a production of nonterminal 'lNTIdx' */
{ long lMbrCnt, lSym, lSymIdx, lClsIdx, lTyp,
lSubSym, lClsSym, lSubIdx, lI, lJ;
ROW(ROW(symbol)) pNTLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lDocIdx),
pMbrLines;
ROW(symbol) pNTLine = OT_CREATE_ADT(symbol), pMbrLine;
c_string szSym, szClsSym;
symbol pSym, pClsSym;
c_bool bOptNT;
lMbrCnt = PLR_prodSymCnt(pStyDoc->pTab,lPrdIdx);
for( lI=0; lI < lMbrCnt; ++lI )
{
lSym = PLR_prodSymbol(pStyDoc->pTab,lPrdIdx,lI);
lTyp = PLR_symType(pStyDoc->pTab,lSym);
if( CFG_NTM(lTyp) )
{
lSymIdx = lSym-PLR_tokenCnt(pStyDoc->pTab);
lClsIdx = PLR_ntClassId(pStyDoc->pTab,lSymIdx);
lSubIdx = SD_load_ntgroup(lSymIdx,pEBNF,pStyDoc);
lSubSym = lSubIdx + PLR_tokenCnt(pStyDoc->pTab);
lClsSym = lClsIdx + PLR_tokenCnt(pStyDoc->pTab);
szSym = PLR_symName(pStyDoc->pTab,lSubSym);
szClsSym = SD_splitClass(pStyDoc,lClsIdx)
? szSym : PLR_symName(pStyDoc->pTab,lClsSym);
pSym = stringToSymbol(szSym);
pClsSym = stringToSymbol(szClsSym);
pMbrLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lSubIdx);
bOptNT = ACFG_HAS_NTTYP(pStyDoc->aPol[lSubIdx],ACFG_NTTYP_OPT) &&
! ACFG_HAS_NTTYP(pStyDoc->aPol[lSubIdx],ACFG_NTTYP_RECTYP);
if( HS_MBR_ELM(pSym,pNTsToKeep) ||
( ( MAP_defined(pStyDoc->pNTMap,pSym) ||
SD_IsNTRecRef(lSymIdx, pStyDoc) ||
! ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST) ) &&
( ACFG_HAS_NTTYP(pStyDoc->aPol[lSubIdx],ACFG_NTTYP_RECTYP) ||
( OT_CNT(pMbrLines) > 1 &&
! ( ACFG_HAS_NTTYP(pStyDoc->aPol[lSymIdx],ACFG_NTTYP_REF1) &&
ignProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) &&
lMbrCnt == 1 ) ) ) ) )
/*HM 26.1.2005
if( ( MAP_defined(pStyDoc->pNTMap,pSym) ||
HS_MBR_ELM(pSym,pNTsToKeep) ||
SD_IsNTRecRef(lSymIdx, pStyDoc) ||
! ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST) ) &&
( ACFG_HAS_NTTYP(pStyDoc->aPol[lSubIdx],ACFG_NTTYP_RECTYP) ||
( OT_CNT(pMbrLines) > 1 &&
! ( ACFG_HAS_NTTYP(pStyDoc->aPol[lSymIdx],ACFG_NTTYP_REF1) &&
ignProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) &&
lMbrCnt == 1 ) ) ) )
*/
{
if( ! MAP_defined(pStyDoc->pNTMap,pSym) )
{
if( pSym != pClsSym &&
!MAP_defined(pStyDoc->pNTMap,pClsSym) )
MAP_dfndom(pStyDoc->pClsMap,pSym,pClsSym);
MAP_dfndom(pStyDoc->pNTMap,pSym,lSubIdx);
OT_PUSH(pSym,pStyDoc->pDocBase);
OT_PUSH(pMbrLines,pStyDoc->pDocBase);
}
SD_symbolToNTSeq(bOptNT,"[]",pNTLine,pSym);
}
else
if( OT_CNT(pMbrLines) > 0 )
{
if( ! bNTList )
{
if( OT_CNT(pMbrLines) == 1 )
{
pMbrLine = OT_GET(ROW(symbol),pMbrLines,0);
if( ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST) )
SD_rowToNTSeq
(
lMbrCnt > 1 && SD_IsNTUnion(pMbrLine) &&
!SD_IsNTSequence(pMbrLine),
"()", pNTLine,pMbrLine
);
else SD_rowToNTSeq(bOptNT,"[]",pNTLine,pMbrLine);
}
else
{
assert0( pMbrLines != pNTLines,szSym );
for( lJ=0; lJ < OT_CNT(pMbrLines); ++lJ )
{
pMbrLine = OT_GET(ROW(symbol),pMbrLines,lJ);
OT_PUSH(OT_COPY(pMbrLine),pNTLines);
}
}
}
else // in this case only one line is possible !!!
if( lNTIdx != lSymIdx ) // CONSREF
{
pMbrLine = OT_GET(ROW(symbol),pMbrLines,0);
if( PLR_ntClassId(pStyDoc->pTab,lNTIdx) != lClsIdx &&
ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST) )
SD_rowToNTSeq
(
SD_IsNTUnion(pMbrLine) && !SD_IsNTSequence(pMbrLine),
"()", pNTLine,pMbrLine
);
else SD_rowToNTSeq(bOptNT,"[]",pNTLine,pMbrLine);
}
}
}
else
{
szSym = PLR_symName(pStyDoc->pTab,lSym);
OT_PUSH(stringToSymbol(szSym),pNTLine);
}
}
return pNTLine;
}
static void SD_cons_ntprod
(
long lDocIdx, MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* concat simple nonterminal/class productions */
{
ROW(ROW(symbol)) pNTLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lDocIdx);
ROW(symbol) pNTLine;
long lClsIdx = PLR_ntClassId(pStyDoc->pTab,lDocIdx), lCnt, lI;
c_bool bSimple;
bSimple = ! ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST) &&
( ACFG_HAS_NTTYP(pStyDoc->aPol[lDocIdx],ACFG_NTTYP_PRIM) ||
ACFG_HAS_NTTYP(pStyDoc->aPol[lDocIdx],ACFG_NTTYP_PRIMC) );
lCnt = OT_CNT(pNTLines);
if( lCnt > 1 && bSimple )
{
pNTLine = OT_GET(ROW(symbol),pNTLines,0);
if( OT_CNT(pNTLine) > 0 )
{
for( lI=1; lI < lCnt; ++lI )
{
OT_PUSH(stringToSymbol("\"|\""),pNTLine);
OT_APPEND(pNTLine,OT_GET(ROW(symbol),pNTLines,lI));
}
OT_DEL_ES(pNTLines,1,lCnt-1);
}
}
}
static void SD_load_nt
(
long lNTIdx, c_bool bNTClass,
MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* load documentation base for a nonterminal/class */
{ long lClsIdx = PLR_ntClassId(pStyDoc->pTab,lNTIdx),
lDocIdx = bNTClass ? lClsIdx : lNTIdx,
lPrdIdx;
ROW(ROW(symbol)) pNTLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lDocIdx);
ROW(symbol) pNTLine;
HS_Itr pItr;
symbol pNTSym = stringToSymbol(PLR_symName
(
pStyDoc->pTab,
PLR_tokenCnt(pStyDoc->pTab) + lNTIdx
)), pProdSym;
c_bool bExcluded;
HS_FORALL(lPrdIdx,pItr,pStyDoc->aPrd[lNTIdx])
{
pProdSym = stringToSymbol(PLR_prodName(pStyDoc->pTab,lPrdIdx));
bExcluded = MAP_defined(pExcludedProds,pNTSym) &&
HS_MBR_ELM
(
pProdSym,MAP_apply(SET(symbol),pExcludedProds,pNTSym)
);
if( ! bExcluded &&
( ! bNTClass ||
!ignProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) ||
PLR_prodSymCnt(pStyDoc->pTab,lPrdIdx) > 1 ) )
{
pNTLine = SD_load_ntprod(lNTIdx,lPrdIdx,lDocIdx,C_False,pEBNF,pStyDoc);
if( OT_CNT(pNTLine) > 0 )
OT_PUSH(pNTLine,pNTLines);
else OT_DEL_T(pNTLine);
}
}
}
static c_bool SD_add_listprod
(
long lNTIdx, long lPrdIdx,
c_bool bNTNil, ROW(symbol) pListLine,
MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* appends list production to 'pListLine' if not empty. RC = opt. list */
{ ROW(symbol) pNTLine = SD_load_ntprod
(
lNTIdx,lPrdIdx,lNTIdx,C_True,pEBNF,pStyDoc
);
c_bool bEmpty = ( OT_CNT(pNTLine) == 0 );
if( ! bEmpty )
{
bEmpty = bNTNil;
if( OT_CNT(pListLine) > 0 ) OT_PUSH(stringToSymbol("\"|\""),pListLine);
OT_APPEND(pListLine,pNTLine);
}
OT_DEL_T(pNTLine);
return bEmpty;
}
static c_bool SD_add_consprod
(
long lNTIdx, long lPrdIdx,
c_bool bNTNil, ROW(symbol)* pListLine,
MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* appends cons production to 'pListLine' if not empty. RC = opt. list */
{ ROW(symbol) pNTLine = SD_load_ntprod
(
lNTIdx,lPrdIdx,lNTIdx,C_True,pEBNF,pStyDoc
),
pTmpLine;
c_bool bEmpty = ( OT_CNT(pNTLine) == 0 );
if( ! bEmpty )
{
bEmpty = ( bNTNil && OT_CNT(*pListLine) > 0 );
pTmpLine = OT_CREATE_ADT(symbol);
SD_rowToNTSeq
(
bNTNil || !SD_IsNTSequence(pNTLine), bNTNil?"{}":"()", pTmpLine,pNTLine
);
if( ! bNTNil ) OT_PUSH(stringToSymbol("\"+\""),pTmpLine);
pTmpLine =
SD_rowToNTSeq(!bNTNil && OT_CNT(*pListLine) > 0,"[]",pTmpLine,pTmpLine);
if( SD_IsLLProd(lPrdIdx,pStyDoc) )
{
OT_APPEND(*pListLine,pTmpLine); OT_DEL_T(pTmpLine);
}
else
{
OT_APPEND(pTmpLine,*pListLine); OT_DEL_T(*pListLine);
*pListLine = pTmpLine;
}
}
OT_DEL_T(pNTLine);
return bEmpty;
}
static void SD_load_ntlist
(
long lNTIdx, MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* load documentation base for a nonterminal list */
{ long lConsIdx = -1, lMbrCnt, lPrdIdx, lIgnNTIdx;
c_bool bNTNil = ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_NIL),
bConsRef =
ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_CONSREF) &&
! SD_IsNTRecRef(lNTIdx, pStyDoc);
ROW(symbol) pListLine = OT_CREATE_ADT(symbol);
HS_Itr pItr;
HS_FORALL(lPrdIdx,pItr,pStyDoc->aPrd[lNTIdx])
{
lMbrCnt = PLR_prodSymCnt(pStyDoc->pTab,lPrdIdx);
if( nilProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) && lMbrCnt > 0 )
bNTNil = SD_add_listprod(lNTIdx,lPrdIdx,bNTNil,pListLine,pEBNF,pStyDoc);
else
if( ignProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) )
{
lIgnNTIdx = SD_getIgnNTIdx(lPrdIdx,pStyDoc);
if( lMbrCnt > 1 ||
( ! ACFG_HAS_NTTYP(pStyDoc->aPol[lIgnNTIdx],ACFG_NTTYP_EMPTY) &&
lIgnNTIdx != lNTIdx ) )
bNTNil = SD_add_listprod(lNTIdx,lPrdIdx,bNTNil,pListLine,pEBNF,pStyDoc);
else
bNTNil |= ACFG_HAS_NTTYP(pStyDoc->aPol[lIgnNTIdx],ACFG_NTTYP_EMPTY);
}
else
if( consProd(PLR_prodName(pStyDoc->pTab,lPrdIdx)) )
{
if( bConsRef ) lConsIdx = lPrdIdx;
else
bNTNil = SD_add_listprod(lNTIdx,lPrdIdx,bNTNil,pListLine,pEBNF,pStyDoc);
}
}
if( lConsIdx >= 0 )
bNTNil = SD_add_consprod(lNTIdx,lConsIdx,bNTNil,&pListLine,pEBNF,pStyDoc);
pListLine =
SD_rowToNTSeq(bNTNil && OT_CNT(pListLine) > 0,"[]",pListLine,pListLine);
if( OT_CNT(pListLine) > 0 )
{ ROW(ROW(symbol)) pNTLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lNTIdx);
OT_PUSH(pListLine,pNTLines);
}
else OT_DEL_T(pListLine);
}
static long SD_load_ntgroup
(
long lNTIdx, MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* load documentation base for a nonterminal/class/list */
{ long lClsIdx = PLR_ntClassId(pStyDoc->pTab,lNTIdx), lDocIdx;
c_bool bNTList = ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_LIST),
bNTClass = !bNTList &&
ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_CLASS) &&
! SD_splitClass(pStyDoc,lClsIdx);
lDocIdx = bNTClass ? lClsIdx : lNTIdx;
if( ! MAP_defined(pEBNF,lDocIdx) )
{ ROW(ROW(symbol)) pNTLines = OT_CREATE
(
ROW(symbol),primCopy,OT_delT,primEqual
);
symbol pNTSym = stringToSymbol(PLR_symName
(
pStyDoc->pTab,
PLR_tokenCnt(pStyDoc->pTab) + lDocIdx
)),
pClsSym = SD_splitClass(pStyDoc,lClsIdx)
? pNTSym
: stringToSymbol(PLR_symName
(
pStyDoc->pTab,
PLR_tokenCnt(pStyDoc->pTab) + lClsIdx
));
HS_Itr pItr;
MAP_dfndom(pEBNF,lDocIdx,pNTLines);
if( ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_START) &&
! MAP_defined(pStyDoc->pNTMap,pNTSym) )
{
if( pNTSym != pClsSym &&
!MAP_defined(pStyDoc->pNTMap,pClsSym) )
MAP_dfndom(pStyDoc->pClsMap,pNTSym,pClsSym);
MAP_dfndom(pStyDoc->pNTMap,pNTSym,lDocIdx);
OT_PUSH(pNTSym,pStyDoc->pDocBase);
OT_PUSH(pNTLines,pStyDoc->pDocBase);
}
if( bNTClass )
{
if( ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_RECTYP) &&
ACFG_HAS_NTTYP(pStyDoc->aPol[lClsIdx],ACFG_NTTYP_OPT) )
OT_PUSH(OT_CREATE_ADT(symbol),pNTLines);
HS_FORALL(lNTIdx,pItr,pStyDoc->aNtm[lClsIdx])
if( HS_CARD(pStyDoc->aPrd[lNTIdx]) > 1 ||
! ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_EMPTY) )
{
SD_load_nt(lNTIdx,bNTClass,pEBNF,pStyDoc);
}
}
else
{
if( HS_CARD(pStyDoc->aPrd[lNTIdx]) > 1 ||
! ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_EMPTY) )
{
if( bNTList ) SD_load_ntlist(lNTIdx,pEBNF,pStyDoc);
else
{
if( ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_RECTYP) &&
ACFG_HAS_NTTYP(pStyDoc->aPol[lNTIdx],ACFG_NTTYP_OPT) )
OT_PUSH(OT_CREATE_ADT(symbol),pNTLines);
SD_load_nt(lNTIdx,bNTClass,pEBNF,pStyDoc);
}
}
}
}
return lDocIdx;
}
static void SD_load_cfg(StyDoc_T pStyDoc)
/* load documentation base for context free grammar */
{ MAP(long,ROW(ROW(symbol))) pEBNF;
ROW(ROW(symbol)) pNTLines;
MAPIT pItr;
long lCnt = PLR_startCnt(pStyDoc->pTab),
lDocIdx, lI;
symbol pNTSym;
pEBNF = MAP_newPrimMap();
for( lI=0; lI < lCnt; ++lI )
{
lDocIdx = SD_load_ntgroup
(
PLR_startSymbol(pStyDoc->pTab,lI)-PLR_tokenCnt(pStyDoc->pTab),
pEBNF,pStyDoc
);
}
MAP_forItrAsg(pNTSym,lDocIdx,pItr,pStyDoc->pNTMap)
{
SD_cons_ntprod(lDocIdx,pEBNF,pStyDoc);
MAP_rmvdom(pEBNF,lDocIdx);
}
MAP_forItrAsg(lDocIdx,pNTLines,pItr,pEBNF)
if( pNTLines != (ROW(ROW(symbol)))NULL ) OT_DEL_T(pNTLines);
MAP_freeMap(pEBNF);
}
static void SD_load_cnt
(
long lNTIdx,
MAP(long,ROW(ROW(symbol))) pEBNF, StyDoc_T pStyDoc
)
/* load documentation base for a nonterminal */
{ long lPrdIdx, lSymCnt, lSym, lI;
ROW(ROW(symbol)) pNTLines = MAP_apply(ROW(ROW(symbol)),pEBNF,lNTIdx);
ROW(symbol) pNTLine;
HS_Itr pItr;
symbol pNTSym = stringToSymbol(PLR_symName
(
pStyDoc->pTab,
PLR_tokenCnt(pStyDoc->pTab) + lNTIdx
)), pProdSym;
c_bool bExcluded;
HS_FORALL(lPrdIdx,pItr,pStyDoc->aPrd[lNTIdx])
{
pProdSym = stringToSymbol(PLR_prodName(pStyDoc->pTab,lPrdIdx));
bExcluded = MAP_defined(pExcludedProds,pNTSym) &&
HS_MBR_ELM
(
pProdSym,MAP_apply(SET(symbol),pExcludedProds,pNTSym)
);
if( ! bExcluded )
{
pNTLine = OT_CREATE_ADT(symbol);
OT_PUSH(pNTLine,pNTLines);
lSymCnt = PLR_prodSymCnt(pStyDoc->pTab,lPrdIdx);
for( lI=0; lI < lSymCnt; ++lI )
{ c_string szSym;
lSym = PLR_prodSymbol(pStyDoc->pTab,lPrdIdx,lI);
szSym = PLR_symName(pStyDoc->pTab,lSym);
OT_PUSH(stringToSymbol(szSym),pNTLine);
}
}
}
}
static void SD_load_ccfg(StyDoc_T pStyDoc)
/* load documentation base for the concrete context free grammar */
{ MAP(long,ROW(ROW(symbol))) pEBNF;
ROW(ROW(symbol)) pNTLines;
MAPIT pItr;
long lCnt = PLR_startCnt(pStyDoc->pTab),
lDocIdx, lI;
symbol pNTSym;
pEBNF = MAP_newPrimMap();
for( lI=0; lI < lCnt; ++lI )
{
lDocIdx = PLR_startSymbol(pStyDoc->pTab,lI)-PLR_tokenCnt(pStyDoc->pTab);
pNTSym = stringToSymbol
(
PLR_symName(pStyDoc->pTab,PLR_tokenCnt(pStyDoc->pTab)+lDocIdx)
);
MAP_dfndom(pStyDoc->pNTMap,pNTSym,lDocIdx);
pNTLines = OT_CREATE(ROW(symbol),primCopy,OT_delT,primEqual);
MAP_dfndom(pEBNF,lDocIdx,pNTLines);
OT_PUSH(pNTSym,pStyDoc->pDocBase);
OT_PUSH(pNTLines,pStyDoc->pDocBase);
SD_load_cnt(lDocIdx,pEBNF,pStyDoc);
}
lCnt = PLR_nontermCnt(pStyDoc->pTab);
for( lI=0; lI < lCnt; ++lI )
{
if( !MAP_defined(pEBNF,lI) )
{
pNTSym = stringToSymbol
(
PLR_symName(pStyDoc->pTab,PLR_tokenCnt(pStyDoc->pTab)+lI)
);
MAP_dfndom(pStyDoc->pNTMap,pNTSym,lI);
pNTLines = OT_CREATE(ROW(symbol),primCopy,OT_delT,primEqual);
MAP_dfndom(pEBNF,lI,pNTLines);
OT_PUSH(pNTSym,pStyDoc->pDocBase);
OT_PUSH(pNTLines,pStyDoc->pDocBase);
SD_load_cnt(lI,pEBNF,pStyDoc);
}
}
MAP_forItrAsg(pNTSym,lDocIdx,pItr,pStyDoc->pNTMap)
{
MAP_rmvdom(pEBNF,lDocIdx);
}
MAP_forItrAsg(lDocIdx,pNTLines,pItr,pEBNF)
if( pNTLines != (ROW(ROW(symbol)))NULL ) OT_DEL_T(pNTLines);
MAP_freeMap(pEBNF);
}
static c_bool SD_load_pat(StyDoc_T pStyDoc)
/* load template */
{
if( strlen(template) > 0 )
{ Scn_Stream pStream;
pStyDoc->pHPat = HP_create();
HP_setContext(pStyDoc->pHPat,pStyDoc);
HP_setPrintFun(pStyDoc->pHPat,SD_gendoc_txt);
if( strlen(refalias) > 0 )
HP_setRefAlias(pStyDoc->pHPat,stringToSymbol(refalias));
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_CFGDFN,SD_gendoc_cfg,HPAT_REF_PAT);
//HP_addPatSpec(pStyDoc->pHPat,SD_PAT_COMSEC,SD_gendoc_csec,HPAT_REF_PAT);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_TKMSEC,SD_gendoc_tsec,HPAT_REF_LIST);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_NTMSEC,SD_gendoc_nsec,HPAT_REF_LIST);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_MBRSEC,SD_gendoc_msec,HPAT_REF_LIST);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_PRDSEC,SD_gendoc_psec,HPAT_REF_LIST);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_CFGID,SD_gendoc_cid,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_DFNID,SD_gendoc_did,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_DFNREF,SD_gendoc_dref,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_LANREF,SD_gendoc_lref,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_DFNCAT,SD_gendoc_dcat,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_DFNOPT,SD_gendoc_dopt,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_MBRID,SD_gendoc_mid,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_DFNCOM,SD_gendoc_dcom,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_GRPCOM,SD_gendoc_gcom,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_BOTCOM,SD_gendoc_bcom,HPAT_REF_PAR);
HP_addPatSpec(pStyDoc->pHPat,SD_PAT_OPTCOM,SD_gendoc_ocom,HPAT_REF_PAR);
pStream = Stream_file(HP_getScanner(pStyDoc->pHPat),"",template,"");
return HP_load(pStyDoc->pHPat,pStream,NULL,SD_PAT_CFGDFN,recursiv) &&
HP_check(pStyDoc->pHPat);
}
else return C_True;
}
static c_bool SD_load(StyDoc_T* ppStyDoc)
/* load documentation base */
{ PLR_Tab pTab;
Scn_T pScn;
Scn_Stream pStream;
PT_Cfg pCfg;
StyDoc_T pStyDoc;
MAP(long,symbol) pPreParMap;
SPP_T pPP;
// init database
pStyDoc = *ppStyDoc = SD_init_base();
// parse language definition
pPreParMap = MAP_newPrimMap();
MAP_dfndom(pPreParMap,SPP_INC_PATH,stringToSymbol(styxpath));
pPP = SPP_init_reentrant(pPreParMap);
Scn_get_styx(&pScn);
pStream = Stream_file(pScn,"",infile,"");
Stream_premac_set(pStream, SPP_premac);
Stream_add_ctxval(pStream,stringToSymbol("SPP_premac"),pPP);
pTab = PLR_get_styx();
pCfg = PT_init(pTab,pStream);
pStyDoc->pTree = PT_PARSE(pCfg,"");
PT_setErrorCnt(PT_synErrorCnt(pCfg));
PT_quit(pCfg);
Stream_close(pStream);
Stream_free(pStream);
Scn_free(pScn);
PLR_delTab(pTab);
SPP_quit_reentrant(pPP);
MAP_freeMap(pPreParMap);
if( PT_errorCnt() == 0 )
{ styxSource pSrc;
GLS_Lst(styxQlxDfn) pQDfns;
GLS_Lst(styxDfn) pDfns;
styxOptCfg pOptCfg;
GLS_Tok pIde;
// fill documentation base
styx_Start_Source(pStyDoc->pTree,&pSrc);
styxSource_root(pSrc,_,&pIde,&pQDfns,&pOptCfg);
SD_load_com(pStyDoc);
SD_load_lex(pQDfns,pStyDoc);
if( styxOptCfg_cfg(pOptCfg,&pDfns,_) && ! GLS_EMPTY(pDfns) )
{
pStyDoc->pTab = PLR_getTab_env(binpath,GLS_Tok_string(pIde));
if( pStyDoc->pTab != (PLR_Tab)NULL &&
acfg_init_doc(pStyDoc->pTab,
&pStyDoc->aPol,&pStyDoc->aNtm,&pStyDoc->aPrd) )
{
if( bConcreteCfg )
SD_load_ccfg(pStyDoc);
else
SD_load_cfg(pStyDoc);
return SD_load_pat(pStyDoc);
}
}
else
return SD_load_pat(pStyDoc);
}
return C_False;
}
static void SD_unload(StyDoc_T pStyDoc)
/* unload documentation base */
{ long lCnt = OT_CNT(pStyDoc->pDocBase)/2, lDom, lI;
MAPIT pItr; ROW(PT_Term) pRng;
if( pStyDoc->pTree != (PT_Term)NULL )
PT_delT(pStyDoc->pTree);
if( pStyDoc->pTab != (PLR_Tab)NULL )
{
acfg_quit(pStyDoc->pTab,pStyDoc->aPol,pStyDoc->aNtm,pStyDoc->aPrd);
PLR_delTab(pStyDoc->pTab);
}
MAP_forItrAsg(lDom,pRng,pItr,pStyDoc->pDfnCom)
OT_DEL_T(pRng);
MAP_freeMap(pStyDoc->pDfnCom);
MAP_forItrAsg(lDom,pRng,pItr,pStyDoc->pGrpCom)
OT_DEL_T(pRng);
MAP_freeMap(pStyDoc->pGrpCom);
MAP_freeMap(pStyDoc->pGMap);
MAP_freeMap(pStyDoc->pTMap);
MAP_freeMap(pStyDoc->pNTMap);
MAP_freeMap(pStyDoc->pClsMap);
HS_DROP_SET(pStyDoc->pLSet);
for( lI=0; lI < lCnt; ++lI )
OT_DEL_T(OT_GET(ROW(_),pStyDoc->pDocBase,2*lI+1));
OT_DEL_T(pStyDoc->pDocBase);
if( pStyDoc->pHPat != (HPat_T)NULL )
HP_drop(pStyDoc->pHPat);
FreeMem(pStyDoc);
}
/* ------------------------- Main ----------------------------------------- */
int main(int argc, c_string argv[])
{ StyDoc_T pStyDoc;
SD_init(argc,argv);
if( SD_load(&pStyDoc) )
{
// generate language documentation
if( strlen(outfile) > 0 )
pStyDoc->pSysOut = OpnFile(outfile,"wt");
else
pStyDoc->pSysOut = stdout;
if( pStyDoc->pHPat != (HPat_T)NULL )
SD_gendoc_cfg(pStyDoc->pHPat);
else SD_gendoc_raw(pStyDoc);
fclose(pStyDoc->pSysOut);
}
SD_unload(pStyDoc);
SD_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/pim2dot.cmd 0000666 0001750 0001750 00000001300 10373405111 012261 0000000 0000000 # [pim2dot.cmd] command description for pim2dot.c
Program pim2dot -- Parse table visualisation
doc
'pim2dot' converts a styx parse table [Language.pim] into the graph file language 'dot'.
The current version doesn't support the embedded language facility.
cod
Arguments
Img : path -- path of the parse table image [Language.pim]
Options
DiaType : string = "T" -- diagram type T=parse table (default), R=nonterminal relation, A=class relation
OutFile : path = "" -- path of the target file (default: stdout)
Template : path = "" -- path of the template file
doc
The template file can be used to specify default graph, node or edge attributes.
cod
Environment
styx-2.0.1/pgm/pgm_popt.h 0000666 0001750 0001750 00000000435 07572652761 012252 0000000 0000000 /* [pgm_popt.h] Common parse command line options */
#define start CTX_EVAL(c_string,"Start")
#define xaron CTX_EVAL(c_bool,"xaron")
#define early CTX_EVAL(c_bool,"early")
#define shiftfun CTX_EVAL(c_string,"shiftfun")
#define reducefun CTX_EVAL(c_string,"reducefun")
styx-2.0.1/pgm/pgm_popt.inc 0000666 0001750 0001750 00000000601 10161654632 012552 0000000 0000000 Start : string = "" -- start symbol
xaron : flag = false -- create a derivation tree ( lisp like representation )
early : flag = false -- use early reduction
shiftfun : string = "" -- user-defined token conversion: Function@Library ( see [ptm_gen] )
reducefun : string = "" -- user-defined nonterminal conversion: Function@Library ( see [ptm_gen] )
styx-2.0.1/pgm/pgm_arg.inc 0000666 0001750 0001750 00000000144 07572652761 012360 0000000 0000000 Language : name -- language name
FileName : path -- path of source file to scan
styx-2.0.1/pgm/ptm_img.cmd 0000666 0001750 0001750 00000001717 10373405111 012353 0000000 0000000 # [ptm_img.cmd] command description for ptm_img.c
Program ptm_img -- Term Put&Get
doc
'ptm_img' translates the given source file into a binary format and reverse.
In the reverse case it lists the derivation tree on stdout.
The source file must be conform with the language parameter. It uses the image files
of the parser and scanner tables, [Language.lim] and [Language.pim].
In case you specify a start symbol the parsing process starts from this nonterminal.
The symbol must be specified as valid start nonterminal in [Language.sty].
If the option is omitted the parser takes the first start nonterminal.
cod
Arguments
Language : name -- language name
Img : path -- path of the binary format
Options
FileName : path = "" -- path of source file to parse
#include pgm_sopt.inc
#include pgm_popt.inc
#include pgm_odoc.inc
Environment
BINSTYX : path = "PATH" -- search environment for [Language.pim] and [Language.lim]
styx-2.0.1/pgm/lim2dot.c 0000666 0001750 0001750 00000010373 10125554161 011753 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [lim2dot.c] Scanner table visualisation ( lim -> dot ) */
/* */
/* Copyright (c) 2004 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "hmap.h"
#include "pgm_base.h"
#include "scn_imp.h"
#include "gstream.h"
#include "line_scn.h"
#include "pathes.h"
#include "sink.h"
#include "lim2dot_cim.h"
#define imgfile CTX_EVAL(string,"Img")
#define tmplfile CTX_EVAL(string,"Template")
#define outfile CTX_EVAL(string,"OutFile")
static FILE* SysOut = NULL;
static void evalTemplate()
{
if( strlen(tmplfile) > 0 )
{ FILE* fp = OpnFile(tmplfile,"rb");
string line = Line_get(fp);
fprintf(SysOut,"\n");
while( line != NULL )
{
fprintf(SysOut,"%s\n",line);
FreeMem(line);
line = Line_get(fp);
}
fprintf(SysOut,"\n");
}
}
static void edgeCharacter(Sink snk, wc_char wc)
{ byte b = (byte)wc;
if( ((wc_char)b) == wc )
{
switch(b)
{
case '\r': Sink_printf(snk,"\\r"); break;
case '\n': Sink_printf(snk,"\\n"); break;
case '\t': Sink_printf(snk,"\\t"); break;
case '\\': Sink_printf(snk,"\\\\"); break;
case '"' : Sink_printf(snk,"\\\""); break;
default :
if( isprint(b) && b != ' ' )
Sink_printf(snk,"%c",b);
else Sink_printf(snk,"0x%02x",b);
}
}
else Sink_printf(snk,"0x%08lx",wc);
}
static c_string edgeLabel(MAP(wc_char,wc_char) edge)
{ Sink snk = Sink_open();
MAPIT itr; wc_char lwr, upr;
MAP_forItrAsg(lwr,upr,itr,edge)
{
if( lwr == upr )
{
Sink_printf(snk," ");
edgeCharacter(snk,lwr);
}
else
{
Sink_printf(snk," ");
edgeCharacter(snk,lwr);
Sink_printf(snk,"-");
edgeCharacter(snk,upr);
}
}
return Sink_close(snk);
}
static void scn2dot(scn_t scn)
{ long i, j, k, t;
for( i=0; i < scn->States; ++i )
{
for( k=0; k < scn->States; ++k )
{ MAP(wc_char,wc_char) edge = MAP_newPrimMap();
c_string lbl = NULL;
for( j=scn->StaEdg[i]; j < scn->StaEdg[i+1]; ++j )
{
if( k+1 == scn->EdgeS[j] ) // follow state = 0 ==> error
{ wc_char lwr = scn->EdgeC[j],
upr = j > scn->StaEdg[i] ? scn->EdgeC[j-1]-1 : lwr;
MAP_dfndom(edge,lwr,upr);
}
}
if( MAP_count(edge) > 0 )
{
lbl = edgeLabel(edge);
fprintf
(
SysOut,"\n node%ld -> node%ld [label=\"%s\"]", i,k,lbl
);
FreeMem(lbl);
}
MAP_freeMap(edge);
}
t = scn->StaFin[i];
if( t > 0 )
{
fprintf(SysOut,"\n node%ld [label=\"%s\",shape=box]",i,scn->TokId[t]);
}
else
if( i==0 )
{
fprintf(SysOut,"\n node0 [shape=box]");
}
}
}
static void lim2dot(scn_t scn)
{
fprintf(SysOut,"\ndigraph %s",scn->Name);
fprintf(SysOut,"\n{");
evalTemplate();
if( scn->Groups == 0 )
{
scn2dot(scn);
}
else
{ int i, j, g;
for( i=0; i < scn->Groups; ++i )
{
fprintf(SysOut,"\n subgraph %s",scn->GrpScn[i]->Name);
fprintf(SysOut,"\n {");
scn2dot(scn->GrpScn[i]);
fprintf(SysOut,"\n }\n");
}
for( i=0; i < scn->Groups; ++i )
{
for( j=0; i < scn->GrpScn[i]->Tokens; ++j )
{
g = scn->GrpScn[i]->Switch[j];
if( g >= 0 )
{
fprintf
(
SysOut,"\n %s -> %s [label=\"%s\"]",
scn->GrpScn[i]->Name,
scn->GrpScn[g]->Name,
scn->GrpScn[i]->TokId[j]
);
}
}
}
fprintf(SysOut,"\n %s [shape=box]",scn->Name);
}
fprintf(SysOut,"\n}\n");
}
int main(int argc, string argv[])
{ Scn_T scn;
/* init module */
PGM_init(argc,argv,CTX_init_lim2dot);
/* get the scanner */
Scn_get_file(imgfile,&scn);
/* produce the dot file */
if( strlen(outfile) > 0 )
SysOut = OpnFile(outfile,"wt");
else SysOut = stdout;
lim2dot(Scn_IMP(scn));
/* free the scanner */
Scn_free(scn);
/* quit module */
PGM_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/pgm_sopt.h 0000666 0001750 0001750 00000000506 07572652761 012254 0000000 0000000 /* [pgm_sopt.h] Common scan command line options */
#define prepar CTX_EVAL(c_string,"prepar")
#define premac CTX_EVAL(c_string,"premac")
#define prefun CTX_EVAL(c_string,"prefun")
#define cset CTX_EVAL(c_string,"charset")
#define skipset CTX_EVAL(c_string,"skipset")
#define wprint CTX_EVAL(c_bool,"wprint")
styx-2.0.1/pgm/lim_test.c 0000666 0001750 0001750 00000003007 10154060157 012214 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [lim_test.c] Scanner Test */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "pgm_base.h"
#include "pgm_sopt.h"
#include "lim__cim.h"
#define filename CTX_EVAL(string,"FileName")
#define binmode CTX_EVAL(bool,"binmode")
#define binpath CTX_EVAL(string,"BINSTYX")
int main(int argc, string argv[])
{ Scn_Stream stream; Scn_T scn;
/* init module */
PGM_init(argc,argv,CTX_init_lim_test);
/* init preprocessing */
PGM_initPreprocessing(prepar,premac,cset);
/* get the scanner */
Scn_get_env(binpath,CTX_EVAL(string,"Language"),&scn);
/* create & init scan stream */
stream = PGM_initScanStream
(
scn,filename,prepar,prefun,binmode,cset,
skipset,CTX_EVAL(bool,"lookahead"),True
);
/* actual scanning & printing */
PGM_scan(stream,CTX_EVAL(bool,"tokens"),cset,wprint);
/* quit scan stream */
PGM_quitScanStream(stream);
Scn_free(scn);
/* quit preprocessing */
PGM_quitPreprocessing(prepar);
/* print symbols */
if (CTX_EVAL(bool,"symbols")) { NL; printSymbols(0); NL; }
/* quit module */
PGM_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/Makefile.am 0000664 0001750 0001750 00000001106 10125536257 012267 0000000 0000000 ## Process this file with automake to create pgm/Makefile.in
vpath %.h $(top_srcdir)/modstd $(top_srcdir)/libutil $(top_srcdir)/libbase $(top_srcdir)/pgm $(top_srcdir)/modext $(top_srcdir)/inc
INCLUDES = -I$(top_srcdir)/modstd -I$(top_srcdir)/libutil -I$(top_srcdir)/libbase -I$(top_srcdir)/pgm -I$(top_srcdir)/modext -I$(top_srcdir)/inc
include_HEADERS = pgm_popt.h pgm_sopt.h
noinst_LIBRARIES = libpgm.a
libpgm_a_SOURCES = ctoh.c lim_test.c styx.c pim_test.c stypp.c stydoc.c ptm_img.c lim2dot.c pim2dot.c
EXTRA_DIST = $(wildcard $(srcdir)/*.cmd) $(wildcard $(srcdir)/*.inc)
styx-2.0.1/pgm/Makefile.in 0000644 0001750 0001750 00000043364 12116751125 012305 0000000 0000000 # Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
am__make_dryrun = \
{ \
am__dry=no; \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
| grep '^AM OK$$' >/dev/null || am__dry=yes;; \
*) \
for am__flg in $$MAKEFLAGS; do \
case $$am__flg in \
*=*|--*) ;; \
*n*) am__dry=yes; break;; \
esac; \
done;; \
esac; \
test $$am__dry = yes; \
}
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = pgm
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
LIBRARIES = $(noinst_LIBRARIES)
ARFLAGS = cru
libpgm_a_AR = $(AR) $(ARFLAGS)
libpgm_a_LIBADD =
am_libpgm_a_OBJECTS = ctoh.$(OBJEXT) lim_test.$(OBJEXT) styx.$(OBJEXT) \
pim_test.$(OBJEXT) stypp.$(OBJEXT) stydoc.$(OBJEXT) \
ptm_img.$(OBJEXT) lim2dot.$(OBJEXT) pim2dot.$(OBJEXT)
libpgm_a_OBJECTS = $(am_libpgm_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libpgm_a_SOURCES)
DIST_SOURCES = $(libpgm_a_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
am__install_max = 40
am__nobase_strip_setup = \
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
am__nobase_strip = \
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
am__nobase_list = $(am__nobase_strip_setup); \
for p in $$list; do echo "$$p $$p"; done | \
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
if (++n[$$2] == $(am__install_max)) \
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
END { for (dir in files) print dir, files[dir] }'
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(includedir)"
HEADERS = $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sampledir = @sampledir@
sbindir = @sbindir@
sgmldir = @sgmldir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
INCLUDES = -I$(top_srcdir)/modstd -I$(top_srcdir)/libutil -I$(top_srcdir)/libbase -I$(top_srcdir)/pgm -I$(top_srcdir)/modext -I$(top_srcdir)/inc
include_HEADERS = pgm_popt.h pgm_sopt.h
noinst_LIBRARIES = libpgm.a
libpgm_a_SOURCES = ctoh.c lim_test.c styx.c pim_test.c stypp.c stydoc.c ptm_img.c lim2dot.c pim2dot.c
EXTRA_DIST = $(wildcard $(srcdir)/*.cmd) $(wildcard $(srcdir)/*.inc)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign pgm/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign pgm/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
libpgm.a: $(libpgm_a_OBJECTS) $(libpgm_a_DEPENDENCIES) $(EXTRA_libpgm_a_DEPENDENCIES)
-rm -f libpgm.a
$(libpgm_a_AR) libpgm.a $(libpgm_a_OBJECTS) $(libpgm_a_LIBADD)
$(RANLIB) libpgm.a
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ctoh.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lim2dot.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lim_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pim2dot.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pim_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptm_img.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stydoc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stypp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/styx.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \
$(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \
fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES) $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am: install-includeHEADERS
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-includeHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool clean-noinstLIBRARIES ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-includeHEADERS install-info \
install-info-am install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-includeHEADERS
vpath %.h $(top_srcdir)/modstd $(top_srcdir)/libutil $(top_srcdir)/libbase $(top_srcdir)/pgm $(top_srcdir)/modext $(top_srcdir)/inc
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
styx-2.0.1/pgm/stypp.cmd 0000666 0001750 0001750 00000002075 10373405111 012074 0000000 0000000 # [stypp.cmd] command description for stypp.c
Program stypp -- Pretty Printer
doc
'stypp' serves as a pretty printer for source files written in a styx-conform language.
Beside that it can be used to port source files, provided that the abstract syntax of the
source and target language are equivalent. The conversion includes all comments. A user-defined
token conversion handler can be applied.
The work on this program, especially on the pretty printer layout, ist still in progress.
The current version doesn't support the embedded language facility.
cod
Arguments
srclang : name -- source language name
dstlang : name -- target language name
filename : path -- path of source file to transform
Options
#macro EXCLUDE_OPTION_BINMODE
#include pgm_sopt.inc
#include pgm_popt.inc
ppfun : string = "" -- user-defined token conversion: Function@Library ( see [ptm_pp] )
#include pgm_odoc.inc
Environment
BINSTYX : path = "PATH"
-- search environment for [srclang.pim], [srclang.lim], [dstlang.pim] and [dstlang.lim]
styx-2.0.1/pgm/lim2dot.cmd 0000666 0001750 0001750 00000001132 10373405111 012260 0000000 0000000 # [lim2dot.cmd] command description for lim2dot.c
Program lim2dot -- Scanner table visualisation
doc
'lim2dot' converts a styx scanner table [Language.lim] into the graph file language 'dot'.
The current version doesn't support the embedded language facility.
cod
Arguments
Img : path -- path of the scanner table image [Language.lim]
Options
OutFile : path = "" -- path of the target file (default: stdout)
Template : path = "" -- path of the template file
doc
The template file can be used to specify default graph, node or edge attributes.
cod
Environment
styx-2.0.1/libstyx/ 0000755 0001750 0001750 00000000000 12116751137 011224 5 0000000 0000000 styx-2.0.1/libstyx/styx_gen.c 0000666 0001750 0001750 00000357740 12116673413 013174 0000000 0000000 /* ------------------------------------------------------------------------- */
/* */
/* [styx_gen.c] STYX Compiler Library */
/* - realizes an abstract syntax tree - */
/* */
/* Copyright (c) 2002 by D\olle, Manns. */
/* ------------------------------------------------------------------------- */
#include "standard.h"
#include "scn_base.h"
#include "prs.h"
#include "hmap.h"
#include "symbols.h"
#include "pathes.h"
#include "literal.h"
#include "prs_gen.h"
#include "cfg_abs.h"
#include "ptm.h"
#include "ptm_gen.h"
#include "gls.h"
#include "hset.h"
#include "scn_gen.h"
#include "scn_pre.h"
#include "sink.h"
#include "gstream.h"
#include "styx_int.h"
#include "styx_lim.h"
#include "styx_pim.h"
/*!!
The module [styx_gen] provides an reentrant interface for the compilation of
STYX definitions.
*/
/*I-------------------------- Types and macros ------------------------------ */
/* Scanner & parser translation */
#define UsageLet -100
#define UsageIgn 1
#define UsageTok 2
#define UsageCom 3
#define UsageLan 4
#define UsageInd 5
#define InitialGroup stringToSymbol("_INIT_")
#define RootCtx(c) ( ((c)->root == (Styx_T)NULL) ? (c) : (c)->root )
/* Interface generation */
#define INTEXT "int" /* FileNames will be LANGUAGE_INTEXT.(c|h) */
#define ANTEXT "ant" /* FileNames will be LANGUAGE_ANTEXT.(c|h) */
#define LineLen 78
ExternalType( StyxApp_T ) /* Abstract STYX application type */
{
PLR_Tab PTab; /* STYX Parse table */
Scn_T Scn; /* STYX Scan table */
};
ExternalType( Styx_T ) /* Abstract STYX compiler type */
{
StyxApp_T styapp; /* STYX application configuration */
/* STYX compilation configuration */
c_bool verbose; /* print progress information */
c_bool diagnose; /* print diagnose information */
c_bool conflicts; /* allow conflicts ? */
/* Parsing & semantic check of STYX definition */
c_string language; /* STYX language */
int version; /* STYX version (default=0) */
symbol incpath; /* STYX include & embedded path */
PT_Term PTree; /* Source derivation tree */
PT_Diag diag; /* Diagnose context */
MAPTY gloty; /* Type for global definitions */
MAP(PT_Term, PT_Term) glo; /* Global definitions */
MAP(symbol,PT_Term) grp; /* Scan groups */
MAP(GLS_Tok,symbol) grptok; /* Scan group tokens */
MAP(symbol,int) dyntok; /* Dynamic token references */
MAP(symbol,symbol) langrp; /* Embedded language token group */
MAP(GLS_Tok,symbol) tokgrp; /* Token --> group to activate */
MAP(PT_Term,symbol) ebnfmbr; /* EBNF production member */
int ebnfcnt; /* number of EBNF nonterminals */
MAP(symbol,SET(symbol)) metagrp; /* meta group --> token groups */
MAP(GLS_Tok,byte) tokflg; /* special token flags */
Styx_T root; /* Main language */
MAP(symbol,Styx_T) embed; /* Embedded languages */
c_string (*ef_info)(Styx_T styctx,c_string language, c_string incpath);
/* Embedded language path / definition retrieval function */
int (*ef_compile)(Styx_T styctx, c_string e_info, c_string incpath);
/* Embedded language path / definition compile function */
Any_T extctx; /* external context */
HS_Set tkset; /* Used tokens */
MAP(symbol,_) indtokkeys; /* (de)indent token keywords */
int errorCnt; /* number of translation errors */
/* Scanner translation */
MAP(GLS_Tok,RegSet_T) qlx; /* Computed RegSets */
/* Scan & parse table generation */
PLR_Tab PTab; /* Parse table */
Scn_T Scn; /* Scan table */
/* abstract syntax data structure ( see comments in cfg_abs.c ) */
int* aPol;
HS_Set* aNtm;
HS_Set* aPrd;
/* Interface generation */
FILE* SysOut; /* Interface output file */
c_bool genabs;
/* True: generate for row representation */
int maxlen;
/* Layout: maximal function name length */
c_string tkclsnam; /* Token class name */
c_string lprefix; /* Language prefix */
c_string cprefix; /* comment prefix */
c_string csuffix; /* comment suffix */
};
/*I----------------------------- Init & Quit --------------------------------- */
StyxApp_T STYX_app_init(void)
/* init STYX application */
{ StyxApp_T styapp;
initSymbols();
MAP_init();
styx_initSymbols();
styapp = New(StyxApp_T);
Scn_get_styx(&styapp->Scn);
styapp->PTab = PLR_get_styx();
return styapp;
}
void STYX_app_quit(StyxApp_T styapp)
/* quit STYX application; release resources */
{
if( styapp != (StyxApp_T)NULL )
{
if( styapp->PTab != (PLR_Tab)NULL )
{
PLR_delTab(styapp->PTab);
styapp->PTab = (PLR_Tab)NULL;
}
if( styapp->Scn != (Scn_T)NULL )
{
Scn_free(styapp->Scn);
styapp->Scn = (Scn_T)NULL;
}
FreeMem(styapp);
}
styx_quitSymbols();
MAP_quit();
freeSymbols();
}
/*forward*/ void STYX_quit(Styx_T styctx);
/*forward*/ int STYX_compile_file
(
Styx_T styctx, c_string stydfn, c_string incpath
);
/*forward*/ int STYX_compile_string
(
Styx_T styctx, c_string stydfn, c_string incpath
);
static void STYX_reset(Styx_T styctx)
{
styctx->errorCnt = 0;
styctx->SysOut = (FILE*)NULL;
styctx->genabs = C_False;
styctx->maxlen = 0;
styctx->version = 0;
if( styctx->embed != (MAP(_,_))NULL )
{
if( MAP_count(styctx->embed) > 0 )
{ MAPIT itr; Styx_T rng; symbol dom;
ROW(Styx_T) tmp = OT_CREATE_ADT(Styx_T);
long cnt, i;
MAP_forItrAsg(dom,rng,itr,styctx->embed)
{
if( !strcmp(symbolToString(dom),rng->language) )
OT_PUSH(rng,tmp);
}
cnt = OT_CNT(tmp);
for( i=0; i < cnt; ++i )
STYX_quit(OT_GET(Styx_T,tmp,i));
OT_DEL_T(tmp);
}
MAP_freeMap(styctx->embed);
styctx->embed = (MAP(_,_))NULL;
}
if( styctx->grp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->grp);
styctx->grp = (MAP(_,_))NULL;
}
if( styctx->grptok != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->grptok);
styctx->grptok = (MAP(_,_))NULL;
}
if( styctx->dyntok != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->dyntok);
styctx->dyntok = (MAP(_,_))NULL;
}
if( styctx->langrp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->langrp);
styctx->langrp = (MAP(_,_))NULL;
}
if( styctx->tokgrp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->tokgrp);
styctx->tokgrp = (MAP(_,_))NULL;
}
if( styctx->ebnfmbr != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->ebnfmbr);
styctx->ebnfmbr = (MAP(_,_))NULL;
}
styctx->ebnfcnt = 0;
if( styctx->metagrp != (MAP(_,_))NULL )
{ MAPIT itr; SET(symbol) rng; symbol dom;
MAP_forItrAsg(dom,rng,itr,styctx->metagrp)
HS_DROP_SET(rng);
MAP_freeMap(styctx->metagrp);
styctx->metagrp = (MAP(_,_))NULL;
}
if( styctx->tokflg != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->tokflg);
styctx->tokflg = (MAP(_,_))NULL;
}
if( styctx->glo != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->glo);
styctx->glo = (MAP(_,_))NULL;
}
if( styctx->qlx != (MAP(_,_))NULL )
{ MAPIT itr; RegSet_T rng; symbol dom;
MAP_forItrAsg(dom,rng,itr,styctx->qlx)
RegSet_Free(rng);
MAP_freeMap(styctx->qlx);
styctx->qlx = (MAP(_,_))NULL;
}
if( styctx->indtokkeys != (MAP(symbol,_))NULL )
{
MAP_freeMap(styctx->indtokkeys);
styctx->indtokkeys = (MAP(symbol,_))NULL;
}
if( styctx->gloty != (MAPTY)NULL )
{
MAP_freeTyp(styctx->gloty);
styctx->gloty = (MAPTY)NULL;
}
if( styctx->tkset != (HS_Set)NULL )
{
HS_DROP_SET(styctx->tkset);
styctx->tkset = (HS_Set)NULL;
}
if( styctx->PTree != (PT_Term)NULL )
{
PT_delT(styctx->PTree);
styctx->PTree = (PT_Term)NULL;
}
if( styctx->PTab != (PLR_Tab)NULL )
{
acfg_quit(styctx->PTab,styctx->aPol,styctx->aNtm,styctx->aPrd);
PLR_delTab(styctx->PTab);
styctx->PTab = (PLR_Tab)NULL;
styctx->aPol = (int*)NULL;
styctx->aNtm = (HS_Set*)NULL;
styctx->aPrd = (HS_Set*)NULL;
}
if( styctx->Scn != (Scn_T)NULL )
{
Scn_free(styctx->Scn);
styctx->Scn = (Scn_T)NULL;
}
if( styctx->cprefix != (c_string)NULL )
{
FreeMem(styctx->cprefix);
styctx->cprefix = (c_string)NULL;
}
if( styctx->csuffix != (c_string)NULL )
{
FreeMem(styctx->csuffix);
styctx->csuffix = (c_string)NULL;
}
if( styctx->diag != (PT_Diag)NULL )
{
PT_diag_setErrorCnt(styctx->diag,0);
PT_diag_setWarningCnt(styctx->diag,0);
}
}
Styx_T STYX_init
(
StyxApp_T styapp, c_string language,
void (*prMsg)(c_string msg), c_bool verbose, c_bool diagnose
)
/* init STYX compilation for 'language';
'prMsg' --> print function or NULL
'verbose' --> (de)activate progress information
'diagnose' --> (de)activate diagnose information
*/
{ Styx_T styctx;
BUG_NULL(styapp); BUG_NULL(language);
styctx = New(Styx_T);
styctx->root = (Styx_T)NULL;
styctx->styapp = styapp;
styctx->verbose = verbose;
styctx->diagnose = diagnose;
styctx->conflicts = C_True;
styctx->language = StrCopy(language);
styctx->version = 0;
styctx->incpath = (symbol)NULL;
styctx->diag = PT_diag_init(prMsg!=NULL?prMsg:prMsg_stderr);
styctx->PTree = (PT_Term)NULL;
styctx->gloty = (MAPTY)NULL;
styctx->glo = (MAP(_,_))NULL;
styctx->embed = (MAP(_,_))NULL;
styctx->ef_info =
(c_string (*)(Styx_T styctx,c_string language,c_string incpath))NULL;
styctx->ef_compile = STYX_compile_file;
styctx->extctx = (Any_T)NULL;
styctx->grp = (MAP(_,_))NULL;
styctx->grptok = (MAP(_,_))NULL;
styctx->dyntok = (MAP(_,_))NULL;
styctx->langrp = (MAP(_,_))NULL;
styctx->tokgrp = (MAP(_,_))NULL;
styctx->ebnfmbr = (MAP(_,_))NULL;
styctx->ebnfcnt = 0;
styctx->metagrp = (MAP(_,_))NULL;
styctx->tokflg = (MAP(_,_))NULL;
styctx->tkset = (HS_Set)NULL;
styctx->indtokkeys = (MAP(symbol,_))NULL;
styctx->errorCnt = 0;
styctx->qlx = (MAP(_,_))NULL;
styctx->PTab = (PLR_Tab)NULL;
styctx->Scn = (Scn_T)NULL;
styctx->aPol = (int*)NULL;
styctx->aNtm = (HS_Set*)NULL;
styctx->aPrd = (HS_Set*)NULL;
styctx->SysOut = (FILE*)NULL;
styctx->genabs = C_False;
styctx->maxlen = 0;
styctx->tkclsnam = Str_printf("T%s",language);
styctx->lprefix = StrCopy(language);
styctx->cprefix = (c_string)NULL;
styctx->csuffix = (c_string)NULL;
return styctx;
}
void STYX_quit(Styx_T styctx)
/* quit STYX compilation; release resources */
{
if(styctx != (Styx_T)NULL )
{
STYX_reset(styctx);
if( styctx->language != (c_string)NULL )
{
FreeMem(styctx->language);
styctx->language = (c_string)NULL;
}
if( styctx->lprefix != (c_string)NULL )
{
FreeMem(styctx->lprefix);
styctx->lprefix = (c_string)NULL;
}
if( styctx->tkclsnam != (c_string)NULL )
{
FreeMem(styctx->tkclsnam);
styctx->tkclsnam = (c_string)NULL;
}
if( styctx->diag != (PT_Diag)NULL )
{
PT_diag_quit(styctx->diag);
styctx->diag = (PT_Diag)NULL;
}
FreeMem(styctx);
}
}
/*I----------------------------- Set & Get ----------------------------------- */
void STYX_set_conflict_policy(Styx_T styctx, c_bool conflicts)
/* (dis)allow conflicts during parse table generation */
{
BUG_NULL(styctx);
styctx->conflicts = conflicts;
}
void STYX_set_verbose(Styx_T styctx, c_bool verbose)
/* (de)activate progress information */
{
BUG_NULL(styctx);
styctx->verbose = verbose;
}
void STYX_set_diagnose(Styx_T styctx, c_bool diagnose)
/* (de)activate diagnose information */
{
BUG_NULL(styctx);
styctx->diagnose = diagnose;
}
void STYX_set_shortform(Styx_T styctx, c_bool shortform)
/* (de)activate short filenames ( default: longform ) */
{
BUG_NULL(styctx);
if( styctx->lprefix != (c_string)NULL ) FreeMem(styctx->lprefix);
if( shortform )
styctx->lprefix = Str_printf("%.4s",styctx->language);
else
styctx->lprefix = StrCopy(styctx->language);
if( styctx->tkclsnam != (c_string)NULL ) FreeMem(styctx->tkclsnam);
if( shortform )
styctx->tkclsnam = Str_printf("T%.4s",styctx->language);
else
styctx->tkclsnam = Str_printf("T%s",styctx->language);
}
void STYX_set_context(Styx_T styctx, Any_T extctx)
/* set external context information */
{
BUG_NULL(styctx);
assert0(RootCtx(styctx) == styctx,"");
styctx->extctx = extctx;
}
Any_T STYX_get_context(Styx_T styctx)
/* get external context information */
{
BUG_NULL(styctx);
return RootCtx(styctx)->extctx;
}
void STYX_set_fun_epath
(
Styx_T styctx,
c_string (*ef_path)(Styx_T styctx, c_string language, c_string incpath)
)
/* (re)set embedded language path retrieval function */
{
BUG_NULL(styctx);
assert0(RootCtx(styctx) == styctx,"");
styctx->ef_info = ef_path;
styctx->ef_compile = STYX_compile_file;
}
void STYX_set_fun_edfn
(
Styx_T styctx,
c_string (*ef_dfn)(Styx_T styctx, c_string language, c_string incpath)
)
/* (re)set embedded language definition retrieval function */
{
if( ef_dfn == NULL )
STYX_set_fun_epath(styctx,ef_dfn);
else
{
BUG_NULL(styctx);
assert0(RootCtx(styctx) == styctx,"");
styctx->ef_info = ef_dfn;
styctx->ef_compile = STYX_compile_string;
}
}
MAP(symbol,Styx_T) STYX_get_embed(Styx_T styctx)
/* STYX compilations of embedded languages or NULL;
The result map has to be released.
*/
{ MAP(symbol,Styx_T) embed = (MAP(_,_))NULL;
if( MAP_count(styctx->embed) > 0 )
{ MAPIT itr; Styx_T rng; symbol dom;
embed = MAP_newPrimMap();
MAP_forItrAsg(dom,rng,itr,styctx->embed)
{
if( !strcmp(symbolToString(dom),rng->language) )
MAP_dfndom(embed,dom,rng);
}
}
return embed;
}
void STYX_get_tables(Styx_T styctx, PLR_Tab* PTab, Scn_T* Scn)
/* get scan & parse table */
{
BUG_NULL(styctx);
if( PTab != (PLR_Tab*)NULL )
*PTab = styctx->PTab;
if( Scn != (Scn_T*)NULL )
*Scn = styctx->Scn;
}
/*I----------------------------- Compilation --------------------------------- */
/* semantic check */
static c_bool pop_group(Styx_T styctx, styxQlxGrp grp)
{
return styxQlxGrp_pop(grp);
}
static c_bool push_group(Styx_T styctx, styxQlxGrp grp)
{
return styxQlxGrp_pigrp(grp) || styxQlxGrp_pgrp(grp,_);
}
static void getGroupInfo
(
Styx_T styctx, styxQlxGrp grp,
symbol* grpsym, c_bool prError
)
{ GLS_Tok id;
if( grpsym != (symbol*)NULL )
*grpsym = (symbol)NULL;
if( styxQlxGrp_grp(grp,&id) || styxQlxGrp_pgrp(grp,&id) )
{
if( !MAP_defined(styctx->grp,GLS_Tok_symbol(id)) )
{
if( prError )
PT_diag_err
(
id,styctx->diag,"identifier '%s' undefined",
GLS_Tok_string(id)
);
}
else
{
if( grpsym != (symbol*)NULL )
*grpsym = GLS_Tok_symbol(id);
}
}
else
if( styxQlxGrp_igrp(grp) || styxQlxGrp_pigrp(grp) )
{
if( grpsym != (symbol*)NULL )
*grpsym = InitialGroup;
}
}
static void addTokenFlag(Styx_T styctx, GLS_Tok id, byte f)
{
if( MAP_defined(styctx->tokflg,id) )
f |= MAP_apply_small(byte,styctx->tokflg,id);
MAP_ovrdom(styctx->tokflg,id,f);
}
static PT_Term getDfn(Styx_T styctx, GLS_Tok id, c_bool force)
{ Styx_T rootctx = RootCtx(styctx);
if(MAP_defined(styctx->glo,id))
return MAP_apply(PT_Term,styctx->glo,id);
else
{
if( MAP_defined(rootctx->embed,GLS_Tok_symbol(id)) )
return MAP_apply(PT_Term,styctx->grp,GLS_Tok_symbol(id));
}
if( force == C_True ) C_BUG;
return (PT_Term)NULL;
}
static int qlx_usage(Styx_T styctx, PT_Term t)
{ styxQlxCat cat;
if (styx_QlxDfn(t,_) )
styxQlxDfn_defn((styxQlxDfn)t,&cat,_,_,_,_,_);
else
styxQlxDfn_defn((styxQlxDfn)getDfn(styctx,t,C_True),&cat,_,_,_,_,_);
if (styxQlxCat_letC(cat)) return UsageLet;
if (styxQlxCat_tokC(cat)) return UsageTok;
if (styxQlxCat_comC(cat)) return UsageCom;
if (styxQlxCat_ignC(cat)) return UsageIgn;
if (styxQlxCat_lanC(cat)) return UsageLan;
if (styxQlxCat_indC(cat)) return UsageInd;
C_BUG; return 0;
}
static c_bool qlx_quotient(Styx_T styctx, GLS_Tok id)
{ styxExp exp;
styxQlxDfn qd = (styxQlxDfn)getDfn(styctx,id,C_True);
if( !styxQlxDfn_defn(qd,_,_,_,_,_,&exp) )
return C_False;
return styxExp_quot(exp,_,_);
}
static c_bool qlx_dyck(Styx_T styctx, GLS_Tok id)
{ styxExp exp;
styxQlxDfn qd = (styxQlxDfn)getDfn(styctx,id,C_True);
if( !styxQlxDfn_defn(qd,_,_,_,_,_,&exp) )
return C_False;
if( styxExp_quot(exp,&exp,_) )
/* noop */;
return styxExp_dyck(exp,_,_,_);
}
static c_bool qlx_pattern(Styx_T styctx, GLS_Tok id)
{ styxExp exp;
styxQlxDfn qd = (styxQlxDfn)getDfn(styctx,id,C_True);
if( !styxQlxDfn_defn(qd,_,_,_,_,_,&exp) )
return C_False;
if( styxExp_quot(exp,&exp,_) )
/* noop */;
return styxExp_spat(exp,_,_,_) || styxExp_epat(exp,_,_,_);
}
static c_bool qlx_ica(Styx_T styctx, GLS_Tok id)
{ styxQlxOpt opt;
styxQlxDfn qd = (styxQlxDfn)getDfn(styctx,id,C_True);
if( !styxQlxDfn_defn(qd,_,&opt,_,_,_,_) )
return C_False;
return styxQlxOpt_ignca(opt);
}
static void Pass1(Styx_T styctx, styxSource s)
/* Collecting definitions and scoping rules */
{ Styx_T lanctx, rootctx; bool startflg = False;
int indcnt = 0, dyncnt = 0, rc;
MAP(PT_Term,NULL) pro = MAP_newMap(styctx->gloty); /* Productions */
PT_Itr it; styxOptCfg optcfg; GLS_Lst(styxDfn) dfns;
rootctx = RootCtx(styctx);
styxSource_root(s,_,_,_,&optcfg);
/* set initial group */
MAP_dfndom(styctx->grp,InitialGroup,(PT_Term)NULL);
/* collect definitions */
PT_FORALL(it,s)
{ PT_Term t = PT_termIT(it), st = (PT_Term)NULL;
if (PT_stateIT(it) == PT_POST)
{ styxQlxDfn qd; styxDfn pd; styxPrd p; GLS_Tok id, sgid, dgid;
styxMbr mbr;
/* Scope(Source): all identifiers in QLX definitions */
if (styx_QlxDfn(t,&qd) )
{ styxQlxOpt o; styxQlxCat c; styxQlxGrp gsrc, gdst; styxExp e, e1;
if( styxQlxDfn_igrp(qd,&id) || styxQlxDfn_xgrp(qd,&id) ||
styxQlxDfn_tgrp(qd,&id) ||
styxQlxDfn_mgrp(qd,&id,_) )
{ GLS_Lst(GLS_Tok) ids, lst;
if (MAP_defined(styctx->grp,GLS_Tok_symbol(id)) ||
!strcmp(styctx->language,GLS_Tok_string(id)))
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
GLS_Tok_string(id)
);
else
{
MAP_dfndom(styctx->grp,GLS_Tok_symbol(id),qd);
if( styxQlxDfn_mgrp(qd,_,&ids) )
{ SET(symbol) grpset = HS_CREATE_ADTSET(symbol);
MAP_dfndom(styctx->metagrp,GLS_Tok_symbol(id),grpset);
GLS_FORALL(lst,ids)
{ GLS_Tok grpid = GLS_FIRST(GLS_Tok,lst);
if( !strcmp(styctx->language,GLS_Tok_string(grpid)) )
HS_SET_ELM(InitialGroup,grpset);
else
if( !MAP_defined(styctx->grp,GLS_Tok_symbol(grpid)) )
PT_diag_err
(
grpid,styctx->diag,"undefined identifier '%s'",
GLS_Tok_string(grpid)
);
else
if( MAP_defined(styctx->metagrp,GLS_Tok_symbol(grpid)) )
PT_diag_err(grpid,styctx->diag,"invalid group");
else
HS_SET_ELM(GLS_Tok_symbol(grpid),grpset);
}
}
}
}
else
if ( styxQlxDfn_defn(qd,&c,&o,&gsrc,&id,&gdst,&e) )
{
if( !styxQlxCat_lanC(c) && MAP_defined(styctx->glo,id))
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
GLS_Tok_string(id)
);
else
{
if( !styxQlxCat_lanC(c) )
MAP_dfndom(styctx->glo,id,qd);
if( styxQlxCat_letC(c) )
{
if( !styxQlxGrp_non(gsrc) || !styxQlxGrp_non(gdst) )
PT_diag_err(qd,styctx->diag,"grouping not allowed here");
}
else
if( styxQlxCat_lanC(c) )
{
if( !(styxQlxGrp_grp(gsrc,&sgid) && styxQlxGrp_grp(gdst,&dgid)) )
PT_diag_err
(
qd,styctx->diag,"invalid or incomplete embedded language specification"
);
else
{ c_string lantok, lanpath; symbol lansym;
lantok = Str_printf
(
"%s%s",GLS_Tok_string(sgid),GLS_Tok_string(id)
);
lansym = stringToSymbol(lantok);
if( MAP_defined(styctx->grp,lansym) )
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
symbolToString(lansym)
);
else
{ styxCat c;
MAP_dfndom(styctx->grp,lansym,qd);
if( !MAP_defined(rootctx->embed,GLS_Tok_symbol(sgid)) )
{ c_string incpath = symbolToString(styctx->incpath);
lanctx = STYX_init
(
styctx->styapp, GLS_Tok_string(sgid),
PT_diag_msgFun(styctx->diag),
styctx->verbose, styctx->diagnose
);
lanctx->root = rootctx;
MAP_dfndom(rootctx->embed,GLS_Tok_symbol(sgid),lanctx);
MAP_ovrdom(rootctx->embed,lansym,lanctx);
if( rootctx->ef_info != NULL )
lanpath =
(*rootctx->ef_info)(styctx,GLS_Tok_string(sgid),incpath);
else
lanpath = MkPath(incpath,GLS_Tok_string(sgid),".sty",'p');
rc = (*rootctx->ef_compile)(lanctx,lanpath,incpath);
if( rc != 0 )
PT_diag_err
(
qd,styctx->diag,
"compilation of embedded language '%s' failed",
GLS_Tok_string(sgid)
);
FreeMem(lanpath);
}
else
{
lanctx = MAP_apply(Styx_T,rootctx->embed,GLS_Tok_symbol(sgid));
MAP_ovrdom(rootctx->embed,lansym,lanctx);
if( lanctx->qlx == (MAP(_,_))NULL )
PT_diag_err
(
qd,styctx->diag,
"cyclic referenced embedded language '%s'",
GLS_Tok_string(sgid)
);
}
if( strcmp(styctx->language,GLS_Tok_string(dgid)) &&
strcmp(lanctx->language,GLS_Tok_string(dgid)) )
PT_diag_err
(
dgid,styctx->diag,
"unknown EOF or follow token language '%s'",
GLS_Tok_string(dgid)
);
if( MAP_defined(lanctx->glo,id) )
st = MAP_apply(PT_Term,lanctx->glo,id);
if( st != (PT_Term)NULL &&
( !styx_Dfn(st,&pd) ||
!styxDfn_defn(pd,&c,_,_,_) || !styxCat_bgnC(c) ) )
PT_diag_err
(
id,styctx->diag,
"start symbol '%s' doesn't exist in language '%s'",
GLS_Tok_string(id), GLS_Tok_string(sgid)
);
}
FreeMem(lantok);
}
}
else
{ symbol srcsym = (symbol)NULL,
dstsym = (symbol)NULL;
getGroupInfo(styctx,gsrc,&srcsym,C_True);
if( srcsym == (symbol)NULL )
srcsym = InitialGroup;
MAP_dfndom(styctx->grptok,id,srcsym);
if( MAP_defined(rootctx->embed,srcsym) )
PT_diag_err(gsrc,styctx->diag,"invalid group or group list");
getGroupInfo(styctx,gdst,&dstsym,C_True);
if( MAP_defined(styctx->metagrp,dstsym) )
PT_diag_err(gdst,styctx->diag,"invalid group");
else
if( dstsym != (symbol)NULL )
{
MAP_ovrdom(styctx->tokgrp,id,dstsym);
}
if( push_group(styctx,gdst) || pop_group(styctx,gdst) )
{
addTokenFlag(styctx,id,SCN_FLG_GroupStack);
if( styxExp_spat(e,_,_,_) ||
( styxExp_quot(e,&e1,_) && styxExp_spat(e1,_,_,_) ) )
PT_diag_err(c,styctx->diag,"push/pop group not allowed here");
}
if( MAP_defined(rootctx->embed,dstsym) )
{
addTokenFlag(styctx,id,SCN_FLG_SwitchToken);
if( MAP_defined(styctx->langrp,dstsym) )
{
if( MAP_apply(symbol,styctx->langrp,dstsym) != srcsym )
PT_diag_err
(
gsrc,styctx->diag,
"different embedded language token group '%s'",
symbolToString(srcsym)
);
}
else
{
MAP_dfndom(styctx->langrp,dstsym,srcsym);
}
if( push_group(styctx,gdst) )
PT_diag_err(c,styctx->diag,"push group not allowed here");
if( ! styxQlxCat_tokC(c) && ! styxQlxCat_comC(c) )
PT_diag_err(c,styctx->diag,"invalid switch token category");
}
}
}
/* quotient expression must be set or sequence */
if( styxExp_quot(e,_,&e1) &&
!( styxExp_set(e1,_) || styxExp_sequ(e1,_) ) )
PT_diag_err
(
e1,styctx->diag,"quotient expression must be set or sequence"
);
/* CaseIgnore only with categories tok, com */
if( styxQlxOpt_ignca(o) &&
! styxQlxCat_tokC(c) &&
! styxQlxCat_comC(c) )
PT_diag_err(o,styctx->diag,"CaseIgnore not allowed here");
/* dyck, pattern not with categories let, lan, ind */
if( (styxExp_quot(e,_,_) || styxExp_dyck(e,_,_,_) ||
styxExp_spat(e,_,_,_) || styxExp_epat(e,_,_,_)) &&
(styxQlxCat_letC(c) || styxQlxCat_lanC(c) || styxQlxCat_indC(c)) )
PT_diag_err(e,styctx->diag,"quotient, dyck or pattern token definition not allowed here");
/* pattern not with category ign */
if( (styxExp_quot(e,_,_) || styxExp_spat(e,_,_,_) || styxExp_epat(e,_,_,_)) &&
styxQlxCat_ignC(c) )
PT_diag_err(e,styctx->diag,"quotient or pattern token definition not allowed here");
/* maximal 1 (de)indent token per scanner (group) */
indcnt += styxQlxCat_indC(c);
if( indcnt > 1 )
PT_diag_err(o,styctx->diag,"too many (de)indent tokens");
}
else
if ( styxQlxDfn_defd(qd,&id) )
{
if( MAP_defined(styctx->glo,id))
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
GLS_Tok_string(id)
);
else
{
MAP_dfndom(styctx->glo,id,qd);
MAP_dfndom(styctx->dyntok,GLS_Tok_symbol(id),0);
}
}
}
/* Scope(Source): all identifiers in CFG definitions */
if (styx_Dfn(t,&pd))
{ styxCat c; styxDfnOpt o;
if ( styxDfn_defn(pd,&c,&o,&id,_) )
{
if (MAP_defined(styctx->glo,id))
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
symbolToString(GLS_Tok_symbol(id))
);
else MAP_dfndom(styctx->glo,id,pd);
if (MAP_emptyMap(pro))
PT_diag_err
(
id,styctx->diag,"production '%s' has no rules",
GLS_Tok_string(id)
);
MAP_rmvall(pro);
startflg |= styxCat_bgnC(c);
}
}
/* Scope(Definition): all production identifiers */
if (styx_Prd(t,&p))
{
dyncnt = 0;
if ( styxPrd_prod(p,_,&id,_) )
{
if (MAP_defined(pro,id))
PT_diag_err
(
id,styctx->diag,"identifier '%s' already defined",
GLS_Tok_string(id)
);
else MAP_dfndom(pro,id,NULL);
}
}
if (styx_Mbr(t,&mbr) )
{
if( styxMbr_dtok(mbr,_,_) )
++dyncnt;
if( dyncnt == 2 )
PT_diag_err
(
mbr,styctx->diag,"production with more than one dynamic token members"
);
}
}
}
if( ! startflg && styxOptCfg_cfg(optcfg,&dfns,_) && ! GLS_EMPTY(dfns) )
PT_diag_err(dfns,styctx->diag,"missing start production");
MAP_freeMap(pro);
}
static int Pass2_checkMbrIde(Styx_T styctx, GLS_Tok id, GLS_Lst(styxQlxDfn) qlxdfns)
/* check wether production or conflict member 'id' is a defined token or nonterminal
rc = -1 (unknown), 0 (token), 1 (nonterminal), 2 (embedded language token)
*/
{
Styx_T rootctx = RootCtx(styctx);
if (!MAP_defined(styctx->glo,id) &&
!MAP_defined(rootctx->embed,GLS_Tok_symbol(id)))
{
if( GLS_EMPTY(qlxdfns) )
{
return 0;
}
}
else
if (MAP_defined(styctx->glo,id))
{ PT_Term def = MAP_apply(PT_Term,styctx->glo,id);
styxQlxDfn qd; styxQlxCat qc;
if( ! ( styx_Dfn(def,_) ||
( styx_QlxDfn(def,&qd) &&
( styxQlxDfn_defd(qd,_) ||
styxQlxDfn_defn(qd,&qc,_,_,_,_,_) &&
(styxQlxCat_tokC(qc) || styxQlxCat_lanC(qc)) ) ) ) )
{
PT_diag_err
(
id,styctx->diag,"invalid production member symbol '%s'",GLS_Tok_string(id)
);
return -1;
}
return styx_Dfn(def,_) ? 1 : 0;
}
else
if( MAP_defined(styctx->grp,GLS_Tok_symbol(id)) )
{
return 2;
}
PT_diag_err
(
id,styctx->diag,"undefined grammar symbol '%s'",GLS_Tok_string(id)
);
return -1;
}
static void Pass2_checkMbr(Styx_T styctx, styxMbr m, GLS_Lst(styxQlxDfn) qlxdfns)
/* check production member 'm' (Pass2) */
{ GLS_Tok id, did; int rc, flg;
if ( styxMbr_ntm(m,&id) )
{
rc = Pass2_checkMbrIde(styctx,id,qlxdfns);
if( rc == 0 && MAP_defined(styctx->dyntok,GLS_Tok_symbol(id)) )
{
flg = MAP_apply(int,styctx->dyntok,GLS_Tok_symbol(id));
flg |= 2;
MAP_upddom(styctx->dyntok,GLS_Tok_symbol(id),(long)flg);
}
}
else
if ( styxMbr_dtok(m,&id,&did) )
{
rc = Pass2_checkMbrIde(styctx,id,qlxdfns);
if( rc == 1 || rc == 2 ||
MAP_defined(styctx->dyntok,GLS_Tok_symbol(id)) )
{
PT_diag_err
(
id,styctx->diag,"expected token '%s'",GLS_Tok_string(id)
);
}
if( !MAP_defined(styctx->dyntok,GLS_Tok_symbol(did)) )
{
PT_diag_err
(
did,styctx->diag,"undefined dynamic token '%s'",GLS_Tok_string(did)
);
}
else
{
flg = MAP_apply(int,styctx->dyntok,GLS_Tok_symbol(did));
flg |= 1;
MAP_upddom(styctx->dyntok,GLS_Tok_symbol(did),(long)flg);
}
}
else
{ styxMbr em;
if( styxMbr_klst0(m,_,&em,_,_) ||
styxMbr_klst1(m,_,&em,_,_) || styxMbr_opt(m,_,&em,_) )
{
Pass2_checkMbr(styctx,em,qlxdfns);
}
}
}
static void Pass2_checkConflict
(
Styx_T styctx, styxConflict conflict,
GLS_Lst(styxQlxDfn) qlxdfns
)
/* check wether conflict token, state and rules refer to defined
token, nonterminals and productions.
*/
{ styxState state; styxToken token; GLS_Lst(styxRule) rules, itr;
if( styxConflict_defn(conflict,&state,&token,&rules) )
{ GLS_Tok id1, id2, pid;
int rc;
if( styxState_ide(state,&id1) )
{
rc = Pass2_checkMbrIde(styctx,id1,qlxdfns);
}
if( styxToken_ide(token,&id1) )
{
rc = Pass2_checkMbrIde(styctx,id1,qlxdfns);
if( rc == 1 ) /* nonterminal */
{
PT_diag_err
(
id1,styctx->diag,"'%s' must be a token",GLS_Tok_string(id1)
);
}
}
GLS_FORALL(itr,rules)
{
styxRule rule = GLS_FIRST(styxRule,itr);
if( styxRule_red(rule,&id1,&id2) )
{
rc = Pass2_checkMbrIde(styctx,id1,qlxdfns);
if( rc == 0 || rc == 2 ) /* token */
{
PT_diag_err
(
id1,styctx->diag,"'%s' must be a nonterminal",GLS_Tok_string(id1)
);
}
else
if( rc == 1 ) /* nonterminal */
{ PT_Term def = MAP_apply(PT_Term,styctx->glo,id1);
styxDfn pd; GLS_Lst(styxPrd) prds, prditr;
if( styx_Dfn(def,&pd) && styxDfn_defn(pd,_,_,_,&prds) )
{
c_bool found = C_False;
GLS_FORALL(prditr,prds)
{ styxPrd p = GLS_FIRST(styxPrd,prditr);
if( styxPrd_prod(p,_,&pid,_) &&
GLS_Tok_symbol(pid) == GLS_Tok_symbol(id2) );
{
found = C_True; break;
}
}
if( !found )
{
PT_diag_err
(
id2,styctx->diag,"'%s' must be a production name",GLS_Tok_string(id2)
);
}
}
}
}
}
}
}
static void Pass2(Styx_T styctx, styxSource s)
/* References */
{ PT_Itr it; Styx_T rootctx = RootCtx(styctx), tokctx;
MAP(PT_Term,Styx_T) lanexp = MAP_newPrimMap();
GLS_Lst(styxQlxDfn) qlxdfns;
styxSource_root(s,_,_,&qlxdfns,_);
PT_FORALL(it,s)
{ PT_Term t = PT_termIT(it);
styxExp exp; GLS_Tok id, lid;
if (PT_stateIT(it) == PT_PRAE)
{ styxQlxDfn qd; styxQlxCat c; styxQlxGrp g;
if (styx_QlxDfn(t,&qd) &&
styxQlxDfn_defn(qd,&c,_,_,_,&g,&exp) &&
styxQlxCat_lanC(c) &&
styxQlxGrp_grp(g,&lid))
{
if( MAP_defined(rootctx->embed,GLS_Tok_symbol(lid)) )
MAP_dfndom
(
lanexp,exp,MAP_apply(Styx_T,rootctx->embed,GLS_Tok_symbol(lid))
);
else
MAP_dfndom(lanexp,exp,styctx);
}
}
else
if (PT_stateIT(it) == PT_POST)
{ styxMbr m; styxConflict cr;
if (styx_Exp(t,&exp) )
{
if ( styxExp_ident(exp,&id) )
{ styxQlxDfn qd;
tokctx = styctx;
if( MAP_defined(lanexp,exp) )
tokctx = MAP_apply(Styx_T,lanexp,exp);
if (!MAP_defined(tokctx->glo,id))
PT_diag_err
(
id,styctx->diag,"undefined identifier '%s'",GLS_Tok_string(id)
);
else
if (!styx_QlxDfn(MAP_apply(PT_Term,tokctx->glo,id),&qd))
PT_diag_err
(
id,styctx->diag,"undefined QLX-identifier '%s'", GLS_Tok_string(id)
);
else
if( styxQlxDfn_defd(qd,_) ||
qlx_usage(tokctx,id) == UsageLan ||
qlx_quotient(tokctx,id) || qlx_dyck(tokctx,id)
/*|| qlx_pattern(tokctx,id)*/ )
PT_diag_err
(
id,styctx->diag,"'%s' can't be used as subexpression",
GLS_Tok_string(id)
);
}
}
if (styx_Mbr(t,&m) )
{
Pass2_checkMbr(styctx,m,qlxdfns);
}
else
if( styx_Conflict(t,&cr) )
{
Pass2_checkConflict(styctx,cr,qlxdfns);
}
}
}
MAP_freeMap(lanexp);
}
/* Scanner Translation */
static RegSet_T trans_Ide(Styx_T styctx, GLS_Tok id);
static RegSet_T trans_Exp(Styx_T styctx, styxExp e);
static RegSet_T TRANS_RegSet_String(string s)
{ RegSet_T reg; long len; c_bool ucs4;
wc_string tstring = LIT_styx_lit_str(&len,s,&ucs4);
reg = RegSet_StringN(tstring,len);
FreeMem(tstring);
return reg;
}
static RegSet_T TRANS_RegSet_Cset
(
Styx_T styctx, string s, PT_Term t, c_bool setrange
)
{ RegSet_T reg, a, b; long len, i; c_bool ucs4;
wc_string tstring = LIT_styx_lit_str(&len,s,&ucs4);
if( !setrange || strstr(s,"..") == (c_string)NULL )
reg = RegSet_CsetN(tstring,len);
else
{ reg = (RegSet_T)NULL;
for( i=0; i < len; ++i )
{
if( i + 3 < len &&
tstring[i+1] == WCHAR_LITERAL('.') &&
tstring[i+2] == WCHAR_LITERAL('.') )
{
if (tstring[i] > tstring[i+3])
{
PT_diag_err
(
t,styctx->diag,"range ( %ld, %ld ) must be ordered",
tstring[i], tstring[i+3]
);
a = RegSet_Range(tstring[i+3], tstring[i]);
}
else
{
a = RegSet_Range(tstring[i], tstring[i+3]);
}
i+= 3;
}
else
{
a = RegSet_CsetN(&tstring[i],1);
}
if( reg == (RegSet_T)NULL ) reg = a;
else
{
b = RegSet_Union(reg,a);
RegSet_Free(a); RegSet_Free(reg);
reg = b;
}
}
}
FreeMem(tstring); return reg;
}
static c_string TRANS_ID_Cset
(
Styx_T styctx, string s, PT_Term t,
c_bool setrange, c_bool quotient
)
{ Sink snk = Sink_open(); long len, i; c_bool ucs4;
wc_string tstring = LIT_styx_lit_str(&len,s,&ucs4);
Sink_printf(snk,"%c",SCN_SEP_TOK_ID_PATTERN);
if( quotient )
{
Sink_printf(snk,"%03d",(unsigned int)s[0]);
}
else /* pattern */
{
Sink_printf(snk,"000");
}
if( ucs4 )
{
PT_diag_err(t,styctx->diag,"invalid unicode character in set");
}
else
if( !setrange || strstr(s,"..") == (c_string)NULL )
{
for( i=0; i < len; ++i )
{
Sink_printf(snk,"%03ld",tstring[i]);
}
}
else
{
for( i=0; i < len; ++i )
{
if( i + 3 < len &&
tstring[i+1] == WCHAR_LITERAL('.') &&
tstring[i+2] == WCHAR_LITERAL('.') )
{
if (tstring[i] > tstring[i+3])
{ /* error already reported */
Sink_printf(snk,"%03ld...%03ld",tstring[i+3], tstring[i]);
}
else
{
Sink_printf(snk,"%03ld...%03ld",tstring[i], tstring[i+3]);
}
i+= 3;
}
else
{
Sink_printf(snk,"%03ld",tstring[i]);
}
}
}
FreeMem(tstring);
return Sink_close(snk);
}
static c_string TRANS_ID_quotient
(
Styx_T styctx, styxExp exp, c_bool setrange
)
{ styxExp exp1; GLS_Tok tok;
assert0(styxExp_quot(exp,_,&exp1),"");
if( styxExp_set(exp1,&tok) )
{
return TRANS_ID_Cset(styctx,GLS_Tok_string(tok),tok,C_True,C_True);
}
else
if( styxExp_sequ(exp1,&tok) )
{
return TRANS_ID_Cset(styctx,GLS_Tok_string(tok),tok,C_True,C_True);
}
else /* error, already reported */
{
return StrCopy("");
}
}
static StdCPtr TRANS_Seq(GLS_Tok seq, c_bool* ucs4)
{ StdCPtr res; wc_string tstring; long len;
string s = symbolToString(GLS_Tok_symbol(seq));
tstring = LIT_styx_lit_str(&len,s,ucs4);
if( *ucs4 == C_False )
{
res = WCToStrCopy(tstring);
bug0(strlen((string)res) == len,"'\\0' not allowed in keywords");
FreeMem(tstring);
}
else
{
bug0(WCStrLen(tstring) == len,"'L\\0' not allowed in keywords");
res = tstring;
}
return res;
}
static RegSet_T trans_Ide(Styx_T styctx, GLS_Tok id)
{
if (!MAP_defined(styctx->qlx,id))
{ RegSet_T res,old; styxExp exp, lft;
/* Flag to protect against endless recursion */
MAP_dfndom(styctx->qlx,id,NULL);
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,id),_,_,_,_,_,&exp);
if( styxExp_quot(exp,&exp,_) )
/* noop */;
if( styxExp_dyck(exp,&lft,_,_) )
res = trans_Exp(styctx,lft);
else res = trans_Exp(styctx,exp);
old = MAP_apply(RegSet_T,styctx->qlx,id);
if (old != (RegSet_T)NULL) RegSet_Free(old);
MAP_upddom(styctx->qlx,id,res);
}
else
if (MAP_apply(RegSet_T,styctx->qlx,id) == (RegSet_T)NULL)
{
PT_diag_err(id,styctx->diag,"recursive definition");
MAP_upddom(styctx->qlx,id,RegSet_Empty());
}
return RegSet_Copy(MAP_apply(RegSet_T,styctx->qlx,id));
}
static RegSet_T trans_Exp(Styx_T styctx, styxExp e)
{ styxExp exp1; styxExp exp2;
styxLimit limit; GLS_Tok tok;
if( styxExp_union(e,&exp1,&exp2) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T b = trans_Exp(styctx,exp2);
RegSet_T res = RegSet_Union(a,b);
RegSet_Free(a); RegSet_Free(b);
return res;
}
if( styxExp_diff(e,&exp1,&exp2) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T b = trans_Exp(styctx,exp2);
RegSet_T res = RegSet_Difference(a,b);
RegSet_Free(a); RegSet_Free(b);
return res;
}
if( styxExp_conc(e,&exp1,&exp2) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T b = trans_Exp(styctx,exp2);
RegSet_T res;
res = RegSet_Concat(a,b);
RegSet_Free(a); RegSet_Free(b);
return res;
}
if( styxExp_spat(e,&exp1,&tok,&exp2) )
{ RegSet_T a = styxExp_non(exp1)
? RegSet_Epsilon() : trans_Exp(styctx,exp1);
RegSet_T b = styxExp_non(exp2)
? RegSet_Epsilon() : trans_Exp(styctx,exp2);
RegSet_T c = TRANS_RegSet_Cset
(
styctx,symbolToString(GLS_Tok_symbol(tok)),tok,C_True
);
RegSet_T d = RegSet_Plus(c);
RegSet_T e = RegSet_Concat(a,d);
RegSet_T res = RegSet_Concat(e,b);
RegSet_Free(a);
RegSet_Free(b);
RegSet_Free(c);
RegSet_Free(d);
RegSet_Free(e);
return res;
}
if( styxExp_epat(e,&exp1,&tok,&exp2) )
{ styxExp exp; RegSet_T a, b, c, d, e, res;
a = styxExp_non(exp1) ? RegSet_Epsilon() : trans_Exp(styctx,exp1);
b = styxExp_non(exp2) ? RegSet_Epsilon() : trans_Exp(styctx,exp2);
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,tok),_,_,_,_,_,&exp);
if( styxExp_quot(exp,&exp,_) )
/* noop */;
if( !styxExp_spat(exp,_,&tok,_) )
{
PT_diag_err
(
tok,styctx->diag,"'%s' is no start pattern",GLS_Tok_string(tok)
);
d = trans_Exp(styctx,exp);
}
else
{
c = TRANS_RegSet_Cset
(
styctx,symbolToString(GLS_Tok_symbol(tok)),tok,C_True
);
d = RegSet_Plus(c);
RegSet_Free(c);
}
e = RegSet_Concat(a,d);
res = RegSet_Concat(e,b);
RegSet_Free(a);
RegSet_Free(b);
RegSet_Free(d);
RegSet_Free(e);
return res;
}
if( styxExp_opt(e,&exp1) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T res = RegSet_Option(a);
RegSet_Free(a);
return res;
}
if( styxExp_star(e,&exp1) || styxExp_plus0(e,&exp1) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T res = RegSet_Star(a);
RegSet_Free(a);
return res;
}
if( styxExp_plus(e,&exp1) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T res = RegSet_Plus(a);
RegSet_Free(a);
return res;
}
if( styxExp_plusn(e,&exp1,&limit) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T res = (RegSet_T)NULL;
styxOptNat optnat;
int lwr = -1, upr = -1;
if( styxLimit_ntime(limit,&tok) )
{
lwr = atoi(GLS_Tok_string(tok));
if (lwr < 0) PT_diag_err(tok,styctx->diag,"limit >= 0");
res = RegSet_Plus_ntimes(a,lwr);
}
else
if( styxLimit_range(limit,&tok,&optnat) )
{
lwr = atoi(GLS_Tok_string(tok));
if (lwr < 0) PT_diag_err(tok,styctx->diag,"limit >= 0");
if( styxOptNat_nat(optnat,&tok) )
{
upr = atoi(GLS_Tok_string(tok));
if (upr < 0) PT_diag_err(tok,styctx->diag,"limit >= 0");
res = RegSet_Plus_range(a,lwr,upr);
}
else
{
RegSet_T b = RegSet_Plus_ntimes(a,lwr);
RegSet_T c = RegSet_Star(a);
res = RegSet_Concat(b,c);
RegSet_Free(b); RegSet_Free(c);
}
}
RegSet_Free(a);
return res;
}
if( styxExp_range(e,&exp1,&exp2) )
{ RegSet_T a = trans_Exp(styctx,exp1);
RegSet_T b = trans_Exp(styctx,exp2);
RegSet_T res;
wc_char al, bu;
if (!RegSet_isChar(a)) PT_diag_err(exp1,styctx->diag,"single character");
if (!RegSet_isChar(b)) PT_diag_err(exp2,styctx->diag,"single character");
al = RegSet_charVal(a);
bu = RegSet_charVal(b);
if (al > bu)
{ wc_char x = al; al = bu; bu = x;
PT_diag_err(e,styctx->diag,"range ( %ld, %ld ) must be ordered",bu,al);
}
res = RegSet_Range(al,bu);
RegSet_Free(a); RegSet_Free(b);
return res;
}
if( styxExp_set(e,&tok) )
return TRANS_RegSet_Cset(styctx,GLS_Tok_string(tok),tok,C_False);
if( styxExp_sequ(e,&tok) )
return TRANS_RegSet_String(GLS_Tok_string(tok));
if( styxExp_ident(e,&tok) )
return trans_Ide(styctx,tok);
C_BUG; return (RegSet_T)NULL;
}
static void collectEofOrFollowTokens
(
Styx_T styctx, Styx_T parctx, symbol lansym, styxExp e,
MAP(symbol,MAP(GLS_Tok,RegSet_T)) g_ftoks
)
{ Styx_T rootctx = RootCtx(styctx),
lanctx = MAP_apply(Styx_T,rootctx->embed,lansym), ftokctx;
styxQlxDfn qd = MAP_apply(styxQlxDfn,styctx->grp,lansym);
styxQlxGrp gs, gd; styxExp exp1, exp2; GLS_Tok tok, slid, dlid;
MAP(GLS_Tok,RegSet_T) ftoks;
assert0
(
styxQlxDfn_defn(qd,_,_,&gs,_,&gd,_) &&
styxQlxGrp_grp(gs,&slid) && styxQlxGrp_grp(gd,&dlid),""
);
ftokctx = ( !strcmp(GLS_Tok_string(dlid),styctx->language) )
? styctx : lanctx;
if( MAP_defined(g_ftoks,GLS_Tok_symbol(slid)) )
ftoks = MAP_apply(MAP(_,_),g_ftoks,GLS_Tok_symbol(slid));
else
{
ftoks = MAP_newMap(styctx->gloty);
MAP_dfndom(g_ftoks,GLS_Tok_symbol(slid),ftoks);
MAP_dfndom(ftoks,(GLS_Tok)NULL,(RegSet_T)NULL);
}
if( styxExp_conc(e,&exp1,&exp2) )
{
collectEofOrFollowTokens(styctx,parctx,lansym,exp1,g_ftoks);
collectEofOrFollowTokens(styctx,parctx,lansym,exp2,g_ftoks);
}
else
if( styxExp_ident(e,&tok) )
{ styxQlxGrp gsrc; symbol grpsym;
if( qlx_pattern(ftokctx,tok) )
PT_diag_err
(
tok,parctx->diag,
"pattern token '%s' not allowed here", GLS_Tok_string(tok)
);
else
if( ftokctx != lanctx && MAP_defined(lanctx->glo,tok) )
PT_diag_err
(
tok,parctx->diag,
"identifier '%s' already defined in embedded language '%s'",
GLS_Tok_string(tok),lanctx->language
);
else
{ styxQlxCat c;
styxQlxDfn_defn(MAP_apply(styxQlxDfn,ftokctx->glo,tok),&c,_,&gsrc,_,_,_);
if( ftokctx == styctx )
{
getGroupInfo(styctx,gsrc,&grpsym,C_False);
if( grpsym == (symbol)NULL )
grpsym = InitialGroup;
if( MAP_defined(styctx->langrp,lansym) &&
MAP_apply(symbol,styctx->langrp,lansym) != grpsym )
PT_diag_err
(
gsrc,parctx->diag,
"different embedded language token group '%s'",
symbolToString(grpsym)
);
else
{ RegSet_T a, b, u;
if( MAP_defined(ftoks,tok) )
{
a = MAP_apply(RegSet_T,ftoks,tok);
b = trans_Ide(styctx,tok);
u = RegSet_Union(a,b);
MAP_dfndom(ftoks,tok,u);
RegSet_Free(a); RegSet_Free(b);
}
else
{
u = trans_Ide(styctx,tok);
MAP_dfndom(ftoks,tok,u);
}
a = MAP_apply(RegSet_T,ftoks,(GLS_Tok)NULL);
if( a == (RegSet_T)NULL )
{
MAP_upddom(ftoks,(GLS_Tok)NULL,RegSet_Copy(u));
}
else
{
b = RegSet_Union(a,u);
MAP_upddom(ftoks,(GLS_Tok)NULL,b);
RegSet_Free(a);
}
}
}
else MAP_ovrdom(ftoks,tok,(RegSet_T)NULL);
if( ! styxQlxCat_tokC(c) && ! styxQlxCat_comC(c) )
PT_diag_err(c,parctx->diag,"invalid EOF or follow token category");
}
}
else PT_diag_err(e,parctx->diag,"malformed follow token");
}
static Scn_T trans_Dyck
(
Styx_T styctx, GLS_Tok id, RegSet_T left
)
{ Scn_T dyck; ScnDfn_T scndfn;
styxExp exp, pat, rgt; RegSet_T rpat, rrgt;
c_string sl = Str_printf("%sPrefix",GLS_Tok_string(id)),
sp = Str_printf("%sPattern",GLS_Tok_string(id)),
sr = Str_printf("%sSuffix",GLS_Tok_string(id));
scndfn = Scn_dfnBegin_reentrant(symbolToString(GLS_Tok_symbol(id)));
Scn_setMsgFun_reentrant(scndfn,PT_diag_msgFun(styctx->diag));
Scn_dfnToken_reentrant
(
scndfn,sl,(byte)( qlx_ica(styctx,id)?SCN_FLG_IgnoreCase:0 ),left
);
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,id),_,_,_,_,_,&exp);
if( styxExp_quot(exp,&exp,_) )
/* noop */;
styxExp_dyck(exp,_,&pat,&rgt);
rrgt = trans_Exp(styctx,rgt);
Scn_dfnToken_reentrant
(
scndfn,sr,(byte)( qlx_ica(styctx,id)?SCN_FLG_IgnoreCase:0 ),rrgt
);
RegSet_Free(rrgt);
if( !styxExp_non(pat) )
{
rpat = trans_Exp(styctx,pat);
Scn_dfnToken_reentrant
(
scndfn,sp,(byte)( qlx_ica(styctx,id)?SCN_FLG_IgnoreCase:0 ),rpat
);
RegSet_Free(rpat);
}
FreeMem(sl); FreeMem(sp); FreeMem(sr);
dyck = Scn_dfnEnd_reentrant(scndfn,styctx->diagnose);
return dyck;
}
static Scn_T trans_QlxDfns(Styx_T styctx, styxSource s)
{ GLS_Tok id; ScnDfn_T scndfn;
PT_Itr it; MAPIT itr;
styctx->qlx = MAP_newMap(styctx->gloty);
styxSource_root(s,_,&id,_,_);
scndfn = Scn_dfnBegin_reentrant(symbolToString(GLS_Tok_symbol(id)));
Scn_setMsgFun_reentrant(scndfn,PT_diag_msgFun(styctx->diag));
PT_FORALL(it,s) if (PT_stateIT(it) == PT_PRAE)
{ PT_Term t = PT_termIT(it); styxQlxDfn d; styxQlxGrp gsrc, gdst;
if( styx_QlxDfn(t,&d) )
{ styxQlxOpt o;
if( styxQlxDfn_defn(d,_,&o,&gsrc,&id,&gdst,_) )
{
if( qlx_usage(styctx,d) == UsageTok ||
qlx_usage(styctx,d) == UsageIgn ||
qlx_usage(styctx,d) == UsageCom ||
qlx_usage(styctx,d) == UsageInd )
{ RegSet_T a = trans_Ide(styctx,id);
byte f = 0;
if( qlx_usage(styctx,d) == UsageInd )
f |= SCN_FLG_IndentToken;
if( !qlx_dyck(styctx,id) )
{ c_string tid = GLS_Tok_string(id);
if( qlx_pattern(styctx,id) )
{ styxExp exp; GLS_Tok tok;
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,id),_,_,_,_,_,&exp);
if( styxExp_quot(exp,&exp,_) )
/* noop */;
if( styxExp_spat(exp,_,&tok,_) )
{ c_string pat = TRANS_ID_Cset(styctx,GLS_Tok_string(tok),tok,C_True,C_False),
pid = Str_printf("%s%s",tid,pat);
tid = symbolToString(stringToSymbol(pid));
FreeMem(pat); FreeMem(pid);
}
f |= SCN_FLG_PatternToken;
}
if( qlx_quotient(styctx,id) )
{ styxExp exp; c_string pat, pid;
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,id),_,_,_,_,_,&exp);
pat = TRANS_ID_quotient(styctx,exp,C_True);
pid = Str_printf("%s%s",tid,pat);
tid = symbolToString(stringToSymbol(pid));
FreeMem(pat); FreeMem(pid);
}
Scn_dfnToken_reentrant
(
scndfn, tid,
(byte)( qlx_usage(styctx,d) == UsageIgn
? SCN_FLG_IgnoreToken
: f | ( styxQlxOpt_ignca(o) ? SCN_FLG_IgnoreCase : 0)
),
a
);
}
else
{ Scn_T dyck = trans_Dyck(styctx,id,a);
c_string tid = GLS_Tok_string(id);
if( qlx_quotient(styctx,id) )
{ styxExp exp; c_string pat, pid;
styxQlxDfn_defn(MAP_apply(styxQlxDfn,styctx->glo,id),_,_,_,_,_,&exp);
pat = TRANS_ID_quotient(styctx,exp,C_True);
pid = Str_printf("%s%s",tid,pat);
tid = symbolToString(stringToSymbol(pid));
FreeMem(pat); FreeMem(pid);
}
Scn_dfnDyckToken_reentrant
(
scndfn, tid,
(byte)( qlx_usage(styctx,d) == UsageIgn
? SCN_FLG_IgnoreToken
: f | ( styxQlxOpt_ignca(o) ? SCN_FLG_IgnoreCase : 0)
),
a, dyck
);
}
RegSet_Free(a);
}
}
}
}
styctx->Scn = Scn_dfnEnd_reentrant(scndfn,styctx->diagnose);
if( styctx->root == (Styx_T)NULL )
{
MAP_forItr(id,itr,styctx->qlx)
RegSet_Free(MAP_apply(RegSet_T,styctx->qlx,id));
MAP_freeMap(styctx->qlx); styctx->qlx = (MAP(_,_))NULL;
}
return styctx->Scn;
}
static void trans_QlxGroupDfns
(
Styx_T styctx, ScnDfn_T scndfn, symbol grpsym,
MAP(GLS_Tok,RegSet_T) ftoks,
MAP(GLS_Tok,symbol) patids
)
{ GLS_Tok id; MAPIT itr; RegSet_T a, u, d; symbol rng; byte f;
MAP_forItrAsg(id,rng,itr,styctx->grptok)
{
if( rng == grpsym ||
( MAP_defined(styctx->metagrp,rng) &&
HS_MBR_ELM(grpsym,MAP_apply(SET(symbol),styctx->metagrp,rng)) ) )
{ styxQlxDfn qd; styxQlxGrp gsrc, gdst; styxQlxOpt o; styxExp exp;
qd = MAP_apply(styxQlxDfn,styctx->glo,id);
if( styxQlxDfn_defn(qd,_,&o,&gsrc,&id,&gdst,&exp) )
{
if( qlx_usage(styctx,qd) == UsageTok ||
qlx_usage(styctx,qd) == UsageIgn ||
qlx_usage(styctx,qd) == UsageCom ||
qlx_usage(styctx,qd) == UsageInd )
{
a = trans_Ide(styctx,id);
u = ( ftoks == (MAP(_,_))NULL )
? (RegSet_T)NULL : MAP_apply(RegSet_T,ftoks,(GLS_Tok)NULL);
d = ( u == (RegSet_T)NULL ) ? a : RegSet_Difference(a,u);
f = 0;
if( qlx_usage(styctx,qd) == UsageInd )
f |= SCN_FLG_IndentToken;
if( MAP_defined(styctx->tokflg,id) )
f |= MAP_apply_small(byte,styctx->tokflg,id);
if( ftoks != (MAP(_,_))NULL && MAP_defined(ftoks,id) &&
MAP_apply(RegSet_T,ftoks,id) == (RegSet_T)NULL )
f |= SCN_FLG_EofToken;
if( !qlx_dyck(styctx,id) )
{ c_string tid = GLS_Tok_string(id);
if( qlx_pattern(styctx,id) )
{ GLS_Tok tok;
if( styxExp_quot(exp,&exp,_) )
/* noop */;
if( styxExp_spat(exp,_,&tok,_) )
{ c_string pat = TRANS_ID_Cset(styctx,GLS_Tok_string(tok),tok,C_True,C_False),
pid = Str_printf("%s%s",tid,pat);
symbol psy = stringToSymbol(pid);
tid = symbolToString(psy);
MAP_ovrdom(patids,id,psy);
FreeMem(pat); FreeMem(pid);
}
f |= SCN_FLG_PatternToken;
}
if( qlx_quotient(styctx,id) )
{ styxExp exp; c_string pat, pid; symbol psy;
styxQlxDfn_defn(qd,_,_,_,_,_,&exp);
pat = TRANS_ID_quotient(styctx,exp,C_True);
pid = Str_printf("%s%s",tid,pat);
psy = stringToSymbol(pid);
tid = symbolToString(psy);
MAP_ovrdom(patids,id,psy);
FreeMem(pat); FreeMem(pid);
}
Scn_dfnToken_reentrant
(
scndfn, tid,
(byte)( qlx_usage(styctx,qd) == UsageIgn
? SCN_FLG_IgnoreToken
: f | ( styxQlxOpt_ignca(o) ? SCN_FLG_IgnoreCase : 0)
),
d
);
}
else
{ Scn_T dyck = trans_Dyck(styctx,id,a);
c_string tid = GLS_Tok_string(id);
if( qlx_quotient(styctx,id) )
{ styxExp exp; c_string pat, pid; symbol psy;
styxQlxDfn_defn(qd,_,_,_,_,_,&exp);
pat = TRANS_ID_quotient(styctx,exp,C_True);
pid = Str_printf("%s%s",tid,pat);
psy = stringToSymbol(pid);
tid = symbolToString(psy);
MAP_ovrdom(patids,id,psy);
FreeMem(pat); FreeMem(pid);
}
Scn_dfnDyckToken_reentrant
(
scndfn, tid,
(byte)( qlx_usage(styctx,qd) == UsageIgn
? SCN_FLG_IgnoreToken
: f | ( styxQlxOpt_ignca(o) ? SCN_FLG_IgnoreCase : 0)
),
a, dyck
);
}
if( d != a ) RegSet_Free(d);
RegSet_Free(a);
}
}
}
}
if( ftoks != (MAP(_,_))NULL )
{
MAP_forItrAsg(id,a,itr,ftoks)
{
if( a != (RegSet_T)NULL )
{
f = SCN_FLG_EofToken | SCN_FLG_SwitchToken;
Scn_dfnToken_reentrant(scndfn, GLS_Tok_string(id),f,a);
}
}
}
}
static void trans_QlxGroups_prepare
(
Styx_T styctx, Styx_T parctx,
MAP(symbol,MAP(GLS_Tok,RegSet_T)) g_ftoks
)
{ Styx_T rootctx = RootCtx(styctx), lanctx;
MAPIT itr; symbol grpsym;
styxQlxDfn d; styxExp e;
MAP_forItrAsg(grpsym,lanctx,itr,rootctx->embed)
{
if( MAP_defined(styctx->grp,grpsym) )
{
d = MAP_apply(styxQlxDfn,styctx->grp,grpsym);
styxQlxDfn_defn(d,_,_,_,_,_,&e);
collectEofOrFollowTokens(styctx,parctx,grpsym,e,g_ftoks);
trans_QlxGroups_prepare(lanctx,parctx,g_ftoks);
}
}
}
static void trans_QlxGroups_aux
(
Styx_T styctx, Styx_T parctx, symbol elansym,
MAP(symbol,MAP(GLS_Tok,RegSet_T)) g_ftoks,
MAP(symbol,symbol) grpset,
MAP(GLS_Tok,symbol) patids
)
{ Styx_T rootctx = RootCtx(styctx), lanctx;
MAPIT itr, itr2; MAP(GLS_Tok,RegSet_T) ftoks;
ScnDfn_T scndfn; Scn_T scn; styxQlxDfn d; GLS_Tok id;
symbol rng, grpsym, lansym; c_string grpid, igrpid, sgrpid;
/* initialGroup */
ftoks = (MAP(_,_))NULL;
if( parctx == styctx )
igrpid = StrCopy(symbolToString(InitialGroup));
else
{
igrpid = Str_printf
(
"%s_%s",styctx->language,
symbolToString(elansym)+strlen(styctx->language)
);
lansym = stringToSymbol(styctx->language);
if( MAP_defined(g_ftoks,lansym) )
ftoks = MAP_apply(MAP(_,_),g_ftoks,lansym);
}
if( !MAP_defined(grpset,stringToSymbol(igrpid)) )
{
MAP_dfndom(grpset,stringToSymbol(igrpid),InitialGroup);
scndfn = Scn_dfnBegin_reentrant(igrpid);
Scn_setMsgFun_reentrant(scndfn,PT_diag_msgFun(parctx->diag));
trans_QlxGroupDfns(styctx,scndfn,InitialGroup,ftoks,patids);
MAP_forItrAsg(lansym,rng,itr,styctx->langrp)
{
if( rng == InitialGroup )
{
lanctx = MAP_apply(Styx_T,rootctx->embed,lansym);
Scn_dfnToken_reentrant
(
scndfn,symbolToString(lansym),SCN_FLG_CfgToken,(RegSet_T)NULL
);
}
}
scn = Scn_dfnEnd_reentrant(scndfn,parctx->diagnose);
ScnGrp_dfnScanner(parctx->Scn,scn);
}
/* other groups and embedded languages */
MAP_forItrAsg(grpsym,d,itr,styctx->grp)
{
if( !MAP_defined(rootctx->embed,grpsym) )
{
if( grpsym != InitialGroup &&
!MAP_defined(styctx->metagrp,grpsym) )
{
ftoks = (MAP(_,_))NULL;
if( parctx == styctx )
{
if( styxQlxDfn_tgrp(d,_) )
grpid = Str_printf("tok_%s",symbolToString(grpsym));
else
grpid = StrCopy(symbolToString(grpsym));
}
else
{
if( styxQlxDfn_tgrp(d,_) )
grpid = Str_printf
(
"%s__tok_%s",styctx->language,symbolToString(grpsym)
);
else
grpid = Str_printf
(
"%s__%s",styctx->language,symbolToString(grpsym)
);
lansym = stringToSymbol(styctx->language);
if( MAP_defined(g_ftoks,lansym) )
ftoks = MAP_apply(MAP(_,_),g_ftoks,lansym);
}
if( !MAP_defined(grpset,stringToSymbol(grpid)) )
{
MAP_dfndom(grpset,stringToSymbol(grpid),grpsym);
scndfn = Scn_dfnBegin_reentrant(grpid);
Scn_setMsgFun_reentrant(scndfn,PT_diag_msgFun(parctx->diag));
trans_QlxGroupDfns(styctx,scndfn,grpsym,ftoks,patids);
if( styxQlxDfn_igrp(d,_) )
trans_QlxGroupDfns(styctx,scndfn,InitialGroup,ftoks,patids);
MAP_forItrAsg(lansym,rng,itr2,styctx->langrp)
{
if( rng == grpsym )
{
lanctx = MAP_apply(Styx_T,rootctx->embed,lansym);
Scn_dfnToken_reentrant
(
scndfn,symbolToString(lansym),SCN_FLG_CfgToken,(RegSet_T)NULL
);
}
}
scn = Scn_dfnEnd_reentrant(scndfn,parctx->diagnose);
if( scn != (Scn_T)NULL )
ScnGrp_dfnScanner(parctx->Scn,scn);
}
FreeMem(grpid);
}
}
else
{
lanctx = MAP_apply(Styx_T,rootctx->embed,grpsym);
trans_QlxGroups_aux(lanctx, parctx, grpsym, g_ftoks, grpset, patids);
}
}
/* set token group switch information */
MAP_forItrAsg(id,rng,itr,styctx->tokgrp)
{
grpsym = MAP_apply(symbol,styctx->grptok,id);
if( MAP_defined(styctx->grp,grpsym) )
d = MAP_apply(styxQlxDfn,styctx->grp,grpsym);
else d = (styxQlxDfn)NULL;
if( grpsym == InitialGroup )
grpid = StrCopy(igrpid);
else
if( parctx == styctx )
{
if( d != (styxQlxDfn)NULL && styxQlxDfn_tgrp(d,_) )
grpid = Str_printf("tok_%s",symbolToString(grpsym));
else
grpid = StrCopy(symbolToString(grpsym));
}
else
{
if( d != (styxQlxDfn)NULL && styxQlxDfn_tgrp(d,_) )
grpid = Str_printf
(
"%s__tok_%s",styctx->language,symbolToString(grpsym)
);
else
grpid = Str_printf
(
"%s__%s",styctx->language,symbolToString(grpsym)
);
}
if( MAP_defined(styctx->grp,rng) )
d = MAP_apply(styxQlxDfn,styctx->grp,rng);
if( rng == InitialGroup )
sgrpid = StrCopy(igrpid);
else
if( MAP_defined(rootctx->embed,rng) )
{
lanctx = MAP_apply(Styx_T,rootctx->embed,rng);
sgrpid = Str_printf
(
"%s_%s",lanctx->language,
symbolToString(rng)+strlen(lanctx->language)
);
}
else
if( parctx == styctx )
{
if( d != (styxQlxDfn)NULL && styxQlxDfn_tgrp(d,_) )
sgrpid = Str_printf("tok_%s",symbolToString(rng));
else
sgrpid = StrCopy(symbolToString(rng));
}
else
{
if( d != (styxQlxDfn)NULL && styxQlxDfn_tgrp(d,_) )
sgrpid = Str_printf
(
"%s__tok_%s",styctx->language,symbolToString(rng)
);
else
sgrpid = Str_printf
(
"%s__%s",styctx->language,symbolToString(rng)
);
}
if( !MAP_defined(styctx->metagrp,grpsym) )
{
if( MAP_defined(patids,id) )
{ symbol psy = MAP_apply(symbol,patids,id);
ScnGrp_dfnSwitch(parctx->Scn, grpid, symbolToString(psy), sgrpid);
}
else
ScnGrp_dfnSwitch(parctx->Scn, grpid, GLS_Tok_string(id), sgrpid);
}
else
{ SET(symbol) grpset = MAP_apply(SET(symbol),styctx->metagrp,grpsym);
HS_Itr it; symbol elm;
HS_FORALL(elm,it,grpset)
{
if( MAP_defined(patids,id) )
{ symbol psy = MAP_apply(symbol,patids,id);
ScnGrp_dfnSwitch
(
parctx->Scn, symbolToString(elm), symbolToString(psy), sgrpid
);
}
else
ScnGrp_dfnSwitch
(
parctx->Scn, symbolToString(elm), GLS_Tok_string(id), sgrpid
);
}
}
FreeMem(grpid); FreeMem(sgrpid);
}
FreeMem(igrpid);
}
static Scn_T trans_QlxGroups(Styx_T styctx)
{ MAP(symbol,MAP(GLS_Tok,byte)) g_ftoks;
MAP(GLS_Tok,RegSet_T) ftoks;
MAP(GLS_Tok,symbol) patids;
MAP(symbol,symbol) grpset;
MAPIT itr1, itr2; RegSet_T reg;
GLS_Tok tok; symbol lansym; int rc;
styctx->qlx = MAP_newMap(styctx->gloty);
g_ftoks = MAP_newPrimMap();
grpset = MAP_newPrimMap();
patids = MAP_newPrimMap();
trans_QlxGroups_prepare(styctx,styctx,g_ftoks);
if( PT_diag_errorCnt(styctx->diag) == 0 )
{
styctx->Scn = ScnGrp_dfnBegin(styctx->language);
trans_QlxGroups_aux(styctx,styctx,(symbol)NULL,g_ftoks,grpset,patids);
rc = ScnGrp_dfnEnd(styctx->Scn);
if( rc != 0 )
PT_diag_warn(styctx->PTree,styctx->diag,"%d unreachable groups",rc);
}
MAP_forItrAsg(lansym,ftoks,itr1,g_ftoks)
{
MAP_forItrAsg(tok,reg,itr2,ftoks)
{
if( reg != (RegSet_T)NULL )
RegSet_Free(reg);
}
MAP_freeMap(ftoks);
}
MAP_freeMap(g_ftoks);
MAP_freeMap(grpset);
MAP_freeMap(patids);
if( styctx->root == (Styx_T)NULL )
{
MAP_forItr(tok,itr1,styctx->qlx)
RegSet_Free(MAP_apply(RegSet_T,styctx->qlx,tok));
MAP_freeMap(styctx->qlx); styctx->qlx = (MAP(_,_))NULL;
}
return styctx->Scn;
}
/* checking keywords */
static void Pass3_checkMbrSeq(Styx_T styctx, GLS_Tok seq, GLS_Lst(styxQlxDfn) qlxdfns)
/* check wether production or conflict keyword 'seq' is well defined */
{
c_bool u; int t; StdCPtr s = TRANS_Seq(seq,&u);
/*FIXME: comments are not allowed, too*/
if( Scn_groups(styctx->Scn) == 0 )
{
if( (!u && !(t=Scn_check_Token(styctx->Scn,(string)s))) ||
(u && !(t=Scn_check_WCToken(styctx->Scn,(wc_string)s))) )
PT_diag_err(seq,styctx->diag,"malformed token");
else
if( MAP_count(styctx->indtokkeys) < 3 &&
( Scn_tokFlags(styctx->Scn,t) & SCN_FLG_IndentToken ) )
MAP_ovrdom(styctx->indtokkeys,GLS_Tok_symbol(seq),NULL);
}
else
{
if( (!u && !(t=Scn_check_GroupToken(styctx->Scn,(string)s))) ||
(u && !(t=Scn_check_GroupWCToken(styctx->Scn,(wc_string)s))) )
PT_diag_err(seq,styctx->diag,"malformed token");
else
{ Scn_T grpscn = Scn_group(styctx->Scn,I32_HIGHVAL(t));
if( MAP_count(styctx->indtokkeys) < 3 &&
( Scn_tokFlags(grpscn,I32_LOWVAL(t)) &
SCN_FLG_IndentToken ) )
MAP_ovrdom(styctx->indtokkeys,GLS_Tok_symbol(seq),NULL);
}
}
FreeMem(s);
}
static void Pass3_checkMbr(Styx_T styctx, styxMbr m, GLS_Lst(styxQlxDfn) qlxdfns)
/* check production member 'm' (Pass3) */
{ GLS_Tok seq;
if ( styxMbr_tkm(m,&seq) )
{
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
else
{ styxMbr em;
GLS_Lst(GLS_Tok) glst1;
GLS_Lst(GLS_Tok) glst2;
GLS_Lst(GLS_Tok) glst3;
GLS_Lst(GLS_Tok) itr;
if( styxMbr_klst0(m,&glst1,&em,&glst2,&glst3) ||
styxMbr_klst1(m,&glst1,&em,&glst2,&glst3) )
{
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
GLS_FORALL(itr,glst3)
{
seq = GLS_FIRST(GLS_Tok,itr);
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
Pass3_checkMbr(styctx,em,qlxdfns);
}
else
if( styxMbr_opt(m,&glst1,&em,&glst2) )
{
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
Pass3_checkMbr(styctx,em,qlxdfns);
}
}
}
static void Pass3_checkConflict
(
Styx_T styctx, styxConflict conflict,
GLS_Lst(styxQlxDfn) qlxdfns
)
/* check wether conflict token, state and rules refer to defined
token, nonterminals and productions.
*/
{ styxState state; styxToken token;
if( styxConflict_defn(conflict,&state,&token,_) )
{ GLS_Tok seq;
if( styxState_seq(state,&seq) )
{
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
if( styxToken_seq(token,&seq) )
{
Pass3_checkMbrSeq(styctx,seq,qlxdfns);
}
}
}
static void Pass3(Styx_T styctx, styxSource src)
/* keywords */
{ PT_Itr it; GLS_Lst(styxQlxDfn) qlxdfns;
styxSource_root(src,_,_,&qlxdfns,_);
if( !GLS_EMPTY(qlxdfns) )
{
PT_FORALL(it,src)
{
if (PT_stateIT(it) == PT_POST) /* all reserved words */
{ PT_Term trm = PT_termIT(it);
styxMbr m; styxConflict cr;
if( styx_Mbr(trm,&m) )
{
Pass3_checkMbr(styctx,m,qlxdfns);
}
else
if( styx_Conflict(trm,&cr) )
{
Pass3_checkConflict(styctx,cr,qlxdfns);
}
}
}
if( MAP_count(styctx->indtokkeys) >= 3 )
PT_diag_err(qlxdfns,styctx->diag,"too many (de)indent token keywords");
}
}
/* Parser Translation */
static string normalKeyword
(
Styx_T styctx, GLS_Tok seq, c_bool extkey, c_bool* ucs4
)
/* normalizes keywords (IgnoreCase) */
{ StdCPtr s = TRANS_Seq(seq,ucs4); long tid; Scn_T grpscn;
if( extkey == C_True )
{
if( *ucs4 == C_False )
return (string)s;
else
{ string mbkey;
bug0((mbkey = GS_ucs4_to_utf8((wc_string)s))!=(string)NULL,"");
FreeMem(s);
return mbkey;
}
}
else
if( *ucs4 == C_False )
{
if( Scn_groups(styctx->Scn) == 0 )
{
tid = Scn_check_Token(styctx->Scn,(string)s);
bug1(tid,"token '%s' does not belong to grammar\n",(string)s);
if( Scn_tokFlags(styctx->Scn,(short)tid) & SCN_FLG_IgnoreCase )
StrToLower((string)s);
}
else
{
tid = Scn_check_GroupToken(styctx->Scn,(string)s);
bug1(tid,"token '%s' does not belong to grammar\n",(string)s);
grpscn = Scn_group(styctx->Scn,I32_HIGHVAL(tid));
if( Scn_tokFlags(grpscn,I32_LOWVAL(tid)) & SCN_FLG_IgnoreCase )
StrToLower((string)s);
}
return (string)s;
}
else
{ string mbkey, tmp;
if( Scn_groups(styctx->Scn) == 0 )
tid = Scn_check_WCToken(styctx->Scn,(wc_string)s);
else
tid = Scn_check_GroupWCToken(styctx->Scn,(wc_string)s);
if( !tid )
{ Sink snk = Sink_open();
mbkey = GS_ucs4_to_utf8((wc_string)s);
Sink_puts(snk,"token '");
if( mbkey != (string)NULL ) Sink_puts_raw(styctx->Scn,mbkey);
Sink_puts(snk,"' does not belong to grammar\n");
tmp = Sink_close(snk);
FreeMem(s); FreeMem(mbkey);
bug1(False,"%s",tmp);
}
else
{
if( Scn_groups(styctx->Scn) == 0 )
{
if( Scn_tokFlags(styctx->Scn,(short)tid) & SCN_FLG_IgnoreCase )
WCStrToLower((wc_string)s);
}
else
{
grpscn = Scn_group(styctx->Scn,I32_HIGHVAL(tid));
if( Scn_tokFlags(grpscn,I32_LOWVAL(tid)) & SCN_FLG_IgnoreCase )
WCStrToLower((wc_string)s);
}
bug0((mbkey = GS_ucs4_to_utf8((wc_string)s))!=(string)NULL,"");
FreeMem(s);
}
return mbkey;
}
}
static void trans_Dfns_addMbrNTK_Seq
(
Styx_T styctx, PLR_Cfg Cfg,
GLS_Tok seq, GLS_Lst(styxQlxDfn) qlxdfns,
MAP(symbol,NULL) key
)
{
c_bool ucs4;
string s = normalKeyword(styctx,seq,GLS_EMPTY(qlxdfns),&ucs4);
symbol keyword = stringToSymbol(s);
FreeMem(s);
if( ! MAP_defined(key,keyword) )
{
MAP_dfndom(key,keyword,NULL);
PLR_addTK(Cfg,symbolToString(keyword),(ucs4?PLR_TYP_WKY:PLR_TYP_KEY));
}
}
static void trans_Dfns_addMbrNTK_Ide
(
Styx_T styctx, PLR_Cfg Cfg,
GLS_Tok id, GLS_Lst(styxQlxDfn) qlxdfns,
MAP(symbol,NULL) exttok
)
{ Styx_T rootctx = RootCtx(styctx);
if( GLS_EMPTY(qlxdfns) )
{
if (!MAP_defined(styctx->glo,id) &&
!MAP_defined(rootctx->embed,GLS_Tok_symbol(id)))
{
if( ! MAP_defined(exttok,GLS_Tok_symbol(id)) )
{
MAP_dfndom(exttok,GLS_Tok_symbol(id),NULL);
PLR_addTK(Cfg,GLS_Tok_string(id),PLR_TYP_TOK);
}
}
}
}
static void trans_Dfns_addMbrNTK
(
Styx_T styctx, PLR_Cfg Cfg,
styxMbr m, c_bool* tkother, GLS_Lst(styxQlxDfn) qlxdfns,
MAP(symbol,NULL) key, MAP(symbol,NULL) exttok
)
{ Styx_T rootctx = RootCtx(styctx);
GLS_Tok id, seq;
if( styxMbr_tkm(m,&seq) )
{
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
else
if( styxMbr_else(m) )
{
*tkother = C_True;
}
else
if( styxMbr_ntm(m,&id) )
{
trans_Dfns_addMbrNTK_Ide(styctx,Cfg,id,qlxdfns,exttok);
}
else
if( !MAP_defined(styctx->ebnfmbr,m) ) //20110122 neue Bedingung: Bugfix gleicher EBNF-Member-Term
{ styxMbr em;
GLS_Lst(GLS_Tok) glst1;
GLS_Lst(GLS_Tok) glst2;
GLS_Lst(GLS_Tok) glst3;
GLS_Lst(GLS_Tok) itr;
char buf[80+1];
if( styxMbr_klst0(m,&glst1,&em,&glst2,&glst3) ||
styxMbr_klst1(m,&glst1,&em,&glst2,&glst3) )
{ symbol s = (symbol)NULL;
sprintf(buf,"_List%d",++rootctx->ebnfcnt);
PLR_addNT(Cfg,buf,C_False);
s = stringToSymbol(buf);
sprintf(buf,"%s_0",symbolToString(s));
PLR_addNT(Cfg,buf,C_False);
MAP_dfndom(styctx->ebnfmbr,m,s);
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
GLS_FORALL(itr,glst3)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
/*trans_Dfns_addMbrNTK(styctx,Cfg,em,tkother,qlxdfns,key,exttok);*/
}
else
if( styxMbr_opt(m,&glst1,&em,&glst2) )
{ symbol s = (symbol)NULL;
sprintf(buf,"_Opt%d",++rootctx->ebnfcnt);
PLR_addNT(Cfg,buf,C_False);
s = stringToSymbol(buf);
MAP_dfndom(styctx->ebnfmbr,m,s);
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbrNTK_Seq(styctx,Cfg,seq,qlxdfns,key);
}
/*trans_Dfns_addMbrNTK(styctx,Cfg,em,tkother,qlxdfns,key,exttok);*/
}
}
}
static void trans_Dfns_addConflict
(
Styx_T styctx, PLR_Cfg Cfg,
styxConflict conflict, GLS_Lst(styxQlxDfn) qlxdfns,
MAP(symbol,NULL) key, MAP(symbol,NULL) exttok
)
{ styxState state; styxToken token; GLS_Lst(styxRule) rules, itr;
if( styxConflict_defn(conflict,&state,&token,&rules) )
{ GLS_Tok seq, id1, id2, nat;
string s; symbol statesym = NULL, tokensym = NULL;
int idx = -1; c_bool ucs4;
if( styxState_seq(state,&seq) )
{
s = normalKeyword(styctx,seq,GLS_EMPTY(qlxdfns),&ucs4);
statesym = stringToSymbol(s);
FreeMem(s);
if( !MAP_defined(key,statesym) )
{
PT_diag_err(seq,styctx->diag,"unknown state symbol");
return;
}
}
else
if( styxState_ide(state,&id1) )
{
statesym = GLS_Tok_symbol(id1);
if( GLS_EMPTY(qlxdfns) && !MAP_defined(exttok,statesym) )
{
PT_diag_err(id1,styctx->diag,"unknown state symbol");
return;
}
}
else
if( styxState_nat(state,&nat) )
{
idx = atoi(GLS_Tok_string(nat));
}
if( styxToken_seq(token,&seq) )
{
s = normalKeyword(styctx,seq,GLS_EMPTY(qlxdfns),&ucs4);
tokensym = stringToSymbol(s);
FreeMem(s);
if( !MAP_defined(key,tokensym) )
{
PT_diag_err(seq,styctx->diag,"unknown token symbol");
return;
}
}
else
if( styxToken_ide(token,&id1) )
{
tokensym = GLS_Tok_symbol(id1);
if( GLS_EMPTY(qlxdfns) && !MAP_defined(exttok,tokensym) )
{
PT_diag_err(id1,styctx->diag,"unknown token symbol");
return;
}
}
if( tokensym == NULL )
{
PT_diag_err(token,styctx->diag,"unknown token symbol");
return;
}
if( statesym == NULL && idx == -1 )
{
PT_diag_err(token,styctx->diag,"undefined conflict state");
return;
}
PLR_addCCtx(Cfg,idx,statesym==NULL?NULL:symbolToString(statesym),symbolToString(tokensym));
GLS_FORALL(itr,rules)
{
styxRule rule = GLS_FIRST(styxRule,itr);
if( styxRule_red(rule,&id1,&id2) )
{
PLR_addCRule(Cfg,GLS_Tok_string(id1),GLS_Tok_string(id2));
}
}
}
}
static void trans_Dfns_addMbr_Seq
(
Styx_T styctx, PLR_Cfg Cfg,
GLS_Tok seq, GLS_Lst(styxQlxDfn) qlxdfns
)
{
c_bool ucs4;
long r = PT_row(seq);
long c = PT_col(seq);
string s = normalKeyword(styctx,seq,GLS_EMPTY(qlxdfns),&ucs4);
PLR_addPK(Cfg,s,r,c);
FreeMem(s);
}
static c_bool trans_Dfns_addMbr
(
Styx_T styctx, PLR_Cfg Cfg,
styxMbr m, GLS_Lst(styxQlxDfn) qlxdfns
)
{
long r = PT_row(m), c = PT_col(m);
GLS_Tok id, did, seq;
if( styxMbr_tkm(m,&seq) )
{
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
return C_True;
}
else
if( styxMbr_ntm(m,&id) )
{ PT_Term t = getDfn(styctx,id,!GLS_EMPTY(qlxdfns));
r = PT_row(id);
c = PT_col(id);
if( t == (PT_Term)NULL || styx_QlxDfn(t,_) )
{
PLR_addPT(Cfg,GLS_Tok_string(id),r,c);
HS_SET_ELM(GLS_Tok_symbol(id),styctx->tkset);
}
else
if( styx_Dfn(t,_) )
PLR_addPN(Cfg,GLS_Tok_string(id),r,c);
return C_True;
}
else
if( styxMbr_dtok(m,&id,&did) )
{
r = PT_row(id);
c = PT_col(id);
PLR_addPD(Cfg,GLS_Tok_string(id),GLS_Tok_string(did),r,c);
HS_SET_ELM(GLS_Tok_symbol(id),styctx->tkset);
return C_True;
}
else
if( styxMbr_else(m) )
{
PLR_addPT(Cfg,PLR_TOK_Other,r,c);
HS_SET_ELM(stringToSymbol(PLR_TOK_Other),styctx->tkset);
return C_True;
}
return C_False;
}
static c_bool trans_Dfns_addEBNFMbr
(
Styx_T styctx, PLR_Cfg Cfg,
styxMbr m, GLS_Lst(styxQlxDfn) qlxdfns
)
{
c_bool stdmbr = trans_Dfns_addMbr(styctx,Cfg,m,qlxdfns);
if( !stdmbr && MAP_defined(styctx->ebnfmbr,m) )
{ long r = PT_row(m), c = PT_col(m);
c_string ebnfmbrid = symbolToString(MAP_apply(symbol,styctx->ebnfmbr,m));
PLR_addPN(Cfg,ebnfmbrid,r,c);
}
return stdmbr;
}
static void trans_Dfns_addEBNFPrd
(
Styx_T styctx, PLR_Cfg Cfg,
styxMbr m, GLS_Lst(styxQlxDfn) qlxdfns
)
{ long r = PT_row(m), c = PT_col(m);
c_string ebnfid = symbolToString(MAP_apply(symbol,styctx->ebnfmbr,m));
GLS_Lst(GLS_Tok) glst1;
GLS_Lst(GLS_Tok) glst2;
GLS_Lst(GLS_Tok) glst3;
GLS_Lst(GLS_Tok) itr;
GLS_Tok seq; styxMbr em; char buf[80+1];
if( styxMbr_klst0(m,&glst1,&em,&glst2,&glst3) ||
styxMbr_klst1(m,&glst1,&em,&glst2,&glst3) )
{
sprintf(buf,"%s_0",ebnfid);
if( styxMbr_klst0(m,_,_,_,_) )
{
PLR_addPR(Cfg,"nil", PLR_PRD_DFT,ebnfid);
}
PLR_addPR(Cfg,"cons", PLR_PRD_DFT,ebnfid);
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
}
trans_Dfns_addEBNFMbr(styctx,Cfg,em,qlxdfns);
PLR_addPN(Cfg,buf,r,c);
GLS_FORALL(itr,glst3)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
}
PLR_addPR(Cfg,"nil", PLR_PRD_DFT,buf);
PLR_addPR(Cfg,"cons", PLR_PRD_DFT,buf);
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
}
trans_Dfns_addEBNFMbr(styctx,Cfg,em,qlxdfns);
PLR_addPN(Cfg,buf,r,c);
}
else
if( styxMbr_opt(m,&glst1,&em,&glst2) )
{
PLR_addPR(Cfg,"none", PLR_PRD_DFT,ebnfid);
PLR_addPR(Cfg,"some", PLR_PRD_DFT,ebnfid);
GLS_FORALL(itr,glst1)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
}
trans_Dfns_addEBNFMbr(styctx,Cfg,em,qlxdfns);
GLS_FORALL(itr,glst2)
{
seq = GLS_FIRST(GLS_Tok,itr);
trans_Dfns_addMbr_Seq(styctx,Cfg,seq,qlxdfns);
}
}
}
static PLR_Cfg trans_Dfns(Styx_T styctx, styxSource src)
{
MAPTY keyty; MAP(symbol,NULL) key, exttok; /* reserved words */
PLR_Cfg Cfg; MAPIT itr; PT_Itr it;
GLS_Lst(styxQlxDfn) qlxdfns;
GLS_Lst(styxDfn) dfns, dfnitr;
GLS_Lst(styxConflict) conflicts, critr;
styxOptCfg optcfg; styxDfn pd; styxMbr m;
GLS_Tok id, nt, elan;
c_bool tkother = C_False;
styxSource_root(src,_,&id,&qlxdfns,&optcfg);
styxOptCfg_cfg(optcfg,&dfns,&conflicts);
Cfg = PLR_createCfg(symbolToString(GLS_Tok_symbol(id)),styctx->version);
keyty = MAP_newTyp(primCopy,primFree,primEqual,primHash,primCopy,primFree);
key = MAP_newMap(keyty);
exttok = MAP_newMap(keyty);
PT_FORALL(it,src) if( PT_stateIT(it) == PT_PRAE )
{ PT_Term t = PT_termIT(it); styxQlxDfn qd;
if( styx_QlxDfn(t,&qd) ) /* Token */
{ styxQlxGrp gsrc, gdst;
if( styxQlxDfn_defn(qd,_,_,&gsrc,&id,&gdst,_) &&
( qlx_usage(styctx,qd) == UsageTok ||
qlx_usage(styctx,qd) == UsageCom ||
qlx_usage(styctx,qd) == UsageLan ||
qlx_usage(styctx,qd) == UsageInd ) )
{
if( qlx_usage(styctx,qd) != UsageLan )
PLR_addTK(Cfg,GLS_Tok_string(id),PLR_TYP_TOK);
else
{ c_string lantok;
assert0( styxQlxGrp_grp(gsrc,&elan), "");
lantok = Str_printf("%s%s",GLS_Tok_string(elan),GLS_Tok_string(id));
PLR_addTK(Cfg,lantok,PLR_TYP_CFG);
FreeMem(lantok);
}
}
else
if( styxQlxDfn_defd(qd,&id) )
{ int flg = 0;
if( MAP_defined(styctx->dyntok,GLS_Tok_symbol(id)) )
flg = MAP_apply(int,styctx->dyntok,GLS_Tok_symbol(id));
if( (flg&1) == 0 || (flg&2) == 0 )
{
PT_diag_warn
(
id,styctx->diag,"%s dynamic token %s",
GLS_Tok_string(id),
(flg&2)==0 ? "unused" : "unintroduced"
);
}
PLR_addTK(Cfg,GLS_Tok_string(id),PLR_TYP_TOK);
}
}
else
if( styx_Dfn(t,&pd) ) /* Nonterminal */
{ styxDfnOpt o;
if( styxDfn_defn(pd,_,&o,&id,_) )
PLR_addNT(Cfg,GLS_Tok_string(id),styxDfnOpt_errnt(o));
}
else
if( styx_Mbr(t,&m) ) /* Keyword, external Token, EBNF Nonterminal */
{
trans_Dfns_addMbrNTK(styctx,Cfg,m,&tkother,qlxdfns,key,exttok);
}
}
if( tkother )
{
PLR_addTK(Cfg,PLR_TOK_Other,PLR_TYP_TOK);
}
/*
MAP_freeMap( key );
MAP_freeMap( exttok );
MAP_freeTyp( keyty );
*/
PLR_endSD(Cfg); /* Sorting Token & Nonterminals */
MAP_forItr(id,itr,styctx->glo)
{ styxQlxDfn qd;
if( styx_QlxDfn(MAP_apply(PT_Term,styctx->glo,id),&qd) &&
styxQlxDfn_defn(qd,_,_,_,_,_,_) &&
qlx_usage(styctx,id) == UsageCom ) /* Special Token */
PLR_addST(Cfg,GLS_Tok_string(id));
}
GLS_FORALL(dfnitr,dfns)
{ styxCat c; GLS_Lst(styxPrd) prds, prditr;
pd = GLS_FIRST(styxDfn,dfnitr);
if( styxDfn_defn(pd,&c,_,&nt,&prds) )
{
if( styxCat_bgnC(c) ) /* Startsymbol */
PLR_addSN(Cfg,GLS_Tok_string(nt));
GLS_FORALL(prditr,prds)
{ styxPrd p = GLS_FIRST(styxPrd,prditr);
GLS_Lst(styxMbr) mbrs, mbritr;
styxLay lay; GLS_Tok pid;
if( styxPrd_prod(p,&lay,&pid,&mbrs) ) /* Production */
{
if( styxLay_dft(lay) )
PLR_addPR
(
Cfg,GLS_Tok_string(pid), PLR_PRD_DFT,GLS_Tok_string(nt)
);
else
if( styxLay_rec(lay) )
PLR_addPR
(
Cfg,GLS_Tok_string(pid), PLR_PRD_REC,GLS_Tok_string(nt)
);
else
if( styxLay_grp(lay) )
PLR_addPR
(
Cfg,GLS_Tok_string(pid), PLR_PRD_GRP,GLS_Tok_string(nt)
);
GLS_FORALL(mbritr,mbrs)
{ m = GLS_FIRST(styxMbr,mbritr); /* Production Symbol */
trans_Dfns_addEBNFMbr(styctx,Cfg,m,qlxdfns);
}
}
}
}
}
/* EBNF Productions */
{ styxMbr ep = (styxMbr)NULL;
MAP_forItr(ep,itr,styctx->ebnfmbr)
{
trans_Dfns_addEBNFPrd(styctx,Cfg,ep,qlxdfns);
}
}
/* Conflict rules */
GLS_FORALL(critr,conflicts)
{ styxConflict conflict = GLS_FIRST(styxConflict,critr);
trans_Dfns_addConflict
(
styctx, Cfg, conflict, qlxdfns, key, exttok
);
}
MAP_freeMap( key );
MAP_freeMap( exttok );
MAP_freeTyp( keyty );
return Cfg;
}
static void STYX_compile_free(Styx_T styctx, int rc)
{
if( styctx->qlx != (MAP(_,_))NULL )
{ MAPIT itr; RegSet_T rng; symbol dom;
MAP_forItrAsg(dom,rng,itr,styctx->qlx)
RegSet_Free(rng);
MAP_freeMap(styctx->qlx); styctx->qlx = (MAP(_,_))NULL;
}
if( styctx->glo != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->glo); styctx->glo = (MAP(_,_))NULL;
}
if( styctx->grp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->grp); styctx->grp = (MAP(_,_))NULL;
}
if( styctx->grptok != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->grptok); styctx->grptok = (MAP(_,_))NULL;
}
if( styctx->dyntok != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->dyntok); styctx->dyntok = (MAP(_,_))NULL;
}
if( styctx->langrp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->langrp); styctx->langrp = (MAP(_,_))NULL;
}
if( styctx->tokgrp != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->tokgrp); styctx->tokgrp = (MAP(_,_))NULL;
}
if( styctx->ebnfmbr != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->ebnfmbr); styctx->ebnfmbr = (MAP(_,_))NULL;
}
if( styctx->tokflg != (MAP(_,_))NULL )
{
MAP_freeMap(styctx->tokflg); styctx->tokflg = (MAP(_,_))NULL;
}
if( rc != 0 && styctx->tkset != (HS_Set)NULL )
{
HS_DROP_SET(styctx->tkset); styctx->tkset = (HS_Set)NULL;
}
if( styctx->indtokkeys != (MAP(symbol,_))NULL )
{
MAP_freeMap(styctx->indtokkeys); styctx->indtokkeys = (MAP(symbol,_))NULL;
}
if( styctx->gloty != (MAPTY)NULL )
{
MAP_freeTyp(styctx->gloty); styctx->gloty = (MAPTY)NULL;
}
}
static int STYX_compile(Styx_T styctx, Scn_Stream cStream, c_string incpath)
{ PLR_Cfg Cfg; PT_Cfg PCfg;
MAP(long,symbol) pPreParMap; SPP_T pPP;
styxSource s; styxOptCfg optcfg; GLS_Lst(styxDfn) dfns;
GLS_Lst(styxQlxDfn) qlxdfns; GLS_Tok id;
void (*prMsg)(c_string msg) = PT_diag_msgFun(styctx->diag);
MAPIT itr; Styx_T rng; symbol dom;
long indcnt = 0; int rc = 0, tblcnt = 2;
if (styctx->verbose) (*prMsg)("parsing ...\n");
STYX_reset(styctx);
styctx->incpath = stringToSymbol(incpath);
pPreParMap = MAP_newPrimMap();
MAP_dfndom(pPreParMap,SPP_INC_PATH,styctx->incpath);
pPP = SPP_init_reentrant(pPreParMap);
Stream_premac_set(cStream, SPP_premac);
Stream_add_ctxval(cStream,SPP_premac,pPP);
PCfg = PT_init(styctx->styapp->PTab,cStream);
styctx->PTree = (styx)PT_PARSE(PCfg,"Source");
PT_diag_setErrorCnt(styctx->diag,PT_synErrorCnt(PCfg));
PT_quit(PCfg);
SPP_quit_reentrant(pPP);
MAP_freeMap(pPreParMap);
if (styctx->verbose) (*prMsg)("done parsing\n");
if( (styctx->errorCnt=PT_diag_errorCnt(styctx->diag)) == 0 )
{ styxOptNat optnat; GLS_Tok nat;
styx_Start_0(styctx->PTree,&s);
styxSource_root(s,&optnat,&id,&qlxdfns,&optcfg);
if( strcmp(GLS_Tok_string(id),styctx->language) != 0 )
{
PT_diag_err
(
id,styctx->diag,"language identifier und file name are different"
);
}
if( styxOptNat_nat(optnat,&nat) )
{
styctx->version = atoi(GLS_Tok_string(nat));
if( styctx->version > 1 )
{
PT_diag_warn
(
nat,styctx->diag,"unknown styx version"
);
}
}
styctx->gloty = MAP_newTyp
(
primCopy,primFree,PT_equal,PT_hash,
primCopy,primFree
);
styctx->glo = MAP_newMap(styctx->gloty);
styctx->tkset = HS_CREATE_ADTSET(symbol);
styctx->indtokkeys = MAP_newPrimMap();
styctx->grp = MAP_newPrimMap();
styctx->grptok = MAP_newMap(styctx->gloty);
styctx->dyntok = MAP_newPrimMap();
styctx->langrp = MAP_newPrimMap();
styctx->tokgrp = MAP_newMap(styctx->gloty);
styctx->ebnfmbr = MAP_newMap(styctx->gloty);
styctx->metagrp = MAP_newPrimMap();
styctx->tokflg = MAP_newMap(styctx->gloty);
if( styctx->root == (Styx_T)NULL )
styctx->embed = MAP_newPrimMap();
if (styctx->verbose) (*prMsg)("Pass 1\n");
Pass1(styctx,s); /* Pass 1: uniqueness */
if (styctx->verbose) (*prMsg)("Pass 2\n");
Pass2(styctx,s); /* Pass 2: references */
}
if( (styctx->errorCnt=PT_diag_errorCnt(styctx->diag)) > 0 )
{
PT_diag_msg
(
(PT_Term)NULL,styctx->diag,"Totally %d errors.\n",
PT_diag_errorCnt(styctx->diag)
);
}
else
{
/* QLX translator */
if( !GLS_EMPTY(qlxdfns) )
{
if (styctx->verbose) (*prMsg)("begin scanner creation\n");
if( MAP_count(styctx->grp) <= 1 )
styctx->Scn = trans_QlxDfns(styctx,s);
else
styctx->Scn = trans_QlxGroups(styctx);
if (styctx->verbose) (*prMsg)("end scanner creation\n");
}
else
{
--tblcnt; (*prMsg)("Note: No scanner specified.\n");
}
if( GLS_EMPTY(qlxdfns) || styctx->Scn != (Scn_T)NULL )
{
if (styctx->verbose) (*prMsg)("Pass 3\n");
Pass3(styctx,s); /* Pass 3: keyword */
if( styctx->root == (Styx_T)NULL &&
styctx->embed != (MAP(_,_))NULL &&
(styctx->errorCnt=PT_diag_errorCnt(styctx->diag)) == 0 )
{
MAP_forItrAsg(dom,rng,itr,styctx->embed)
{
indcnt += MAP_count(rng->indtokkeys);
}
if( indcnt >= 3 )
PT_diag_err(s,styctx->diag,"too many (de)indent token keywords");
}
if( (styctx->errorCnt=PT_diag_errorCnt(styctx->diag)) == 0 )
{
/* CFG translator */
if( styxOptCfg_cfg(optcfg,&dfns,_) && ! GLS_EMPTY(dfns) )
{
Cfg = trans_Dfns(styctx,s);
if( (styctx->errorCnt=PT_diag_errorCnt(styctx->diag)) == 0 )
{
styctx->PTab = PLR_createTab(Cfg,styctx->verbose,styctx->diagnose);
}
PLR_delCfg(Cfg);
if( styctx->PTab != (PLR_Tab)NULL )
{
if( ! acfg_init(styctx->PTab,
&styctx->aPol,&styctx->aNtm,&styctx->aPrd,True) )
{
acfg_quit(styctx->PTab,styctx->aPol,styctx->aNtm,styctx->aPrd);
PLR_delTab(styctx->PTab); styctx->PTab = (PLR_Tab)NULL;
}
}
else (*prMsg)("Parse table creation failed.\n");
if( styctx->PTab == (PLR_Tab)NULL && styctx->Scn != (Scn_T)NULL )
{
Scn_free(styctx->Scn); styctx->Scn = (Scn_T)NULL;
}
}
else
{
--tblcnt; (*prMsg)("Note: No parser specified.\n");
}
}
else
if( styctx->Scn != (Scn_T)NULL )
{
Scn_free(styctx->Scn); styctx->Scn = (Scn_T)NULL;
}
}
else
{
(*prMsg)("Scan table creation failed.\n");
}
}
if( styctx->errorCnt > 0 )
rc = styctx->errorCnt;
else
if( tblcnt > 0 && styctx->Scn == (Scn_T)NULL &&
styctx->PTab == (PLR_Tab)NULL )
rc = -1;
if( styctx->root == (Styx_T)NULL )
{
if( styctx->embed != (MAP(_,_))NULL )
{
MAP_forItrAsg(dom,rng,itr,styctx->embed)
{
STYX_compile_free(rng,rc);
}
}
STYX_compile_free(styctx,rc);
}
return rc;
}
int STYX_compile_file(Styx_T styctx, c_string stydfn, c_string incpath)
/* compiles STYX definition in file 'stydfn' and
creates the corresponding scan & parse table;
uses 'incpath' as include path
RC > 0: number of syntax and semantic errors
RC = -1: table creation failed
RC = 0: successful compilation
*/
{ Scn_Stream cStream; int rc = 0;
BUG_NULL(styctx);
cStream = Stream_file(styctx->styapp->Scn,"",stydfn,"");
rc = STYX_compile(styctx,cStream,incpath);
Stream_free(cStream);
return rc;
}
int STYX_compile_string(Styx_T styctx, c_string stydfn, c_string incpath)
/* compiles STYX definition in string 'stydfn' and
creates the corresponding scan & parse table;
uses 'incpath' as include path
RC > 0: number of syntax and semantic errors
RC = -1: table creation failed
RC = 0: successful compilation
*/
{ Scn_Stream cStream; int rc = 0;
BUG_NULL(styctx);
cStream = Stream_string(styctx->styapp->Scn,stydfn);
rc = STYX_compile(styctx,cStream,incpath);
Stream_free(cStream);
return rc;
}
/*I----------------------- Table image & source generation ------------------- */
void STYX_createTabIMG(Styx_T styctx, c_string Environ)
/* unloads scan & parse table to images
[$'Environ'/] The module [scn_gen] supports the construction of regular sets and
produces the scanner definitions as base for the
scan streams.
The complexity of the scanner is linear. A consequence of this design-goal
is its restriction to a one-character-lookahead.
The construction of regular sets is reentrant.
There also exists a reentrant version of the scanner production. The resulting regular sets when applying one of the following functions
have to be released.
*/
/* -- basic graph constructors -- */
static int RegSet_TId = 1;
RegSet_T RegSet_Epsilon(void)
/* epsilon "" */
{ faNode s0 = New(faNode);
regset_t res = New(regset_t);
#if defined( _MSDOS ) || defined( _WIN32 )
res->id = InterlockedIncrement(&RegSet_TId);
#else
res->id = RegSet_TId ++;
#endif
res->Nodes = cons(s0,NULL);
s0->id = 0;
s0->Belongs = res;
s0->Source = NULL;
s0->term = True; /* terminal */
s0->Edges = NULL;
s0->flag1 = 0;
s0->flag2 = 0;
return RegSet_ADT(res);
}
RegSet_T RegSet_Empty(void)
/* empty set '' */
{ faNode s0 = New(faNode);
regset_t res = New(regset_t);
#if defined( _MSDOS ) || defined( _WIN32 )
res->id = InterlockedIncrement(&RegSet_TId);
#else
res->id = RegSet_TId ++;
#endif
res->Nodes = cons(s0,NULL);
s0->id = 0;
s0->Belongs = res;
s0->Source = NULL;
s0->term = False; /* non - terminal */
s0->Edges = NULL;
s0->flag1 = 0;
s0->flag2 = 0;
return RegSet_ADT(res);
}
RegSet_T RegSet_Range(wc_char dfa_lower, wc_char dfa_upper)
/* character range L .. U */
{ faNode s0 = New(faNode);
faNode s1 = New(faNode);
regset_t res = New(regset_t);
c_bug
(
((unsigned long)dfa_lower) <= ((unsigned long)dfa_upper),
"RegSet_Range(%ld,%ld) must be a range",
((unsigned long)dfa_lower),((unsigned long)dfa_upper)
);
#if defined( _MSDOS ) || defined( _WIN32 )
res->id = InterlockedIncrement(&RegSet_TId);
#else
res->id = RegSet_TId ++;
#endif
res->Nodes = cons(s0,cons(s1,NULL));
s0->id = 0;
s0->Belongs = res;
s0->Source = NULL;
s0->term = False; /* non - terminal */
s0->Edges = cons(newDfaEdge(dfa_lower,dfa_upper,s1),NULL);
s0->flag1 = 0;
s0->flag2 = 0;
s1->id = 1;
s1->Belongs = res;
s1->Source = NULL;
s1->term = True; /* terminal */
s1->Edges = NULL;
s1->flag1 = 0;
s1->flag2 = 0;
return RegSet_ADT(res);
}
RegSet_T RegSet_Char(wc_char c)
/* character 'c' */
{
return RegSet_Range(c,c);
}
/* -- Graph Combinator -- */
static int lex(int A, int B) { return A ? A : B; }
static bool compNodes(faNode a, faNode b)
/* order Nodes */
{
return lex( a->Belongs->id - b->Belongs->id, a->id - b->id );
}
static List(faNode) insertState(faNode x, List(faNode) y)
/* inserts a state into a source id */
/* we keep them ordered for identification */
{
return empty(y) ? cons(x,y)
: compNodes(x,fst(faNode,y)) == 0 ? y
: compNodes(x,fst(faNode,y)) < 0 ? cons(x,y)
: ((*rst_ref(y) = insertState(x,rst(y))), y);
}
static List(nfaEdge) copyEdges
(
List(dfaEdge) x, RegSet_T lambdaFrom, RegSet_T lambdaTo
)
/* copies an DFA-Edge to a NFA-Edge extending lambda edges */
{
if (empty(x))
return NULL;
else
{ List(faNode) src = NULL;
faNode nod = fst(dfaEdge,x)->dfa_toNode;
src = insertState(nod,src);
if (nod->Belongs == RegSet_IMP(lambdaFrom) && nod->term > 0)
src = insertState(fst(faNode,RegSet_IMP(lambdaTo)->Nodes),src);
return cons(newNfaEdge(fst(dfaEdge,x)->dfa_lower,
fst(dfaEdge,x)->dfa_upper,
src ),
copyEdges(rst(x), lambdaFrom,lambdaTo) );
}
}
static List(faNode) nodesUnion(List(faNode) x, List(faNode) y)
{
if ( empty(x) && empty(y))
return NULL;
if ( empty(x) && !empty(y))
return cons(fst(faNode,y),nodesUnion(NULL,rst(y)));
if (!empty(x) && empty(y))
return cons(fst(faNode,x),nodesUnion(rst(x),NULL));
if (compNodes(fst(faNode,x),fst(faNode,y)) < 0)
return cons(fst(faNode,x),nodesUnion(rst(x),y));
else
if (compNodes(fst(faNode,x),fst(faNode,y)) > 0)
return cons(fst(faNode,y),nodesUnion(x,rst(y)));
else
return cons(fst(faNode,x),nodesUnion(rst(x),rst(y)));
}
static bool equalStates(List(faNode) x, List(faNode) y)
{
for (; !empty(x) && !empty(y); x=rst(x), y=rst(y))
if (fst(faNode,x) != fst(faNode,y))
return False;
return empty(x) && empty(y);
}
static List(nfaEdge) consMerge(nfaEdge x, List(nfaEdge) y)
/* joins two edges if possible */
{
if (!empty(y) &&
x->nfa_upper+1 == fst(nfaEdge,y)->nfa_lower &&
equalStates(x->nfa_toNodes,fst(nfaEdge,y)->nfa_toNodes) )
{
fst(nfaEdge,y)->nfa_lower = x->nfa_lower;
freeNfaEdge(x);
return y;
}
else
return cons(x,y);
}
static List(nfaEdge) mergeEdges(List(nfaEdge) x, List(nfaEdge) y)
/* merges NFA-Edges x with NFA-Edges y */
/* Note that both lists are freed */
{ nfaEdge xe, ye; List(nfaEdge) xy, res;
if (empty(x)) return y;
if (empty(y)) return x;
xy = x; xe = fst(nfaEdge,x); x = rst(x); FreeMem(xy);
xy = y; ye = fst(nfaEdge,y); y = rst(y); FreeMem(xy);
if (xe->nfa_upper > ye->nfa_upper)
{
{ nfaEdge a = xe, b = ye; xe = b; ye = a; }
{ List(nfaEdge) a = x, b = y; x = b; y = a; }
}
if (xe->nfa_upper < ye->nfa_lower)
return consMerge(xe,mergeEdges(x,cons(ye,y)));
/* we have a true intersection here */
res = consMerge
(
newNfaEdge(MAX(xe->nfa_lower,ye->nfa_lower),
xe->nfa_upper,
nodesUnion(xe->nfa_toNodes, ye->nfa_toNodes) ),
mergeEdges(x,
xe->nfa_upper < ye->nfa_upper
? cons(newNfaEdge((wc_char)(xe->nfa_upper+1),
ye->nfa_upper,
nodesUnion(ye->nfa_toNodes, NULL)
),y )
: y )
);
if (xe->nfa_lower > ye->nfa_lower)
{ nfaEdge a = xe, b = ye; xe = b; ye = a; }
if (xe->nfa_lower < ye->nfa_lower)
res = consMerge(newNfaEdge(xe->nfa_lower, (wc_char)(ye->nfa_lower-1),
nodesUnion(xe->nfa_toNodes,NULL) ), res );
freeNfaEdge(xe); freeNfaEdge(ye);
return res;
}
/* -- */
static faNode identifySource(RegSet_T g, List(faNode) x)
/* identify state in g with Source equal to x */
{ List(faNode) *t; int i; faNode s0;
for(i = 0, t = &RegSet_IMP(g)->Nodes; !empty(*t); i += 1, t = rst_ref(*t))
if (equalStates( fst(faNode,*t)->Source, x))
{ freeList(x, freeNothing); return fst(faNode,*t); }
s0 = New(faNode);
s0->id = i;
s0->Belongs = RegSet_IMP(g);
s0->Source = x;
s0->term = False;
s0->Edges = NULL;
s0->flag1 = 0;
s0->flag2 = 0;
*t = cons(s0,NULL);
return s0;
}
static List(faNode) NfaToDfaEdges(RegSet_T g, List(nfaNode) x)
/* translates NfaEdges to DdfaEdges identifying or adding states to g */
{ List(nfaNode) t;
for(t = x; !empty(t); t = rst(t))
{ nfaEdge e = fst(nfaEdge,t);
((dfaEdge)e)->dfa_toNode = identifySource(g, e->nfa_toNodes);
}
return (List(faNode)) x;
}
static List(faNode) RegSet_Starts
(
List(RegSet_T) graphs,
RegSet_T lambdaFrom,
RegSet_T lambdaTo
)
/* returns the list of start nodes of graphs */
/* frees x */
{ List(RegSet_T) x; List(faNode) y; faNode n;
if (empty(graphs)) return NULL;
x = rst(graphs);
n = fst(faNode,fst(regset_t,graphs)->Nodes);
FreeMem(graphs);
y = RegSet_Starts(x, lambdaFrom,lambdaTo);
if (n->Belongs == lambdaFrom && n->term > 0)
y = insertState(fst(faNode,RegSet_IMP(lambdaTo)->Nodes),y);
return insertState(n,y);
}
static RegSet_T RegSet_Merge
(
List(RegSet_T) graphs, RegSet_T lambdaFrom, RegSet_T lambdaTo
)
{ faNode s0 = New(faNode);
List(faNode) Todo;
regset_t res = New(regset_t);
#if defined( _MSDOS ) || defined( _WIN32 )
res->id = InterlockedIncrement(&RegSet_TId);
#else
res->id = RegSet_TId ++;
#endif
res->Nodes = cons(s0,NULL);
s0->id = 0;
s0->Belongs = res;
s0->Source = RegSet_Starts(graphs,lambdaFrom,lambdaTo);
s0->term = False;
s0->Edges = NULL;
s0->flag1 = 0;
s0->flag2 = 0;
for (Todo = res->Nodes; !empty(Todo); Todo = rst(Todo))
{ List(faNode) Nds; List(nfaEdge) NfaEdges = NULL;
for( Nds = fst(faNode,Todo)->Source; !empty(Nds); Nds = rst(Nds))
NfaEdges = mergeEdges
(
NfaEdges,
copyEdges(fst(faNode,Nds)->Edges,lambdaFrom,lambdaTo)
);
fst(faNode,Todo)->Edges = NfaToDfaEdges(res, NfaEdges);
}
return RegSet_ADT(res);
}
/* -- graph reduction -- */
/* Ziel: von allen Zustaenden aus kann ein terminaler Zustand erreicht */
/* werden. */
/* Methode: entferne alle anderen */
#define reachesNxt flag1
#define reachesTrm flag2
static void reachNodes(regset_t reg)
/* build the closure of terminal nodes via egdes */
{ List(faNode) nodes; List(dfaEdges) edges; bool changed = True;
while (changed)
{ changed = False;
for (nodes = reg->Nodes; !empty(nodes); nodes = rst(nodes))
{ faNode nod = fst(faNode,nodes);
for (edges = nod->Edges; !empty(edges); edges = rst(edges))
nod->reachesNxt |= fst(dfaEdge,edges)->dfa_toNode->reachesTrm;
}
for (nodes = reg->Nodes; !empty(nodes); nodes = rst(nodes))
{ faNode nod = fst(faNode,nodes);
changed |= (nod->reachesNxt != nod->reachesTrm);
nod->reachesTrm |= nod->reachesNxt;
}
}
}
static List(dfaEdge) combineRanges(List(dfaEdge) edges)
/* combines ranges if possible */
{ dfaEdge e1, e2; List(dfaEdge) rest;
if (empty(edges) || empty(rst(edges))) return edges;
rest = combineRanges(rst(edges));
*rst_ref(edges) = rest;
e1 = fst(dfaEdge,edges);
e2 = fst(dfaEdge,rst(edges));
if (e1->dfa_upper+1 != e2->dfa_lower || e1->dfa_toNode != e2->dfa_toNode)
return edges;
/* combine */
e2->dfa_lower = e1->dfa_lower;
FreeMem(e1); FreeMem(edges);
return rest;
}
static void reduceGraph(RegSet_T g)
/* reduce graph g */
{ List(faNode) nods, *nodsp; int i;
/* initialize marks */
for (nods = RegSet_IMP(g)->Nodes; !empty(nods); nods = rst(nods))
{ faNode nod = fst(faNode,nods);
nod->reachesTrm = (nod->term > 0);
nod->reachesNxt = (nod->term > 0);
}
/* mark */
reachNodes(RegSet_IMP(g));
fst(faNode,RegSet_IMP(g)->Nodes)->reachesTrm = True;
/* remove all edges leading to blind states */
for (nods = RegSet_IMP(g)->Nodes; !empty(nods); nods = rst(nods))
{ faNode nod = fst(faNode,nods); List(dfaEdge) *edges;
for (edges = &nod->Edges; !empty(*edges); )
{ dfaEdge edge = fst(dfaEdge,*edges);
if (!edge->dfa_toNode->reachesTrm)
{ List(dfaEdge) here = *edges;
*edges = rst(*edges); FreeMem(edge); FreeMem(here);
}
else
edges = rst_ref(*edges);
}
nod->Edges = combineRanges(nod->Edges);
}
/* remove all blind states */
for (i = 0, nodsp = &RegSet_IMP(g)->Nodes; !empty(*nodsp); )
{ faNode nod = fst(faNode,*nodsp);
if (!nod->reachesTrm)
{ List(faNode) here = *nodsp; *nodsp = rst(*nodsp); FreeMem(here); FreeMem(nod); }
else
{ nod->id = i; i += 1; nodsp = rst_ref(*nodsp); }
}
}
/* -- graph minimation -- */
/* Ziel: der Graph enthaelt keine aequivalenten Zustaende */
/* Methode: entferne alle aequivalenten Zustaende */
#define currEquiv flag1
#define prevEquiv flag2
static faNode findNode(RegSet_T g, int NodeId)
{ List(faNode) nods;
for (nods = RegSet_IMP(g)->Nodes; !empty(nods); nods = rst(nods))
if ( fst(faNode,nods)->id == NodeId )
return fst(faNode,nods);
C_BUG; return NULL; /* dummy */
}
static bool sameEquiv(List(faNode) nods)
/* copy curr to prev; return true if all same */
{ bool res = True;
for (; !empty(nods); nods = rst(nods))
{ faNode nod = fst(faNode,nods);
res = res && (nod->prevEquiv == nod->currEquiv);
nod->prevEquiv = nod->currEquiv;
}
return res;
}
static bool sameEquivClass(List(dfaEdge) edgs1, List(dfaEdge) edgs2)
/* return if both edge-lists are equivalent relative to prevEquiv */
{ dfaEdge edg1, edg2 ;
Loop1:
if (empty(edgs1) && empty(edgs2)) return True;
if (empty(edgs1) || empty(edgs2)) return False;
edg1 = fst(dfaEdge,edgs1);
edg2 = fst(dfaEdge,edgs2);
if (edg1->dfa_lower != edg2->dfa_lower) return False;
Loop2:
if (edg1->dfa_toNode->prevEquiv != edg2->dfa_toNode->prevEquiv) return False;
if (edg1->dfa_upper == edg2->dfa_upper)
{
edgs1 = rst(edgs1); edgs2 = rst(edgs2);
goto Loop1;
}
else
if (edg1->dfa_upper < edg2->dfa_upper)
{
if (empty(rst(edgs1)) ||
edg1->dfa_upper+1 != ((dfaEdge)rst(edgs1))->dfa_lower)
return False;
edgs1 = rst(edgs1); edg1 = fst(dfaEdge,edgs1);
goto Loop2;
}
else
{
if (empty(rst(edgs2)) ||
edg2->dfa_upper+1 != ((dfaEdge)rst(edgs2))->dfa_lower)
return False;
edgs2 = rst(edgs2); edg2 = fst(dfaEdge,edgs2);
goto Loop2;
}
}
static void minimizeGraph(RegSet_T g)
/* reduce graph g */
{ List(faNode) nods, nods1, nods2, *nodsp; int i;
/* initialize equivalence */
for (nods1 = RegSet_IMP(g)->Nodes; !empty(nods1); nods1 = rst(nods1))
{ faNode nod1 = fst(faNode,nods1), nod2;
for (nods2 = RegSet_IMP(g)->Nodes; !empty(nods2); nods2 = rst(nods2))
{ nod2 = fst(faNode,nods2); if (nod1->term == nod2->term) break; }
nod2 = fst(faNode,nods2);
nod1->prevEquiv = -1; nod1->currEquiv = nod2->id;
}
while (!sameEquiv(RegSet_IMP(g)->Nodes))
{ /* next equivalence */
for (nods1 = RegSet_IMP(g)->Nodes; !empty(nods1); nods1 = rst(nods1))
{ faNode nod1 = fst(faNode,nods1), nod2;
for (nods2 = RegSet_IMP(g)->Nodes; !empty(nods2); nods2 = rst(nods2))
{ nod2 = fst(faNode,nods2);
if (nod1->prevEquiv == nod2->prevEquiv &&
sameEquivClass(nod1->Edges, nod2->Edges))
break;
}
nod2 = fst(faNode,nods2);
nod1->currEquiv = nod2->id;
}
}
/* patch the edges */
for (nods = RegSet_IMP(g)->Nodes; !empty(nods); nods = rst(nods))
{ faNode nod = fst(faNode,nods); List(dfaEdge) edges;
for (edges = nod->Edges; !empty(edges); edges = rst(edges))
{ dfaEdge edge = fst(dfaEdge,edges);
edge->dfa_toNode = findNode(g,edge->dfa_toNode->currEquiv);
}
nod->Edges = combineRanges(nod->Edges);
}
/* drop all equivalents beside first */
for (i = 0, nodsp = &RegSet_IMP(g)->Nodes; !empty(*nodsp); )
{ faNode nod = fst(faNode,*nodsp);
if (nod->currEquiv != nod->id)
{
List(faNode) here = *nodsp; *nodsp = rst(*nodsp);
FreeMem(here); freeDfaNode(nod);
}
else
{ nod->id = i; i += 1; nodsp = rst_ref(*nodsp); }
}
}
static bool hasTerminal(List(faNode) x, RegSet_T a)
/* whether a terminal state of 'a' is in source list 'x' */
{
for (; !empty(x); x = rst(x))
{ faNode nod = fst(faNode,x);
if (nod->Belongs == RegSet_IMP(a) && nod->term > 0)
return True;
}
return False;
}
/* -- graph operations -- */
RegSet_T RegSet_Copy(RegSet_T a)
/* copies regular set 'a' */
{ RegSet_T res; List(faNode) lst;
res = RegSet_Merge( cons(a,NULL), NULL,NULL );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,a);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
return res;
}
RegSet_T RegSet_Union(RegSet_T a, RegSet_T b)
/* union a | b */
{ RegSet_T res; List(faNode) lst;
if (a == b) return RegSet_Copy(a);
res = RegSet_Merge( cons(a,cons(b, NULL)), NULL,NULL );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,a) || hasTerminal(nod->Source,b);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
reduceGraph(res); minimizeGraph(res);
return res;
}
RegSet_T RegSet_Intersection(RegSet_T a, RegSet_T b)
/* intersection a ^ b */
{ RegSet_T res; List(faNode) lst;
if (a == b) return RegSet_Copy(a);
res = RegSet_Merge( cons(a,cons(b, NULL)), NULL,NULL );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,a) && hasTerminal(nod->Source,b);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
reduceGraph(res); minimizeGraph(res);
return res;
}
RegSet_T RegSet_Difference(RegSet_T a, RegSet_T b)
/* difference a - b */
{ RegSet_T res; List(faNode) lst;
if (a == b) return RegSet_Empty();
res = RegSet_Merge( cons(a,cons(b, NULL)), NULL,NULL );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,a) && !hasTerminal(nod->Source,b);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
reduceGraph(res); minimizeGraph(res);
return res;
}
RegSet_T RegSet_Concat(RegSet_T a, RegSet_T b)
/* concatenation a b */
{ RegSet_T res,c; List(faNode) lst;
c = (a == b) ? RegSet_Copy(a) : b;
res = RegSet_Merge( cons(a,NULL), a,c );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,b);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
if (a==b) RegSet_Free(c);
reduceGraph(res);
minimizeGraph(res);
return res;
}
RegSet_T RegSet_Star(RegSet_T a)
/* iteration { a } */
{ RegSet_T res; List(faNode) lst;
res = RegSet_Merge( cons(a,NULL), a,a );
for (lst = RegSet_IMP(res)->Nodes; !empty(lst); lst = rst(lst))
{ faNode nod = fst(faNode,lst);
nod->term = hasTerminal(nod->Source,a) ||
fst(faNode,nod->Source) == fst(faNode,RegSet_IMP(a)->Nodes);
freeList(nod->Source, freeNothing); nod->Source = NULL;
}
reduceGraph(res); minimizeGraph(res);
return res;
}
/* -- combinations -- */
RegSet_T RegSet_CsetN(wc_string s,int len)
/* character set '...'[0:len) */
{
if (len > 0)
{ RegSet_T a = RegSet_Char((wc_char)(0xffffffffUL & ((unsigned long)s[0])));
RegSet_T b = RegSet_CsetN(s+1,len-1);
RegSet_T c = RegSet_Union(a, b);
RegSet_Free(a); RegSet_Free(b);
return c;
}
else
return RegSet_Empty();
}
RegSet_T RegSet_Cset(wc_string s)
/* character set '...' */
{
return RegSet_CsetN(s,WCStrLen(s));
}
RegSet_T RegSet_StringN(wc_string s,int len)
/* character sequence / string "..."[0:len) */
{
if (len > 0)
{ RegSet_T a = RegSet_Char((wc_char)(0xffffffffUL & ((unsigned long)s[0])));
RegSet_T b = RegSet_StringN(s+1,len-1);
RegSet_T c = RegSet_Concat(a, b);
RegSet_Free(a); RegSet_Free(b);
return c;
}
else
return RegSet_Epsilon();
}
RegSet_T RegSet_String(wc_string s)
/* character sequence / string "..." */
{
return RegSet_StringN(s,WCStrLen(s));
}
RegSet_T RegSet_Option(RegSet_T a)
/* option [ a ] */
{ RegSet_T b = RegSet_Epsilon();
RegSet_T c = RegSet_Union(a,b);
RegSet_Free(b);
return c;
}
RegSet_T RegSet_Plus(RegSet_T a)
/* iteration a + */
{ RegSet_T b = RegSet_Star(a);
RegSet_T c = RegSet_Concat(a,b);
RegSet_Free(b);
return c;
}
RegSet_T RegSet_Plus_ntimes(RegSet_T a, int n)
/* iteration { a } n-times, n >= 0 */
{ RegSet_T res = RegSet_Epsilon();
int i;
for( i=0; i < n; ++i )
{ RegSet_T c = RegSet_Concat(res,a);
RegSet_Free(res);
res = c;
}
return res;
}
RegSet_T RegSet_Plus_range(RegSet_T a, int lwr, int upr)
/* iteration { a } lwr-times .. upr-times, lwr >= 0, upr >= 0 */
{ RegSet_T res = RegSet_Plus_ntimes(a,lwr);
int i;
for( i=lwr+1; i <= upr; ++i )
{ RegSet_T b = RegSet_Option(a);
RegSet_T c = RegSet_Concat(res,b);
RegSet_Free(b);
RegSet_Free(res);
res = c;
}
return res;
}
bool RegSet_isChar(RegSet_T a)
/* a = 'x' ? */
{ faNode s0 = fst(faNode,RegSet_IMP(a)->Nodes);
bool res = !empty(rst(RegSet_IMP(a)->Nodes))
&& empty(rst(rst(RegSet_IMP(a)->Nodes)))
&& !empty(s0->Edges) && empty(rst(s0->Edges));
dfaEdge e = res ? fst(dfaEdge,s0->Edges) : NULL;
return res && e->dfa_lower == e->dfa_upper;
}
wc_char RegSet_charVal(RegSet_T a)
/* x; assertion: a = 'x' */
{ wc_char res;
bug0( RegSet_isChar(a), "single character set requiered" );
res = fst(dfaEdge,fst(faNode,RegSet_IMP(a)->Nodes)->Edges)->dfa_lower;
return res;
}
/*I----------------------- Scanner production ----------------------------- */
/* -- The Production Of The Scanner -- */
struct DefinedGraphs
{
string name;
int usage;
RegSet_T value;
};
#define MAX_ENTRIES 100
ExternalType(ScnDfn_T) /* Scanner production handle */
{
struct DefinedGraphs Table[MAX_ENTRIES];
int topEntry;
string Scn_name;
scn_t dyckpat[MAX_ENTRIES];
bool ConflictFlag;
void (*prMsg)(c_string msg);
};
static ConcreteImp(ScnDfn_T) CurScnDfn; /* current scanner production */
static bool Scn_defining = False;
static void Scn_dfnBegin_aux(ScnDfn_T scndfn, string name, c_bool* defining)
{
bug0(!(*defining),"already defining a scanner");
scndfn->Scn_name = StrCopy(name);
*defining = C_True;
scndfn->prMsg = (void (*)(c_string msg))NULL;
scndfn->topEntry = 1;
scndfn->dyckpat[0] = (scn_t)NULL;
scndfn->Table[0].name = SCN_TOK_Other;
scndfn->Table[0].usage = 0;
scndfn->Table[0].value = (RegSet_T)NULL;
/*
scndfn->topEntry = 2;
scndfn->dyckpat[1] = (scn_t)NULL;
scndfn->Table[1].name = StrCopy("[empty]");
scndfn->Table[1].usage = 0;
scndfn->Table[1].value = RegSet_Epsilon();
*/
}
void Scn_dfnBegin(string name)
/* begins a scanner definition;
uses 'name' as identifier
*/
{
Scn_dfnBegin_aux(&CurScnDfn,name,&Scn_defining);
}
ScnDfn_T Scn_dfnBegin_reentrant(string name)
/* reentrant version of Scn_dfnBegin */
{ ScnDfn_T scndfn = New(ScnDfn_T);
c_bool defining = C_False;
Scn_dfnBegin_aux(scndfn,name,&defining);
return scndfn;
}
void Scn_setMsgFun(void (*prMsg)(c_string msg))
/* defines 'prMsg' as default message function */
{
CurScnDfn.prMsg = prMsg;
}
void Scn_setMsgFun_reentrant(ScnDfn_T curdfn, void (*prMsg)(c_string msg))
/* reentrant version of Scn_setMsgFun */
{
BUG_NULL(curdfn);
curdfn->prMsg = prMsg;
}
static void Scn_dfnToken_aux
(
ScnDfn_T scndfn,
string name, byte tok_flags, RegSet_T value,
c_bool defining
)
{ int i;
bug0(defining,"missing Scn_dfnBegin");
for (i = 1; i < scndfn->topEntry; i++)
bug1(strcmp(scndfn->Table[i].name,name), "duplicate name \'%s\'", name);
bug0(scndfn->topEntry < MAX_ENTRIES, "too many tokens defined");
scndfn->Table[scndfn->topEntry].name = StrCopy(name);
scndfn->Table[scndfn->topEntry].usage = tok_flags;
if( value != (RegSet_T)NULL )
scndfn->Table[scndfn->topEntry].value = RegSet_Copy(value);
else
scndfn->Table[scndfn->topEntry].value = (RegSet_T)NULL;
scndfn->dyckpat[scndfn->topEntry] = (scn_t)NULL;
scndfn->topEntry += 1;
}
void Scn_dfnToken(string name, byte tok_flags, RegSet_T value)
/* adds a new token to the scanner under production
'name' : identifier
'flags': attributes ( see [scn_base] )
'value': regular set
*/
{
Scn_dfnToken_aux(&CurScnDfn,name,tok_flags,value,Scn_defining);
}
void Scn_dfnToken_reentrant
(
ScnDfn_T curdfn, string name, byte tok_flags, RegSet_T value
)
/* reentrant version of Scn_dfnToken */
{
BUG_NULL(curdfn);
Scn_dfnToken_aux(curdfn,name,tok_flags,value,C_True);
}
void Scn_dfnDyckToken
(
string name, byte tok_flags,
RegSet_T left, Scn_T dyck
)
/* adds a new dyck token to the scanner under production;
consumes 'dyck'
'name' : identifier
'flags': attributes ( see [scn_base] )
'left' : regular set for left paranthesis
'dyck' : dyck scanner ( left, inner and right token )
*/
{ scn_t scn = Scn_IMP(dyck);
Scn_dfnToken_aux(&CurScnDfn,name,tok_flags,left,Scn_defining);
CurScnDfn.dyckpat[CurScnDfn.topEntry-1] =
/*( scn == (scn_t)NULL ) ? (scn_t)NULL :*/ scn;
}
void Scn_dfnDyckToken_reentrant
(
ScnDfn_T curdfn, string name, byte tok_flags,
RegSet_T left, Scn_T dyck
)
/* reentrant version of Scn_dfnToken */
{ scn_t scn = Scn_IMP(dyck);
BUG_NULL(curdfn);
Scn_dfnToken_aux(curdfn,name,tok_flags,left,C_True);
curdfn->dyckpat[curdfn->topEntry-1] =
/*( scn == (scn_t)NULL ) ? (scn_t)NULL :*/ scn;
}
static void pConflicts(ScnDfn_T scndfn, List(faNode) nodes)
{
if (length(nodes) > 1)
{ void (*prMsg)(c_string msg) = scndfn->prMsg;
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stderr;
scndfn->ConflictFlag = True;
(*prMsg)("Conflict between ");
for (;!empty(nodes); nodes = rst(nodes))
{ faNode node = fst(faNode,nodes);
(*prMsg)("'");
(*prMsg)(scndfn->Table[node->Belongs->id].name);
(*prMsg)("'");
if (length(nodes) > 1)
{
if (length(nodes) == 2)
(*prMsg)(" and ");
else
(*prMsg)(", ");
}
}
(*prMsg)(".\n");
}
}
static List(faNode) terminalSource(List(faNode) nodes)
/* removes all non-terminal states from the source of a node */
{
if(empty(nodes))
return nodes;
else
{ List(faNode) r = terminalSource(rst(nodes));
if( fst(faNode,nodes)->term )
{ *rst_ref(nodes) = r; return nodes; }
else
{ FreeMem(nodes); return r; }
}
}
static void terminalScanner(ScnDfn_T scndfn, RegSet_T graph)
/* removes all non-terminal states from the sources of a graph */
{ List(faNode) nodes = RegSet_IMP(graph)->Nodes;
for (; !empty(nodes); nodes = rst(nodes))
{ faNode node = fst(faNode,nodes);
node->Source = terminalSource(node->Source);
node->term = empty(node->Source)
? 0
: fst(faNode,node->Source)->Belongs->id;
pConflicts(scndfn,node->Source);
}
}
/* new version of scanner table production */
static Scn_T ScnTable (ScnDfn_T scndfn, RegSet_T scanner)
{ int i, j, edgcnt, dyckcnt, states = length(RegSet_IMP(scanner)->Nodes);
long *StaEdg;
short *StaFin;
wc_char *EdgeC;
long *EdgeS;
List(faNode) nodes; List(dfaEdge) edges;
wc_char clow;
scn_t res;
/* count edges */
edgcnt = 0;
for (nodes = RegSet_IMP(scanner)->Nodes; !empty(nodes); nodes = rst(nodes))
{ faNode node = fst(faNode,nodes);
clow = 0;
for (edges = node->Edges; !empty(edges); edges = rst(edges))
{ dfaEdge edge = fst(dfaEdge,edges);
edgcnt += (clow < edge->dfa_lower)+1;
clow = edge->dfa_upper+1;
}
if (clow < SCN_CHAR_SET_SIZE) edgcnt += 1;
}
/*
assert0
(
(((long)edgcnt) & 0xFFFF0000L) == 0,
"Too many edges. Reduce token complexity"
);
*/
/* count dyck tokens */
dyckcnt = 0;
for( i=0; i < scndfn->topEntry; ++i )
if( scndfn->dyckpat[i] != (scn_t)NULL )
++dyckcnt;
/* make edges and states */
StaEdg = (long* )NewMem( (states+1) * sizeof(long ) );
StaFin = (short* )NewMem( states * sizeof(short ) );
EdgeC = (wc_char*)NewMem( edgcnt * sizeof(wc_char) );
EdgeS = (long* )NewMem( edgcnt * sizeof(long ) );
edgcnt = 0;
for (nodes = RegSet_IMP(scanner)->Nodes; !empty(nodes); nodes = rst(nodes))
{ faNode node = fst(faNode,nodes);
StaEdg[node->id] = edgcnt;
StaFin[node->id] = node->term;
clow = 0;
for (edges = node->Edges; !empty(edges); edges = rst(edges))
{ dfaEdge edge = fst(dfaEdge,edges);
if (clow < edge->dfa_lower)
{
EdgeC[edgcnt] = clow; EdgeS[edgcnt] = 0; edgcnt += 1;
}
EdgeC[edgcnt] = edge->dfa_lower;
EdgeS[edgcnt] = edge->dfa_toNode->id+1;
clow = edge->dfa_upper+1;
edgcnt += 1;
}
if (clow < SCN_CHAR_SET_SIZE)
{
EdgeC[edgcnt] = clow; EdgeS[edgcnt] = 0; edgcnt += 1;
}
for (i = 0; i < (edgcnt-StaEdg[node->id])/2; i ++)
{ wc_char t;
t = EdgeC[StaEdg[node->id]+i];
EdgeC[StaEdg[node->id]+i] = EdgeC[edgcnt-1-i];
EdgeC[edgcnt-1-i] = t;
t = (wc_char)EdgeS[StaEdg[node->id]+i];
EdgeS[StaEdg[node->id]+i] = EdgeS[edgcnt-1-i];
EdgeS[edgcnt-1-i] = t;
}
}
StaEdg[states] = edgcnt;
/* make scanner structure */
res = New(scn_t);
res->Name = scndfn->Scn_name;
res->States = states;
res->Tokens = scndfn->topEntry;
res->StaEdg = StaEdg;
res->StaFin = StaFin;
res->EdgeC = EdgeC;
res->EdgeS = EdgeS;
res->TokId = (string*)NewMem((scndfn->topEntry) * sizeof(string));
res->Flags = (byte *)NewMem((scndfn->topEntry) * sizeof(byte));
res->Groups = 0;
res->GrpScn = (scn_t*)NULL;
res->Switch = (short*)NULL;
res->dyckcnt = dyckcnt;
res->dyckidx = dyckcnt > 0
? (short*)NewMem(dyckcnt * sizeof(short))
: (short*)NULL;
res->dyckpat = dyckcnt > 0
? (scn_t*)NewMem(dyckcnt * sizeof(scn_t))
: (scn_t*)NULL;
for (i = 0; i < scndfn->topEntry; i++)
res->TokId[i] = StrCopy(scndfn->Table[i].name);
for (i = 0; i < scndfn->topEntry; i++)
res->Flags[i] = scndfn->Table[i].usage;
for (i=0, j=0; i < scndfn->topEntry && j < dyckcnt; i++)
{
if( scndfn->dyckpat[i] != (scn_t)NULL )
{
res->dyckpat[j] = scndfn->dyckpat[i];
res->dyckidx[j] = (short)i;
j++;
}
}
/* free temporaries */
RegSet_Free(scanner);
/* done */
return Scn_ADT(res);
}
/* -- graph printer -- */
static void pGraphList
(
List(Abs_T) x, int Indent,
void (*pMember)(Abs_T x, StdCPtr any), StdCPtr any
)
{ void (*prMsg)(c_string msg) = ((ScnDfn_T)any)->prMsg;
char buf[STD_BUFFLEN+1]; int i;
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
(*prMsg)("[");
if (Indent >= 0 && !empty(x))
{
sprintf(buf,"\n%*s",Indent,"");
(*prMsg)(buf);
}
for (i = 0; !empty(x); x = rst(x), i +=1 )
{
(*pMember)(fst(Abs_T,x),any);
if (!empty(rst(x)))
if (Indent >= 0 || (i+1) % 4 == 0)
{ (*prMsg)(",");
sprintf(buf,"\n%*s",(Indent>=0?Indent:7),"");
(*prMsg)(buf);
}
else
(*prMsg)(", ");
else
if (Indent >= 0)
{
sprintf(buf,"\n%*s",Indent,"");
(*prMsg)(buf);
}
}
(*prMsg)("]");
}
static void pSource(faNode x, ScnDfn_T scndfn)
{ void (*prMsg)(c_string msg) = scndfn->prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
sprintf(buf,"%d(", x->Belongs->id);
(*prMsg)(buf);
(*prMsg)(scndfn->Table[x->Belongs->id].name);
(*prMsg)(")");
}
static void pChar(wc_char wc, ScnDfn_T scndfn)
{ byte c = (byte)wc;
void (*prMsg)(c_string msg) = scndfn->prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
if( ((wc_char)c) == wc )
switch (c)
{
case ' ' : sprintf(buf,"\\_"); break;
case '\f' : sprintf(buf,"\\p"); break;
case '\n' : sprintf(buf,"\\n"); break;
case '\r' : sprintf(buf,"\\r"); break;
case '\\' :
case '\'' :
case '\"' :
case '`' : sprintf(buf,"\\%c",c); break;
//default : if (32 < c && c < 127)
default : if ( isascii(c) && isprint(c) )
sprintf(buf,"%c",c);
else
sprintf(buf,"%02x",c);
}
else
sprintf(buf,"%08lx",(long unsigned int)wc);
(*prMsg)(buf);
}
static void pEdge(dfaEdge x, ScnDfn_T scndfn)
{ void (*prMsg)(c_string msg) = scndfn->prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
(*prMsg)("(");
if (x->dfa_lower != x->dfa_upper)
{ pChar(x->dfa_lower,scndfn); (*prMsg)(" - "); }
else
(*prMsg)(" ");
pChar(x->dfa_upper,scndfn);
sprintf(buf," : %2d)", x->dfa_toNode->id );
(*prMsg)(buf);
}
static void pNfaEdge(nfaEdge x, ScnDfn_T scndfn)
{ byte cl = (byte)x->nfa_lower,
cu = (byte)x->nfa_upper;
void (*prMsg)(c_string msg) = scndfn->prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
if( ((wc_char)cl) == x->nfa_lower && ((wc_char)cu) == x->nfa_upper )
{
(*prMsg)("({\'");
pChar(x->nfa_lower,scndfn);
(*prMsg)("\'..\'");
pChar(x->nfa_upper,scndfn);
(*prMsg)("\'}");
}
else
{
sprintf
(
buf,"({%08lx..%08lx}, ",
(long unsigned int)x->nfa_lower, (long unsigned int)x->nfa_upper
);
(*prMsg)(buf);
}
pGraphList(x->nfa_toNodes,-1,(void (*)(Abs_T x,StdCPtr any))pSource,scndfn);
(*prMsg)(")");
}
static void pNfaEdges(List(nfaEdge) x, ScnDfn_T scndfn)
{
pGraphList(x,-1,(void (*)(Abs_T x,StdCPtr any))pNfaEdge,scndfn);
}
static void pNode(faNode x, ScnDfn_T scndfn)
{ void (*prMsg)(c_string msg) = scndfn->prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
sprintf(buf,"%2d %2d ", x->id, x->term);
(*prMsg)(buf);
sprintf(buf,"(%2d %2d) ", x->flag1, x->flag2);
(*prMsg)(buf);
pGraphList(x->Source,-1,(void (*)(Abs_T x,StdCPtr any))pSource,scndfn);
(*prMsg)("\n ");
pGraphList(x->Edges,-1,(void (*)(Abs_T x,StdCPtr any))pEdge,scndfn);
}
void RegSet_Print(RegSet_T x)
/* prints regular set to stdout; for debugging */
{ void (*prMsg)(c_string msg) = CurScnDfn.prMsg;
char buf[STD_BUFFLEN+1];
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
sprintf(buf,"RegSet_T %d =\n",RegSet_IMP(x)->id);
(*prMsg)(buf);
pGraphList
(
RegSet_IMP(x)->Nodes,0,(void (*)(Abs_T x,StdCPtr any))pNode,&CurScnDfn
);
(*prMsg)("\n");
}
void RegSet_Print_reentrant(ScnDfn_T curdfn, RegSet_T x)
/* reentrant version of RegSet_Print */
{ void (*prMsg)(c_string msg);
char buf[STD_BUFFLEN+1];
BUG_NULL(curdfn);
prMsg = curdfn->prMsg;
if( prMsg == (void (*)(c_string msg))NULL )
prMsg = prMsg_stdout;
sprintf(buf,"RegSet_T %d =\n",RegSet_IMP(x)->id);
(*prMsg)(buf);
pGraphList(RegSet_IMP(x)->Nodes,0,(void (*)(Abs_T x,StdCPtr any))pNode,curdfn);
(*prMsg)("\n");
}
static Scn_T Scn_dfnEnd_aux
(
ScnDfn_T scndfn, c_bool diagnose, c_bool* defining
)
{ int i; List(RegSet_Ts) graphs = NULL;
RegSet_T scanner; Scn_T scn;
bug0((*defining),"no definition");
for (i = 1; i < scndfn->topEntry; i++)
{
if( scndfn->Table[i].value != (RegSet_T)NULL )
{
graphs = cons(scndfn->Table[i].value,graphs);
fst(regset_t,graphs)->id = i;
}
}
scndfn->ConflictFlag = False;
scanner = RegSet_Merge(graphs, NULL,NULL);
terminalScanner(scndfn,scanner);
bug0(!scndfn->ConflictFlag,"aborted due to conflicts");
if (diagnose) RegSet_Print_reentrant(scndfn,scanner);
scn = ScnTable(scndfn,scanner);
for (i = 1; i < scndfn->topEntry; i++)
{
FreeMem(scndfn->Table[i].name);
if( scndfn->Table[i].value != (RegSet_T)NULL )
RegSet_Free(scndfn->Table[i].value);
}
*defining = C_False;
return scn;
}
Scn_T Scn_dfnEnd(bool diagnose)
/* completes and creates scanner definition
diagnose --> prints scanner definiton
*/
{
return Scn_dfnEnd_aux(&CurScnDfn,diagnose,&Scn_defining);
}
Scn_T Scn_dfnEnd_reentrant(ScnDfn_T curdfn, bool diagnose)
/* reentrant version of Scn_dfnEnd;
consumes 'curdfn'
*/
{ c_bool defining = C_True;
Scn_T scn = (Scn_T)NULL;
BUG_NULL(curdfn);
scn = Scn_dfnEnd_aux(curdfn,diagnose,&defining);
FreeMem(curdfn);
return scn;
}
/*I----------------------- Scanner group production ------------------------ */
#define MAX_GROUP_ENTRIES 50
Scn_T ScnGrp_dfnBegin(c_string name)
/* begins a scanner group definition;
uses 'name' as identifier
*/
{ scn_t res;
res = New(scn_t);
res->Name = StrCopy(name);
res->States = 0;
res->Tokens = 0;
res->StaEdg = (long* )NULL;
res->StaFin = (short* )NULL;
res->EdgeC = (wc_char* )NULL;
res->EdgeS = (long* )NULL;
res->TokId = (string* )NULL;
res->Flags = (byte* )NULL;
res->Groups = 0;
res->GrpScn = (scn_t* )NewMem(sizeof(scn_t)*MAX_GROUP_ENTRIES);
res->Switch = (short* )NULL;
res->dyckcnt = 0;
res->dyckidx = (short* )NULL;
res->dyckpat = (scn_t* )NULL;
return res;
}
void ScnGrp_dfnScanner(Scn_T group, Scn_T scanner)
/* adds 'scanner' to 'group'; consumes 'scanner' */
{ scn_t g = Scn_IMP(group), s = Scn_IMP(scanner);
int i;
BUG_NULL(g); BUG_NULL(s);
bug1(s->Groups == 0,"scanner group '%s' not allowed",s->Name);
bug1(s->Switch == (short*)NULL,"scanner '%s' already in group",s->Name);
bug0(g->Groups < MAX_GROUP_ENTRIES,"too many scanner defined");
for( i=0; i < g->Groups; ++i )
{
bug1
(
strcmp(g->GrpScn[i]->Name,s->Name),
"scanner with name '%s' already defined",s->Name
);
}
g->GrpScn[g->Groups] = s;
g->Groups += 1;
s->Switch = (short*)NewMem(sizeof(short)*s->Tokens);
for( i=0; i < s->Tokens; ++i ) s->Switch[i] = -1;
}
void ScnGrp_dfnSwitch(Scn_T group, c_string from, c_string token, c_string to)
/* adds context switch information for 'group';
'token' in scanner 'from' switches to scanner 'to'
*/
{ scn_t g = Scn_IMP(group);
int sfidx = -1, stidx = -1, i;
BUG_NULL(g);
for( i=0; i < g->Groups; ++i )
{
if( !strcmp(g->GrpScn[i]->Name,from) )
sfidx = i;
if( !strcmp(g->GrpScn[i]->Name,to) )
stidx = i;
if( sfidx >= 0 && stidx >= 0 ) break;
}
assert0( sfidx >= 0 && stidx >= 0, "scanner not found" );
for( i=0; i < g->GrpScn[sfidx]->Tokens; ++i )
{
if( !strcmp(g->GrpScn[sfidx]->TokId[i],token) )
{
g->GrpScn[sfidx]->Switch[i] = stidx; break;
}
}
assert0( i < g->GrpScn[sfidx]->Tokens, "token not found" );
}
int ScnGrp_dfnEnd(Scn_T group)
/* completes definition for 'group';
returns number of unreachable scanners
*/
{ scn_t g = Scn_IMP(group);
short* glink; int res = 0, i, j;
BUG_NULL(g);
glink = (short*)NewMem(sizeof(short)*g->Groups);
for( i=0; i < g->Groups; ++i )
{
glink[i] = ( i == 0 );
}
for( i=0; i < g->Groups; ++i )
{
for( j=0; j < g->GrpScn[i]->Tokens; ++j )
{
if( g->GrpScn[i]->Switch[j] >= 0 )
glink[g->GrpScn[i]->Switch[j]] = 1;
}
}
for( i=0; i < g->Groups; ++i )
{
if( glink[i] == 0 ) ++res;
}
FreeMem(glink);
return res;
}
styx-2.0.1/libstyx/reg_exp.c 0000666 0001750 0001750 00000037227 12103501533 012745 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [reg_exp.c] Regular Expression Evaluation */
/* */
/* Copyright (c) 1999 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "standard.h"
#include "symbols.h"
#include "scn_base.h"
#include "scn_imp.h"
#include "scn_gen.h"
#include "literal.h"
#include "otab.h"
#include "hmap.h"
#include "hset.h"
#include "sink.h"
#include "gstream.h"
#include "rexp_lim.h"
/*!
[reg_exp] implements a regular expression evaluator based on the
following regular expression syntax.
Literal
Construction
The module [prs_gen] performs two main tasks.
1) A set of functions will be used to dynamically create a BNF-like context
free grammar definition. ( reentrant )
2) The latter function create the corresponding parse table and nonterminal
classes.
The parse table is the input for the parse function.
*/
/* ------------------------ Definition interface -------------------------- */
CTX_T CTX_new(short cnt, c_string name)
/* make new context for program 'name' and 'cnt' arguments */
;
void CTX_free(CTX_T ctx); /* drop context 'ctx' */
void CTX_set
(
CTX_T ctx, short idx, c_string ide,
c_byte cat, c_byte typ, c_string dft
)
/* assign argument 'ide' of category 'cat', with type 'typ' and
default value 'dft' to context entry ctx[idx]
*/
;
void CTX_put(c_string env, CTX_T ctx)
/* put binary image of context 'ctx' */
;
CTX_T CTX_get(c_string env, c_string name)
/* get context from binary image [$'env'/'name'.cim] */
;
void CTX_usage(CTX_T ctx); /* print usage for context 'ctx' */
void CTX_C_Modul(c_string Environ, CTX_T Ctx, c_bool shortform)
/* compiles context 'ctx' to [$'Environ'/'Name'_cim.c] */
;
void CTX_sh_list(void); /* print shell context */
void CTX_list(CTX_T ctx); /* DEBUG; print context 'ctx' */
c_string CTX_dirname(void); /* path of the current program */
void CTX_interprete(int argc, c_string argv[])
/* process current program context */
;
/* ------------------------ Application interface ------------------------- */
void CTX_init(int argc, c_string argv[])
/* initialize and process current program context */
;
void CTX_quit(void); /* drop current program context */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/hpat.h 0000644 0001750 0001750 00000013225 12112434362 011321 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [hpat.h] Template / Pattern Evaluation */
/* */
/* Copyright (c) 1999 by D\olle, Manns, Steffen */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef hpat_INCL
#define hpat_INCL
#include "standard.h"
#include "scn_base.h"
#include "symbols.h"
#include "otab.h"
#include "gls.h"
#include "hpat_int.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
*/
/* ------------------------- Types & Macros ----------------------------- */
/*
*/
/* ------------------------------- Macros ------------------------------------ */
/*
Properties of nonterminals and their classes
*/
#define ACFG_NTTYP_LIST 1
#define ACFG_NTTYP_CLASS 2
#define ACFG_NTTYP_OPT 4
#define ACFG_NTTYP_NIL 8
#define ACFG_NTTYP_RECTYP 16
#define ACFG_NTTYP_REF0 32
#define ACFG_NTTYP_REF1 64
#define ACFG_NTTYP_START 128
#define ACFG_NTTYP_PRIM 256
#define ACFG_NTTYP_PRIMC 512
#define ACFG_NTTYP_EMPTY 1024
#define ACFG_NTTYP_RECREF 2048
#define ACFG_NTTYP_CONSREF 4096
#define ACFG_HAS_NTTYP(v,t) ( (((int)(v)) & ((int)(t))) > 0 )
/* ------------------------------- API --------------------------------------- */
c_bool acfg_init
(
PLR_Tab PTab, int** aPol, HS_Set** aNtm, HS_Set** aPrd, c_bool errmsg
)
/* creates & fills 'aPol', 'aNtm', 'aPrd' from parse table 'PTab'
'aPol' :- polymorph 'cons' classes
'aNtm' :- nonterminal partition
'aPrd' :- nonterminal class productions
*/
;
c_bool acfg_init_doc
(
PLR_Tab PTab, int** aPol, HS_Set** aNtm, HS_Set** aPrd
)
/* creates & fills 'aPol', 'aNtm', 'aPrd' from parse table 'PTab',
as needed for the generation of a refernce document
'aPol' :- nonterminal/class types/properties
'aNtm' :- nonterminal partition
'aPrd' :- nonterminal productions
*/
;
void acfg_quit(PLR_Tab PTab,int* aPol, HS_Set* aNtm, HS_Set* aPrd)
/* deletes 'aPol', 'aNtm' and 'aPrd'
( originally created from parse table 'PTab' )
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/scn_gen.h 0000644 0001750 0001750 00000013150 12112434362 011776 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [scn_gen.h] Scanner Generator */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef scn_gen_INCL
#define scn_gen_INCL
#include "scn_io.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
*/
/* ------------------------- Type of regular sets ------------------------- */
AbstractType(RegSet_T); /* Regular Set */
/* -------------------------- Disposing ----------------------------------- */
void RegSet_Free(RegSet_T g); /* frees regular set 'g' */
/* -------------------------- RegSet Constructors ------------------------- */
/*
*/
/* ------------------------------ Types ------------------------------------- */
AbstractType(PLR_Pdf); /* Abstract parser type */
/* ============================ Parse interface ============================= */
/* ---------------------------- Configuration ------------------------------- */
PLR_Pdf PLR_createPdf(PLR_Tab PTab, StdCPtr extCfg)
/* creates a parser for table 'PTab' and external configuration 'extCfg' */
;
void PLR_addGetF(PLR_Pdf Parser, int (*getToken)(PLR_Pdf Parser))
/* adds next token function 'getToken' to 'Parser' */
;
void PLR_addCurSyF(PLR_Pdf Parser, c_string (*getCurSy)(PLR_Pdf Parser))
/* adds current token name debug function 'getCurSy' to 'Parser' */
;
void PLR_addRedF
(
PLR_Pdf Parser,
StdCPtr (*redVal)(PLR_Pdf Parser, int symcnt, int prodId, c_bool accept)
)
/* adds reduction function 'redVal' to 'Parser' */
;
void PLR_addSftF
(
PLR_Pdf Parser, StdCPtr (*shiftVal)(PLR_Pdf Parser, int symbol)
)
/* adds shift function 'shiftVal' to 'Parser' */
;
void PLR_addErrF(PLR_Pdf Parser, void (*error)(PLR_Pdf Parser))
/* adds error function 'error' to 'Parser' */
;
void PLR_addDbgF(PLR_Pdf Parser, void (*debug)(PLR_Pdf Parser, StdCPtr val))
/* adds debug function 'debug' to 'Parser' */
;
void PLR_delPdf(PLR_Pdf Parser); /* removes 'Parser' */
StdCPtr PLR_CfgExt(PLR_Pdf Parser)
#define PLR_CFGEXT(type,pdf) ((type)PLR_CfgExt(pdf))
/* external configuration of 'Parser' */
;
PLR_Tab PLR_CfgTab(PLR_Pdf Parser); /* parse table of 'Parser' */
/* ---------------------- Parsing ------------------------------------------- */
c_bool PLR_parse(PLR_Pdf Parser, c_string StartSymbol, c_bool interprete)
/* does the parsing for start nonterminal 'StartSymbol'
interprete --> early reduction
*/
;
c_bool PLR_accept(PLR_Pdf Parser)
/* whether the parser accepts the EOF token */
;
StdCPtr PLR_topVal(PLR_Pdf Parser)
/* pops and returns the top stack value of 'Parser' */
;
ROW(StdCPtr) PLR_valStack(PLR_Pdf Parser)
/* returns the value stack of 'Parser' ( use with care ! ) */
;
/* ========================= Parse table interface ========================== */
/* --------------------------- Copy & Delete -------------------------------- */
PLR_Tab PLR_copyTab(PLR_Tab PTab); /* copies parse table 'PTab' */
void PLR_delTab(PLR_Tab PTab); /* removes parse table 'PTab' */
/* --------------------------- Accessing ------------------------------------ */
c_string PLR_language(PLR_Tab PTab); /* language name of parse table 'PTab' */
int PLR_conflictCnt(PLR_Tab PTab)
/* number of conflicts of parse table 'PTab';
available only after construction
*/
;
int PLR_tokenCnt(PLR_Tab PTab); /* number of tokens of parse table 'PTab' */
int PLR_nontermCnt(PLR_Tab PTab)
/* number of nonterminals of parse table 'PTab' */
;
int PLR_startCnt(PLR_Tab PTab)
/* number of startsymbols of parse table 'PTab' */
;
int PLR_symbolCnt(PLR_Tab PTab); /* number of symbols of parse table 'PTab' */
/*
The following functions require binary relations over a single domain.
*/
BS_Set BS_trans(BS_Set rel, INT SetCard)
/* reverse relation / transponent matrix rel' */
;
BS_Set BS_rclosure(BS_Set dst, BS_Set rel, INT SetCard)
/* reflexive closure dst = rel U id */
;
BS_Set BS_sclosure(BS_Set dst, BS_Set rel, INT SetCard)
/* symmetric closure dst = rel U rel' */
;
BS_Set BS_iclosure(BS_Set dst, BS_Set rel, INT SetCard)
/* (Warshall in N*N-Platz, vgl. Mehlhorn) transitive closure dst = rel+ */
;
BS_Set BS_closure(BS_Set dst, BS_Set rel, INT SetCard)
/* (Warshall) transitive, reflexive closure dst = rel* */
;
BS_Set BS_eclosure(BS_Set dst, BS_Set rel, INT SetCard)
/* equivalence relation dst = (rel U rel')* */
;
BS_Set BS_kern(BS_Set dst, BS_Set rel, INT SetCard)
/* kernel dst = rel\square(rel), requires rel = strict order */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/hpat_lim.h 0000644 0001750 0001750 00000000510 12112434362 012153 0000000 0000000 /* [hpat_lim.h] Scanner table for 'hpat' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef hpat_lim_INCL
#define hpat_lim_INCL
#include "scn_io.h"
#ifdef __cplusplus
extern "C" {
#endif
void Scn_get_hpat(Scn_T *scn); /* simulates a Scn_get */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/styx_cim.h 0000644 0001750 0001750 00000000505 12112434362 012221 0000000 0000000 /* [styx_cim.h] Context table for 'styx' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef styx_cim_INCL
#define styx_cim_INCL
#include "ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void CTX_init_styx(int argc, c_string argv[]); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/binimg.h 0000644 0001750 0001750 00000036645 12112434362 011645 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [binimg.h] Portable machine-independant binary format */
/* */
/* Copyright (c) 1993 by Lars D\olle, Heike Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef binimg_INCL
#define binimg_INCL
#include "standard.h"
#include "symbols.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Summary
[binimg] offers a set of functions to read and write binary files in a portable
machine-independant format. Within the STYX-system they are used to make data structures
persistent.
non-reentrant API:
For each supported data type exist a read and write function with the following signature.
| void put
The leading byte specifies the symbol type.
*/
void putSymbol(symbol v); /* put a symbol to file */
void fputSymbol(BinImg_T img, symbol v); /* put a symbol to file */
void getSymbol(symbol *v); /* get a symbol from file */
void fgetSymbol(BinImg_T img, symbol *v)
/* get a symbol from file 'img' (reentrant) */
;
/* ------------------------------- Functions ------------------------------ */
/*
For technical reasons the functions must be defined in a global table.
They are externally represented by a symbolic name representing the key
to the function table entry. ( see also [glo_tab] )
*/
void putFunction(StdCPtr v)
/* put a function to file
raises error if 'v' not 'Glo'bally defined
*/
;
void fputFunction(BinImg_T img, StdCPtr v)
/* put a function to file 'img' (reentrant)
raises error if 'v' not 'Glo'bally defined
*/
;
void getFunction(StdCPtr *v)
/* get a function from file
raises error if 's' not 'Glo'bally defined
*/
;
void fgetFunction(BinImg_T img, StdCPtr *v)
/* get a function from file 'img' (reentrant)
raises error if 's' not 'Glo'bally defined
*/
;
/* ---------------------------- Abstract types ---------------------------- */
/*
In the case of a generic data type ( e.g. 'List(Alpha)') a 'put'-function
typically looks like:
non-reentrant API:
| void putList(List(Alpha) v, void putAlpha(Alpha v))
| {
| putInt(List_length(v));
| for (; !List_null(v); v = List_rest(v))
| putAlpha(List_first(Alpha,v));
| }
reentrant API:
| void putList(BinImg_T img, List(Alpha) v, void putAlpha(BinImg_T img,Alpha v))
| {
| fputInt(img,List_length(v));
| for (; !List_null(v); v = List_rest(v))
| putAlpha(img,List_first(Alpha,v));
| }
In the case of a heterogen parameter type ("Object") the user has to save
the corresponding 'get'-function together with the value.
*/
void putAbstract(Abs_T v, void putData(Abs_T v), void getData(Abs_T *v))
/* put abstract data to file */
;
void fputAbstract
(
BinImg_T img, Abs_T v,
void putData(BinImg_T img,Abs_T v),
void getData(BinImg_T img,Abs_T *v)
)
/* put abstract data to file 'img' (reentrant) */
;
void getAbstract(Abs_T *v); /* get abstract data from file */
void fgetAbstract(BinImg_T img, Abs_T *v)
/* get abstract data from file 'img' (reentrant) */
;
/* -------------------------------- Pointer ------------------------------------------- */
/*
References to multiple or cyclic referenced structures ( except symbols and functions )
can't be simply expanded if the representation should be unique.
For cases like this we support the following function.
non-reentrant API:
| void putReference(Abs_T v, void putData(Abs_T v));
reentrant API:
| void fputReference(BinImg_T img, Abs_T v, void putData(BinImg_T img,Abs_T v));
This function outputs a reference number for this structure and only in the case of the
first reference the structure values.
*/
void putReference(Abs_T v, void putData(Abs_T v)); /* put a pointer to file */
void fputReference
(
BinImg_T img, Abs_T v, void putData(BinImg_T img,Abs_T v)
)
/* put a pointer to file 'img' (reentrant) */
;
void getReference(Abs_T *v, void getData(Abs_T *v))
/* get a pointer from file */
;
void fgetReference
(
BinImg_T img, Abs_T *v, void getData(BinImg_T img,Abs_T *v)
)
/* get a pointer from file 'img' */
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/sysbase1.h 0000644 0001750 0001750 00000015230 12112434362 012115 0000000 0000000 /* -------------------------------------------------------------------------- */
/* */
/* [sysbase1.h] Standard Definitions ( Part 1 ) */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* -------------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef sysbase1_INCL
#define sysbase1_INCL
#include "sysbase0.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ----------------- Byte/String & VarArg Handling -------------------------- */
#define CORE fprintf(STDOUT,"Objects = %ld\n", ObjCount())
#define BUG_CORE bug1(ObjCount() == 0,"%ld objects",ObjCount())
#define BUG_CORE_EX(c) bug1(ObjCount()+(c) == 0,"%ld objects",ObjCount()+(c))
#define New(TYPE) (TYPE)NewMem(SizeOf(TYPE))
StdCPtr BytCopy(StdCPtr bytes, long len)
/* copies 'len' bytes of byte array 'bytes';
allocs memory
*/
;
c_bstring BytToBStrCopy(StdCPtr bytes, long len)
/* constructs a binary string
from 'len' bytes of byte array 'bytes';
allocs memory
*/
;
c_string BytToHStrCopy(StdCPtr bytes, long len)
/* creates a hex string from 'len' bytes of byte array 'bytes';
allocs memory
*/
;
c_string BStrToHStrCopy(c_bstring bstr)
/* creates a hex string from binary string 'bstr';
allocs memory
*/
;
c_bool IsSpaceStr(c_string s)
/* whether string 's' is empty or
only contains space characters
*/
;
size_t WCStrLen(wc_string ws)
/* number of wide characters in string 'ws'
( without the termination character )
*/
;
wc_string SubWCStrCopy(wc_string str, long len)
/* copies 'len' wide characters of string 'str';
appends 0, allocs memory
*/
;
wc_string WCStrCopy(wc_string Str)
/* copies wide character string 'Str'; allocs memory */
;
c_string WCToStrCopy(wc_string wc)
/* copies wide character string 'wc' into a string;
without conversion, allocs memory
*/
;
wc_string WCStrToLower(wc_string st)
/* converts all letters in wide character string 'st' to lower case */
;
wc_string WCStrToUpper(wc_string st)
/* converts all letters in wide character string 'st' to upper case */
;
c_string SubStrCopy(c_string str, long len)
/* copies 'len' characters of string 'str';
appends 0, allocs memory
*/
;
c_string StrCopy(c_string Str); /* copies string 'Str'; allocs memory */
c_string StrToLower(c_string st)
/* converts all letters in string 'st' to lower case */
;
c_string StrToUpper(c_string st)
/* converts all letters in string 'st' to upper case */
;
Any_T* MakeArgLst(va_list args, int fixed_cnt, ...)
/* MakeArgLst is a portable replacement for GetArgLst coping with the
* idiosyncracies of different va_list implementations. Since there is
* no portable way to pass a va_list (caller's variable arguments)
* through '...', it has to be moved before the caller's fixed args.
* fixed_cnt is the count of the caller's fixed arguments.
*
* Sample usage:
* variadic_func(int argcnt, TYPEA a, TYPEB b, TYPEC c, ...)
* {
* va_list va;
* Any_T *argl;
* va_start(va,c); // Must use the *last* fixed argument here
* argl = MakeArgLst(va, 4, argcnt, a, b, c);
* va_end(va);
* // make use of argl
* FreeMem(argl);
* }
*
* For an in depth discussion of variadic functions including
* portability, see libc.info Node: Variadic Functions.
*/
;
/* ------------- Workaround for missing C library functions ----------------- */
wc_string wcsstr_aux(wc_string s1, wc_string s2)
/* workaround for 'wcsstr' */
;
c_string strstr_aux(c_string s1, c_string s2); /* workaround for 'strstr' */
wc_string wcschr_aux(wc_string s, wc_char c); /* workaround for 'wcschr' */
c_string strchr_aux(c_string s, int c); /* workaround for 'strchr' */
wc_string wcsrchr_aux(wc_string s, wc_char c); /* workaround for 'wcsrchr' */
c_string strrchr_aux(c_string s, int c); /* workaround for 'strrchr' */
int strcspn_aux(c_string s, c_string reject); /* workaround for 'strcspn' */
StdCPtr memcpy_aux(StdCPtr dst, StdCPtr src, int n)
/* workaround for 'memcpy' */
;
int memcmp_aux(StdCPtr dst, StdCPtr src, int n); /* workaround for 'memcmp' */
c_string getcwd_aux(c_string buffer, int bufsize)
/* workaround for 'getcwd'; evaluates $PWD */
;
/* -------------------------- System Error ---------------------------------- */
c_string GetSystemError(void); /* system error message; allocs memory */
c_string GetSystemError_noalloc(c_string buffer, int bufsize)
/* system error message */
;
/* -------------------------- Program Execution ----------------------------- */
#define STD_CMD_NOWAIT 0
#define STD_CMD_WAIT_INIT 1
#define STD_CMD_WAIT 2
int runprg(c_string cmd, int cmdflg)
/* executes program 'cmd'
cmdflg=STD_CMD_NOWAIT --> asynchron, non-blocking
cmdflg=STD_CMD_WAIT_INIT --> waits for initialisation
cmdflg=STD_CMD_WAIT --> synchron, blocking
*/
;
/* ----------------- DLL & dynamic Function Call Support -------------------- */
typedef StdCPtr (*PCFUN)();
StdCPtr apply_fun_portable(PCFUN f, int cnt, StdCPtr* args)
/* portable dynamic call of C-function 'f'
with 'cnt' parameters in 'args'
( upto 9 parameters )
*/
;
StdCPtr apply_fun(PCFUN f, int cnt, StdCPtr* args)
/* dynamic call of C-function 'f'
with 'cnt' parameters in 'args'
( restricted to intel )
*/
;
AbstractType( DL_Hdl ); /* Abstract handle type */
#define DL_LOAD_LAZY 0
#if !defined(STYX_CONFIG_OSMS) && (!defined(HAVE_CONFIG_H) || (defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H)))
#define DL_LAZY RTLD_LAZY
#define DL_NOW RTLD_NOW
#define DL_BINDING_MASK RTLD_BINDING_MASK
#define DL_GLOBAL RTLD_GLOBAL
#define DL_LOCAL RTLD_LOCAL
#else
#define DL_LAZY 0
#define DL_NOW 0
#define DL_BINDING_MASK 0
#define DL_GLOBAL 0
#define DL_LOCAL 0
#endif
DL_Hdl DL_open(c_string dlname, int flag)
/* loads dll 'dlname' in mode 'flag' ( ERROR: NULL )
LINUX: flag=RTLD_LAZY|RTLD_NOW|-1=RTLD_NOW, MS: not used
*/
;
int DL_close(DL_Hdl dlhdl)
/* detaches dll 'dlhdl' ( SUCCESS: 0, ERROR: > 0 ) */
;
StdCPtr DL_symbol(DL_Hdl dlhdl, c_string symname)
/* address of symbol 'symname' within dll 'dlhdl' ( ERROR: NULL )
LINUX: function|data, MS: function
*/
;
c_string DL_error(void); /* dll load error; allocs memory */
c_string DL_error_noalloc(c_string buffer, int bufsize); /* dll load error */
/* ---------------------- Network Support ----------------------------------- */
c_string UserName(void); /* login name; allocs memory */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/ptm__cim.h 0000644 0001750 0001750 00000000510 12112434362 012145 0000000 0000000 /* [ptm__cim.h] Context table for 'ptm_img' */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef ptm__cim_INCL
#define ptm__cim_INCL
#include "ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void CTX_init_ptm_img(int argc, c_string argv[]); /* */
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/prs_io.h 0000644 0001750 0001750 00000006005 12112434362 011656 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [prs_io.h] LALR(1) Parser/Generator: parse table input/output */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef prs_io_INCL
#define prs_io_INCL
#include "prs_dfn.h"
#include "binimg.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
This module provides functions that
1) generate a C module for a given parse table
2) unload a parse table to a binary image file
3) load a parse table from a binary image file.
*/
/* ------------------------------ C-Module ---------------------------------- */
void PLR_CTab_Source(FILE* fp, c_string fid, PLR_Tab PTab)
/* writes source for parse table 'PTab' to file 'fp';
produces a source header if filename 'fid' is not empty
*/
;
void PLR_CTab_Modul(c_string Environ, PLR_Tab PTab, c_bool shortform)
#define PLR_printCTab PLR_CTab_Modul
/* creates source [$'Environ'/]
Separator between token ID and pattern
*/
#define SCN_TOK_Other "[other]"
#define SCN_SEP_TOK_ID_PATTERN '@'
AbstractType( Scn_T ); /* Abstract scanner type */
/* ------------------------------ Basics ------------------------------------ */
c_string Scn_LanguageId(Scn_T x)
/* language or group name of scanner definition 'x' */
;
Scn_T Scn_copy(Scn_T x); /* copies scanner definition 'x' */
void Scn_free(Scn_T x); /* frees scanner definition 'x' */
/* ----------------------------- Binary Image ------------------------------- */
Scn_T Scn_fget_bin(BinImg_T img)
/* loads a scanner definition
from binary image 'img' (reentrant)
*/
;
Scn_T Scn_get_bin(void)
/* loads a scanner definition
from the current ( previously opened ) image
*/
;
void Scn_get(c_string Language, Scn_T *x)
/* loads a scanner definition named 'Language' into 'x'
from image [$PATH/]
*/
/* -------------------- Types ------------------------------------------- */
AbstractType(Reg_T) // Abstract regular expression evaluation type
;
/* -------------------- Creating & Disposing ---------------------------- */
void REG_drop(Reg_T pReg); /* removes regular expression evaluator 'pReg' */
Reg_T REG_create
(
c_string szRegExp, long lLen,
c_string szCharSet, c_bool bIgnCase
)
#define REG_CREATE(exp) REG_create((exp),-1,(c_string)NULL,C_False)
#define IREG_CREATE(exp) REG_create((exp),-1,(c_string)NULL,C_True)
/* creates a regular expression evaluator from string 'szRegExp'
'lLen' : -1 or string size in bytes, incl. terminating bytes
'szCharSet': NULL,"" or character set name
( UCS4, UTF-8, MS:CodePage / GNU:iconv-based )
'szCharSet' = NULL,"" --> single byte string
'lLen' = -1 --> null-terminated single byte or utf8 string
RC: evaluator or NULL
*/
;
c_bool REG_recreate
(
Reg_T pReg, c_string szRegExp, long lLen,
c_string szCharSet, c_bool bIgnCase
)
#define REG_RECREATE(reg,exp) REG_recreate((reg),(exp),-1,(c_string)NULL,C_False)
#define IREG_RECREATE(reg,exp) REG_recreate((reg),(exp),-1,(c_string)NULL,C_True)
/* updates regular expression evaluator 'pReg'
from string 'szRegExp'
( 'lLen', 'szCharSet' --> see function 'REG_create' )
RC: true <--> OK
*/
;
/* ------------------------- Evaluation --------------------------------- */
c_string REG_match
(
Reg_T pReg,
c_string szTxt, long lTxtLen, c_string szCharSet,
long* lPatLen
)
#define REG_MATCH(reg,txt,len) REG_match((reg),(txt),-1,(c_string)NULL,(len))
/* applies regular expression evaluator 'pReg' to string 'szTxt'
( 'lTxtLen', 'szCharSet' --> see function 'REG_create' )
RC: start postion of first matched value in 'szTxt' or NULL
'lPatLen' != NULL --> length of first matched value in bytes
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/hset.h 0000644 0001750 0001750 00000024355 12112434362 011336 0000000 0000000 /*----------------------------------------------------------------------------*/
/* */
/* [hset.h] Type: Hash Set/Relation */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/*----------------------------------------------------------------------------*/
/* File generated by 'ctoh'. Don't change manually. */
#ifndef hset_INCL
#define hset_INCL
#include "standard.h"
#include "prim.h" /* for primitive types */
#ifdef __cplusplus
extern "C" {
#endif
/*
[hset] implements sets and relations based on finite maps.
*/
/* There is no Copy Semantic for Domain Values ! */
/* A Set Operation on a special binary Relations leads to */
/* an ordinary binary Relation. */
/* ------------------------------ Types ------------------------------------- */
AbstractType(HS_Set); /* Abstract set/relation type */
AbstractType(HS_Elm); /* Abstract set/relation element type */
AbstractType(HS_Dom); /* Abstract tuple component type */
AbstractType(HS_Itr); /* Abstract set/relation iterator type */
#define SET(type) HS_Set /* Polymorphic SET - Type */
/* -------------------------- Set/Relation Iterator ------------------------- */
/* No changes are allowed on the underlaying set/relation while iterating ! */
HS_Itr HS_createItr(HS_Set set)
#define HS_CREATE_ITR HS_createItr
/* creates an iterator on set/relation 'set' */
;
void HS_dropItr(HS_Itr itr)
#define HS_DROP_ITR HS_dropItr
/* removes iterator 'itr' */
;
c_bool HS_emptyItr(HS_Itr itr)
#define HS_EMPTY_ITR HS_emptyItr
/* whether iterator 'itr' is empty */
;
void HS_get(HS_Itr itr, HS_Elm* elm)
#define HS_GET(itr,pElm) HS_get(itr,(HS_Elm*)(pElm))
/* get the next element from iterator 'itr' into 'elm' */
;
/* Character set ' Literal ... ' String " Literal ... " Any character . Character range
Expression .. Expression
( single character expressions )Subexpression ( Expression ) Option [ Expression ] Expression ? Iteration ( 0.. ) { Expression } Expression * Iteration ( 1.. ) Expression + Iteration ( n ) Expression Number Iteration ( n..m ) Expression Number, Number Union Expression | Expression Difference Expression - Expression Concatenation Expression Expression
moved to [ptm]
*/
#define XGLS_keycom_Skip XPT_keycom_Skip
#define GLS_keycom_Skip PT_keycom_Skip
#define GLS_ign_Skip PT_ign_Skip
/* -------------------------- Token services ------------------------------ */
PT_Term GLS_Tok_cfg(GLS_Tok x); /* the embedded lanuage of token 'x' */
symbol GLS_Tok_symbol(GLS_Tok x); /* the symbol of token 'x' */
c_string GLS_Tok_string(GLS_Tok x); /* the string value of token 'x' */
c_bool GLS_Term_Tok(PT_Term x, GLS_Tok *t); /* Term to token selector */
/* --------------------------- List Construction -------------------------- */
PT_Term GLS_Lst_nil_mk(void); /* nil production */
PT_Term GLS_Lst_cons_mk(PT_Term a, PT_Term b); /* cons production */
PT_Term XGLS_Lst_nil_mk(void); /* nil production (xaron) */
PT_Term XGLS_Lst_cons_mk(PT_Term a, GLS_Lst(PT_Term) *b)
/* cons production (xaron ALT? Speculate?) */
;
PT_Term X4GLS_Lst_cons_mk(PT_Term a, GLS_Lst(PT_Term) *b)
/* cons production (xaron) */
;
/* --------------------------- List service -------------------------------- */
c_bool GLS_Term_Lst(PT_Term x, GLS_Lst(PT_Term) *lst)
/* Term to GLS_Lst selector */
;
c_bool GLS_Lst_nil(GLS_Lst(PT_Term) x)
#define GLS_EMPTY(term) ( GLS_Lst_nil((PT_Term)(term)) )
/* nil - selector */
;
c_bool GLS_Lst_cons(GLS_Lst(PT_Term) x, PT_Term* fst_t, GLS_Lst(PT_Term)* rst_t)
/* cons - selector */
;
PT_Term GLS_Lst_first(GLS_Lst(PT_Term) x)
#define GLS_FIRST(type,term) ( (type)GLS_Lst_first((GLS_Lst(PT_Term))(term)) )
/* first element in list 'x' */
;
PT_Term GLS_Lst_rest(GLS_Lst(PT_Term) x)
#define GLS_REST(type,term) \
( (GLS_Lst(type))GLS_Lst_rest((GLS_Lst(PT_Term))(term)) )
/* remaining elements in list 'x' */
;
int GLS_Lst_length(GLS_Lst(PT_Term) x)
#define GLS_LENGTH(term) ( GLS_Lst_length((GLS_Lst(PT_Term))(term)) )
/* length of list 'x' */
;
PT_Term GLS_Lst_nth(GLS_Lst(PT_Term) x, int nth)
#define GLS_NTH(type,term,nth) ((type)GLS_Lst_nth((GLS_Lst(PT_Term))(term),nth))
/* nth element in list 'x' ( nth >= 1 ) */
;
/* --------------------------- Option service ------------------------------ */
c_bool GLS_Term_Opt(PT_Term x, GLS_Opt(PT_Term) *opt)
/* Term to GLS_Opt selector */
;
c_bool GLS_Opt_none(GLS_Opt(PT_Term) x)
#define GLS_OPT_NONE(term) ( GLS_Opt_none((PT_Term)(term)) )
/* none - selector */
;
c_bool GLS_Opt_some(GLS_Opt(PT_Term) x)
#define GLS_OPT_SOME(term) ( GLS_Opt_some((PT_Term)(term)) )
/* some - selector */
;
PT_Term GLS_Opt_term(GLS_Opt(PT_Term) x)
#define GLS_OPT_TERM(type,term) ( (type)GLS_Opt_term((GLS_Opt(PT_Term))(term)) )
/* element in option 'x' */
;
/* ---------------------- Convenient iterator macros ----------------------- */
#define GLS_FORALL(it,li) for( (it) = ((PT_Term)(li)); \
! GLS_EMPTY(it); \
it = GLS_REST(PT_Term,it) )
#define GLS_FORALLI(it,li,c) for( c=0, (it) = ((PT_Term)(li)); \
! GLS_EMPTY(it); \
++c, it = GLS_REST(PT_Term,it) )
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/ptm_pp.h 0000644 0001750 0001750 00000010475 12112434362 011670 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [ptm_pp.h] Parse Tree Transformation & Pretty Printing */
/* */
/* Copyright (c) 1995 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef ptm_pp_INCL
#define ptm_pp_INCL
#include "ptm.h"
#include "prs.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
The module [ptm_pp] supports some means for source-source-transformations.
1) It performs a tree-to-tree transformation based on the corresponding
grammar specifications. It handles comments, too.
source tree based on CFG 1
specification of CFG 2
--------------------------------------------> concrete target tree
abstraction(CFG 1) = abstraction(CFG 2) based on CFG 2
regexp(token(CFG 1)) = regexp(token(CFG 2))
2) It provides the pretty printing of parse trees. This is usefull after
a transformation, because the target tree doesn't contain any position
information.
Note:
This module is still under construction. The main thing todo refer to the
layout results which are some times broken.
Embedded languages won't be supported, either.
Using the reentrant interface functions you can perform multiple
transformations at a time.
*/
/* ---------------------------- Macros ------------------------------------- */
/*
*/
/* ----------------------------- Init & Quit -------------------------------- */
void Glo_init(void); /* inits [glo_tab] */
void Glo_quit(void); /* quits [glo_tab] */
/* ----------------------------- Table access ------------------------------- */
void Glo_def(symbol Name, Abs_T Value)
/* adds global ( 'Name' <--> 'Value' ) */
;
void Glo_rmv(symbol Name); /* deletes global 'Name' */
c_bool Glo_key_known(symbol Name); /* whether 'Name' is defined */
c_bool Glo_val_known(Abs_T Value); /* whether 'Value' is defined */
Abs_T Glo__val(symbol Name)
#define Glo_val(T,N) ((T)Glo__val(N))
/* value defined for 'Name' */
;
symbol Glo_key(Abs_T Value); /* name defined for 'Value' */
symbol Glo_objkey_mk(symbol Lib, symbol Obj)
/* constructs key for loadable object */
;
c_bool Glo_objkey_de(symbol glokey, symbol* Lib, symbol* Obj)
/* destructs key of loadable object */
;
StdCPtr Glo_load(symbol Lib, symbol Obj, c_bool saveObj)
/* loads the object if not already defined
'saveObj' --> saves it in the global table
*/
;
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/sysbase0.h 0000644 0001750 0001750 00000022650 12112434362 012120 0000000 0000000 /* -------------------------------------------------------------------------- */
/* */
/* [sysbase0.h] Standard Definitions ( Part 0 ) */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* -------------------------------------------------------------------------- */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef sysbase0_INCL
#define sysbase0_INCL
#include "styconf0.h"
#include "syscbhdl.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ---------------------- Global Types -------------------------------------- */
#ifdef _MSDOS
typedef long INT;
typedef long LONG_INT;
#define __FAR __far
#define __HUGE __huge
typedef void __HUGE *HugeCPtr;
#else
typedef int INT;
typedef long int LONG_INT;
#define __FAR
#define __HUGE
#define HugeCPtr StdCPtr
#define NewHMem NewMem
#define FreeHMem FreeMem
#endif
typedef void *StdCPtr;
#if !defined( __GNUC__ )
typedef signed char c_int8;
typedef signed short c_int16;
typedef signed long c_int32;
typedef unsigned char c_uint8;
typedef unsigned short c_uint16;
typedef unsigned long c_uint32;
#if defined(STYX_CONFIG_OSMS) && defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64
#define STYX_CONFIG_TINT64
typedef signed __int64 c_int64;
typedef unsigned __int64 c_uint64;
#endif
#else /*__GNUC__*/
#define STYX_CONFIG_TINT64
typedef int8_t c_int8;
typedef int16_t c_int16;
typedef int32_t c_int32;
typedef int64_t c_int64;
typedef u_int8_t c_uint8;
typedef u_int16_t c_uint16;
typedef u_int32_t c_uint32;
typedef u_int64_t c_uint64;
#endif
#define ConcreteImp(Name) struct Name##_imp
#define ConcreteDecl(Name) typedef ConcreteImp(Name) *Name
#define ConcreteType(Name) typedef ConcreteImp(Name) *Name; ConcreteImp(Name)
#define SizeOf(Name) sizeof(ConcreteImp(Name))
#define ExternalType(TYPENAME) ConcreteType(TYPENAME)
#define ExternalDecl(TYPENAME) ConcreteDecl(TYPENAME)
#define AbstractType(TYPENAME) typedef StdCPtr TYPENAME
#define AbstractHugeType( TYPENAME ) \
typedef HugeCPtr TYPENAME
#define Tupel( TYPENAME ) \
struct TYPENAME
AbstractType( Abs_T );
AbstractType( Any_T );
#define ABS_CAST(t,a) ((t)(long)(a))
#define intCAST(a) ABS_CAST(int,a)
/*NOCONVERSION*/
typedef unsigned char c_byte;
typedef unsigned short c_word;
#ifndef __cplusplus
typedef c_byte byte;
typedef c_word word;
#endif
/*NOCONVERSION*/
#define c_bool int
#define C_False 0
#define C_True 1
#ifndef __cplusplus
#define bool c_bool
#define False C_False
#define True C_True
#endif
/*NOCONVERSION*/
typedef c_byte *c_bstring; /* sizeof(long) Bytes Len, Len Bytes */
typedef char *c_string;
#ifndef __cplusplus
typedef c_string string;
#endif
#if defined(WEOF)
typedef wint_t wc_int;
typedef wchar_t wc_char;
typedef wchar_t *wc_string;
#define WCHAR_LITERAL(c) L##c
#else
typedef unsigned long wc_int;
typedef unsigned long wc_char;
typedef unsigned long *wc_string;
#define WCHAR_LITERAL(c) ((unsigned long)c)
#endif
#define OBJ_REF(obj) ( &(obj) )
#define REF_OBJ(objref) ( *(objref) )
#define _ (NULL)
#define STD_BUFFLEN 512
#define ERR_BUFFLEN 4096
#define _NO_DLL_EXPORT_
#if defined( _MSDOS ) || defined( _WIN32 )
#define _DLL_EXPORT_DECL_ extern __declspec( dllexport )
#define _DLL_EXPORT_ __declspec( dllexport )
#define _DLL_IMPORT_ __declspec( dllimport )
#define _C_DECL_ __cdecl
#else
#define _DLL_EXPORT_DECL_ extern
#define _DLL_EXPORT_
#define _DLL_IMPORT_
#define _C_DECL_
#endif
/* -------------------- CommandLine I/O & Exception ------------------------- */
FILE* StdOutFile(void)
#define STDOUT StdOutFile()
/* stdout */
;
FILE* StdErrFile(void)
#define STDERR StdErrFile()
/* stderr */
;
void fprint_raw(FILE* fp, c_string s, size_t size)
/* prints string 's' in a printable form to file 'fp'
'size' >= 0: number of characters to print
*/
;
void prMsg_stdout(c_string s)
/* prints string 's' in a printable form to stdout */
;
void prMsg_stderr(c_string s)
/* prints string 's' in a printable form to stderr */
;
void AbortApp(c_string errmsg)
#define STD_ERREXIT AbortApp("")
/* aborts application with error message 'errmsg' */
;
PHDL_TRAP getTrapHdl(void); /* gets the trap handler */
void setTrapHdl(PHDL_TRAP h_trap)
/* sets a trap handler
( xaron error callback )
*/
;
PHDL_ABORT getErrExitHdl(void); /* gets the abort handler */
void setErrExitHdl(PHDL_ABORT h_abort); /* sets an abort handler */
PHDL_FREEMEM getFreeMemHdl(void)
/* gets the handler to organize free memory from heap */
;
void setFreeMemHdl(PHDL_FREEMEM h_freemem)
/* sets a handler to organize free memory from heap */
;
void initStdFiles(FILE* out, FILE* err); /* overwrites stdout, stderr */
void quitStdFiles(void); /* resets stdout, stderr */
/* -------------------- Thread/Process Synchronisation ---------------------- */
StdCPtr initSem(c_string id, int maxcnt, int initcnt)
/* creates or opens semaphore 'id [NULL]' to synchronize
a maximum of 'maxcnt' concurrent threads
with an initial value of 'initcnt'
RC: semaphore or NULL
non-MS: 'id', 'maxcnt' not used
*/
;
c_bool quitSem(StdCPtr sem)
/* closes and - on OK - destroys semaphore 'sem'
RC: True=OK
*/
;
int waitSem(StdCPtr sem)
/*
waits and enters critical section 'sem' ( blocking )
RC: 1=OK, 0=occupied, -1=error
*/
;
int trySem(StdCPtr sem)
/*
tries to enter critical section 'sem' ( non-blocking )
RC: 1=OK, 0=occupied, -1=error
*/
;
c_bool postSem(StdCPtr sem, int cnt)
/*
leaves critical section 'sem' and releases 'cnt' resources
RC: True=OK
non-MS: 'cnt' not used (=1)
*/
;
/* -------------------- Error Handling -------------------------------------- */
typedef void (*PF_ERROR)(c_bool cond, c_string format, ...);
void ForceCore(void)
/* since we didn't find an appropriate function in the c-lib */
;
PF_ERROR _AssCheck(c_string kind, c_string file, int line)
/* saves assertion type, source position and
returns assert function
*/
;
#define c_assert (*(_AssCheck("Restriction error",__FILE__,__LINE__)))
#define c_bug (*(_AssCheck("Internal error", __FILE__,__LINE__)))
#define C_BUG c_bug(C_False,"")
#ifndef __cplusplus
#define assert c_assert
#define bug c_bug
#define BUG C_BUG
#endif
#define assert0(cond,txt) ((!(cond)) ? (c_assert(C_False,(txt)),0):0)
#define assert1(cond,txt,a1) ((!(cond)) ? (c_assert(C_False,(txt),(a1)),0):0)
#define assert2(cond,txt,a,b) ((!(cond)) ? (c_assert(C_False,(txt),(a),(b)),0):0)
#define bug0(cond,txt) ((!(cond)) ? (c_bug(C_False,(txt)),0):0)
#define bug1(cond,txt,a1) ((!(cond)) ? (c_bug(C_False,(txt),(a1)),0):0)
#define bug2(cond,txt,a,b) ((!(cond)) ? (c_bug(C_False,(txt),(a),(b)),0):0)
#define BUG_NULL(obj) bug0( (StdCPtr)(obj) != (StdCPtr)NULL, \
"Null Object" )
#define BUG_VRNG(val,min,max) bug0( (val) >= (min) && (val) <= (max), \
"Value out of Range" )
#define BUG_RNG0(val,max) BUG_VRNG((val),0,(max)-1)
#define BUG_RNG1(val,max) BUG_VRNG((val),1,(max))
#define BUG_VMIN(val,min) bug0( (val) > (min), "Value below Minimum" )
#define BUG_VEQU(lft,rgt) bug0( (lft) == (rgt), "Values not equal" )
#define BUG_VNEQ(lft,rgt) bug0( (lft) != (rgt), "Values equal" )
#define BUG_MOD0(lft,rgt) bug0( (rgt) > 0 && ! ( (lft) % (rgt) ), \
"Non Zero Modulo" )
/*
Usage of the macros 'assert', 'bug':
assert | bug ( condition, which has to be true,
message format string ( see printf ),
any further parameter, according to the above format string );
*/
/* ---------------------------- System-Init & Quit -------------------------- */
void sysbase_init(void); /* initializes module ( for thread-savety ) */
void sysbase_quit(void); /* terminates module ( for thread-savety ) */
StdCPtr sysbase_sem(void); /* system semaphore ( for thread-savety ) */
/* ---------------------------- Global Macros ------------------------------- */
#define I32_HIGHVAL(v) ( (short)(((long)(v)) >> 16) )
#define I32_LOWVAL(v) ( (short)(((long)(v)) & 0xFFFFL) )
#define SET_I32_VAL(h,l) ( ((((long)(h)) << 16) & 0xFFFF0000L) | \
(((long)(l)) & 0x0000FFFFL) )
#define STR_EMPTY(s) ( (s) == (c_string)NULL || *(s) == '\0' )
#define INRANGE(a,x,b) ( ( (a) <= (x) ) && ( (x) <= (b) ) )
#define ABS(x) ( (x) < 0 ? - (x) : (x) )
#define MAX(a,b) ( (a) < (b) ? (b) : (a) )
#define MIN(a,b) ( (a) < (b) ? ( a ) : (b) )
#define EQSIGN(a,b) ( ( ( (a) <= 0 ) && ( (b) <= 0 ) ) || \
( ( (a) >= 0 ) && ( (b) >= 0 ) ) )
#define FTAB(F,N) fprintf(F,"\n%*s",N,"")
#define FNLIND(F) FTAB(F,indent)
#define FNL(F) fprintf(F,"\n")
#define TAB(N) FTAB(STDOUT,N)
#define NLIND TAB(indent)
#define NL FNL(STDOUT)
#define FPCHR(F,C) fprintf(F,"%c",C)
#define PCHR(C) FPCHR(STDOUT,C)
#define FPNLSNL(F,S) fprintf(F,"\n%s\n",S)
#define PNLSNL(F,S) FPNLSNL(STDOUT,S)
#define HERE fprintf(STDOUT,"File: %s, Line: %d\n",__FILE__,__LINE__)
#ifdef __cplusplus
}
#endif
#endif
styx-2.0.1/inc/scn_abs.h 0000644 0001750 0001750 00000017142 12112434362 011777 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [scn_abs.h] Abstract Scanner Interface */
/* */
/* Copyright (c) 2002 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* File generated by 'ctoh'. Don't change manually. */
#ifndef scn_abs_INCL
#define scn_abs_INCL
#include "symbols.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
It is possible to define multiple startsymbols and comment tokens.
This creation process is not reentrant. You must synchronize the access
to the function within threads.
*/
/*
The following rules define the abstract syntax. On this base the nonterminal
classes are created.
A) well-formed productions:
1. let X :nil#* : <0 members>
2. let X :cons#*: Y Z <2 members: Y = member && Z = nonterminal>
3. let X :ign#+ : Y <1 nonterminal>
4. let X :name : X1 .. Xn
based on the following macro definition syntax and evaluation process
during the lexical analysis:
#include Path
supports modular grammar design
The macro will be replaced by the content of source file 'Path' and
then rescanned.
#macro Name ( FormalParameter , ... ) = Text #end
supports text replacement
Parameter and replacement text are optional.
The macro will be collected by the preprocessing module and
skipped by the scanner.
A macro expression ( Name ActualParameter Delimiter ... ) will be
replaced by the previous definition and then rescanned.
' Delimiter
introduces another - the second - character as delimiter for the
actual macro parameter.
Spaces will be used as default delimiter.
To reactive the default behaviour specify ' -.
The scanner skips these token.
#undefine Name
revokes a previous definition
#if[n]def Name IfPart #else ElsePart #end
supports conditional parsing
Dependant on the existence of macro 'Name' the scanner skips the
'ElsePart' or 'IfPart'.
Its possible to introduce environment variables as macros.
apart from token names and keywords.
( see below and styx reference )
*/
/* -------------------- Types & Macros ------------------------------------ */
AbstractType( SPP_T ) /* Abstract preprocessing type */
;
/*
In the case of an error program execution stops with a usage message.
") == cmdbuf )
{
*list = sources; *cnt = cnt_sources; return 3;
}
else
if( strstr(cmdbuf,"") == cmdbuf )
{
*list = includes; *cnt = cnt_includes; return 3;
}
else
if( strstr(cmdbuf,"") == cmdbuf )
{
*list = libdirs; *cnt = cnt_libdirs; return 4;
}
else
if( strstr(cmdbuf,"
*/
/* ------------------------- Globals & Constants -------------------------- */
#define CONTEXT CTX_T_IMP(CTX_ctx_val())
#define EXTENSION ".cim"
#define Num_MIN "-2147483648" /* min value of a "long int" */
#define Num_MAX "2147483647" /* max value of a "long int" */
static int errcnt = 0;
/*I------------------------ Definition interface -------------------------- */
CTX_T CTX_new(short cnt, string name)
/* make new context for program 'name' and 'cnt' arguments */
{ CTX_T_Imp ctx; int i;
BUG_NULL(name);
ctx = New(CTX_T_Imp);
ctx->cnt = cnt;
ctx->prg = StrCopy(name);
ctx->tbl = (CTX_L_Imp)NewMem(cnt * SizeOf(CTX_L_Imp));
for( i=0; i < cnt; ++i )
ctx->tbl[i].asg = False;
return( ctx );
}
void CTX_free(CTX_T ctx)
/* drop context 'ctx' */
{ int cnt, i;
BUG_NULL(ctx);
cnt = CTX_T_IMP(ctx)->cnt;
FreeMem(CTX_T_IMP(ctx)->prg);
if( cnt &&
CTX_T_IMP(ctx)->tbl[cnt-1].asg &&
! strcmp(CTX_T_IMP(ctx)->tbl[cnt-1].ide,CTX_VARG) )
{ StdCPtr* vargs = (StdCPtr*)CTX_T_IMP(ctx)->tbl[cnt-1].val;
if( CTX_T_IMP(ctx)->tbl[cnt-1].typ == CTX_PATH ||
CTX_T_IMP(ctx)->tbl[cnt-1].typ == CTX_NAME ||
CTX_T_IMP(ctx)->tbl[cnt-1].typ == CTX_STRING )
for( i=1; i <= intCAST(vargs[0]); ++i ) FreeMem(vargs[i]);
FreeMem(CTX_T_IMP(ctx)->tbl[cnt-1].ide);
FreeMem(vargs);
--cnt;
}
for( i=0; i < cnt; ++i )
{
if( CTX_T_IMP(ctx)->tbl[i].asg &&
( CTX_T_IMP(ctx)->tbl[i].typ == CTX_PATH ||
CTX_T_IMP(ctx)->tbl[i].typ == CTX_NAME ||
CTX_T_IMP(ctx)->tbl[i].typ == CTX_STRING ) )
FreeMem(CTX_T_IMP(ctx)->tbl[i].val);
FreeMem(CTX_T_IMP(ctx)->tbl[i].ide);
if( CTX_T_IMP(ctx)->tbl[i].cat == CTX_OPT ||
CTX_T_IMP(ctx)->tbl[i].cat == CTX_ENV )
FreeMem(CTX_T_IMP(ctx)->tbl[i].dft);
}
FreeMem(CTX_T_IMP(ctx)->tbl);
FreeMem(ctx);
}
void CTX_set
(
CTX_T ctx, short idx, string ide,
byte cat, byte typ, string dft
)
/* assign argument 'ide' of category 'cat', with type 'typ' and
default value 'dft' to context entry ctx[idx]
*/
{
BUG_NULL(ctx); BUG_NULL(ide);
BUG_RNG0(idx,CTX_T_IMP(ctx)->cnt);
CTX_T_IMP(ctx)->tbl[idx].ide = StrCopy(ide);
CTX_T_IMP(ctx)->tbl[idx].cat = cat;
CTX_T_IMP(ctx)->tbl[idx].typ = typ;
if( CTX_T_IMP(ctx)->tbl[idx].cat == CTX_OPT ||
CTX_T_IMP(ctx)->tbl[idx].cat == CTX_ENV )
CTX_T_IMP(ctx)->tbl[idx].dft = dft;
}
void CTX_put(string env, CTX_T ctx)
/* put binary image of context 'ctx' */
{ string hd; int i;
BUG_NULL(env); BUG_NULL(ctx);
putBgn(env,CTX_T_IMP(ctx)->prg,EXTENSION);
hd = Str_printf
(
"[%s%s] Binary Context Image for %s\n",
CTX_T_IMP(ctx)->prg,EXTENSION,CTX_T_IMP(ctx)->prg
);
putHeader(hd,"cim",1,0);
putWord(CTX_T_IMP(ctx)->cnt);
putString(CTX_T_IMP(ctx)->prg);
for( i=0; i < CTX_T_IMP(ctx)->cnt; ++i )
{
putString(CTX_T_IMP(ctx)->tbl[i].ide);
putByte(CTX_T_IMP(ctx)->tbl[i].cat);
putByte(CTX_T_IMP(ctx)->tbl[i].typ);
if( CTX_T_IMP(ctx)->tbl[i].cat == CTX_OPT ||
CTX_T_IMP(ctx)->tbl[i].cat == CTX_ENV )
putString(CTX_T_IMP(ctx)->tbl[i].dft);
}
FreeMem(hd);
putEnd();
}
CTX_T CTX_get(string env, string name)
/* get context from binary image [$'env'/'name'.cim] */
{ CTX_T_Imp ctx; short cnt; int i;
BUG_NULL(env); BUG_NULL(name);
getBgn(env,name,EXTENSION);
getHeader("cim",1,0);
getWord(&cnt);
ctx = New(CTX_T_Imp);
ctx->cnt = cnt;
getString(&ctx->prg);
ctx->tbl = (CTX_L_Imp)NewMem(cnt * SizeOf(CTX_L_Imp));
for( i=0; i < ctx->cnt; ++i )
{
getString(&ctx->tbl[i].ide);
getByte(&ctx->tbl[i].cat);
getByte(&ctx->tbl[i].typ);
if( ctx->tbl[i].cat == CTX_OPT ||
ctx->tbl[i].cat == CTX_ENV )
getString(&ctx->tbl[i].dft);
ctx->tbl[i].asg = False;
}
getEnd();
return ctx;
}
void CTX_usage(CTX_T ctx)
/* print usage for context 'ctx' */
{ CTX_T_Imp ctx_imp = CTX_T_IMP(ctx); int i;
fprintf(STDERR,"Usage: %s", ctx_imp->prg);
for (i = 0; i < ctx_imp->cnt; i++)
if (ctx_imp->tbl[i].cat == CTX_OPT)
{
fprintf(STDERR," [-%s",ctx_imp->tbl[i].ide);
switch( ctx_imp->tbl[i].typ )
{
case CTX_FLAG : break;
case CTX_PATH : fprintf(STDERR,"=path"); break;
case CTX_STRING : fprintf(STDERR,"=string"); break;
case CTX_NAME : fprintf(STDERR,"=name"); break;
case CTX_INT : fprintf(STDERR,"=int"); break;
default :
fprintf(STDERR,"%c%c%c(%d)",'?','?','?',ctx_imp->tbl[i].cat); break;
}
fprintf(STDERR,"]");
}
for (i = 0; i < ctx_imp->cnt; i++)
if(ctx_imp->tbl[i].cat == CTX_ARG)
fprintf(STDERR," %s",ctx_imp->tbl[i].ide);
FNL(STDERR);
STD_ERREXIT;
}
void CTX_C_Modul(string Environ, CTX_T Ctx, c_bool shortform)
/* compiles context 'ctx' to [$'Environ'/'Name'_cim.c] */
{ FILE *tf; CTX_T_Imp ctx = CTX_T_IMP(Ctx);
c_string fid; int maxlen=0, i;
if( shortform )
fid = Str_printf("%.4s_cim",ctx->prg);
else
fid = Str_printf("%s_cim",ctx->prg);
tf = OpenPath(Environ,fid,".c","wt");
fprintf(tf,"/* [%s.c] Context table for '%s' */\n\n", fid, ctx->prg);
fprintf(tf,"#include \"ctx.h\"\n\n");
fprintf(tf,"void CTX_init_%s(int argc, c_string argv[])\n",ctx->prg);
fprintf(tf,"{ CTX_T ctx;\n");
fprintf(tf," ctx = CTX_new(%d,\"%s\");\n",ctx->cnt,ctx->prg);
for (i = 0; i < ctx->cnt; i++)
maxlen = MAX(strlen(ctx->tbl[i].ide),maxlen);
for (i = 0; i < ctx->cnt; i++)
{
fprintf(tf," CTX_set(ctx,%2d,",i);
fprintf(tf,"\"%s\",%*s",ctx->tbl[i].ide,(int)(maxlen-strlen(ctx->tbl[i].ide)),"");
switch( ctx->tbl[i].cat )
{
case CTX_ARG : fprintf(tf,"CTX_ARG,"); break;
case CTX_OPT : fprintf(tf,"CTX_OPT,"); break;
case CTX_ENV : fprintf(tf,"CTX_ENV,"); break;
default : fprintf(tf,"%7d,",ctx->tbl[i].cat); break;
}
switch( ctx->tbl[i].typ )
{
case CTX_FLAG : fprintf(tf,"CTX_FLAG, "); break;
case CTX_PATH : fprintf(tf,"CTX_PATH, "); break;
case CTX_STRING : fprintf(tf,"CTX_STRING,"); break;
case CTX_NAME : fprintf(tf,"CTX_STRING,"); break;
case CTX_INT : fprintf(tf,"CTX_INT, "); break;
default : fprintf(tf,"%10d,",ctx->tbl[i].cat); break;
}
if( ctx->tbl[i].cat == CTX_OPT ||
ctx->tbl[i].cat == CTX_ENV )
{ string s = LIT_c_str_lit(ctx->tbl[i].dft);
fprintf(tf,"StrCopy(%s)",s); FreeMem(s);
}
else
fprintf(tf,"\"\"");
fprintf(tf,");\n");
}
fprintf(tf," CTX_ctx_set(ctx);\n");
fprintf(tf," CTX_interprete(argc, argv);\n");
fprintf(tf,"}\n");
fclose(tf);
FreeMem(fid);
}
static void CTX_prVal(int typ, Abs_T val, bool shell)
{
switch( typ )
{
case CTX_FLAG :
fprintf(STDOUT,"%s",ABS_CAST(bool,val)?"true":"false");
break;
case CTX_PATH :
if( shell ) fprintf(STDOUT,"%s",(string)val);
else fprintf(STDOUT,"<%s>",(string)val);
break;
case CTX_STRING :
if( shell ) fprintf(STDOUT,"'%s'",(string)val);
else fprintf(STDOUT,"\"%s\"",(string)val);
break;
case CTX_NAME :
fprintf(STDOUT,"%s",(string)val);
break;
case CTX_INT :
fprintf(STDOUT,"%ld",(long)val);
break;
default : C_BUG;
}
}
void CTX_sh_list(void)
/* print shell context */
{ int i;
for (i = 0; i < CONTEXT->cnt; i++)
{
fprintf(STDOUT,"%s=",CONTEXT->tbl[i].ide);
if (CONTEXT->tbl[i].asg)
{
if( i == CONTEXT->cnt - 1 && ! strcmp(CONTEXT->tbl[i].ide,CTX_VARG) )
fprintf(STDOUT,"%d",intCAST(((Abs_T*)CONTEXT->tbl[i].val)[0]));
else CTX_prVal(CONTEXT->tbl[i].typ,CONTEXT->tbl[i].val,True);
}
NL;
}
}
void CTX_list(CTX_T ctx)
/* DEBUG; print context 'ctx' */
{ CTX_T_Imp ctx_imp = CTX_T_IMP(ctx); int maxlen=0,i;
fprintf(STDOUT,"Command %s\n", ctx_imp->prg);
for (i = 0; i < ctx_imp->cnt; i++)
maxlen = MAX(strlen(ctx_imp->tbl[i].ide),maxlen);
for (i = 0; i < ctx_imp->cnt; i++)
{
fprintf(STDOUT,"-- ");
switch( ctx_imp->tbl[i].cat )
{
case CTX_ARG : fprintf(STDOUT,"Arg"); break;
case CTX_OPT : fprintf(STDOUT,"Opt"); break;
case CTX_ENV : fprintf(STDOUT,"Env"); break;
default :
fprintf(STDOUT,"%c%c%c(%d)",'?','?','?',ctx_imp->tbl[i].cat); break;
}
fprintf(STDOUT," %-*s : ",maxlen,ctx_imp->tbl[i].ide);
switch( ctx_imp->tbl[i].typ )
{
case CTX_FLAG : fprintf(STDOUT,"flag "); break;
case CTX_PATH : fprintf(STDOUT,"path "); break;
case CTX_STRING : fprintf(STDOUT,"string"); break;
case CTX_NAME : fprintf(STDOUT,"name "); break;
case CTX_INT : fprintf(STDOUT,"int "); break;
default :
fprintf(STDOUT,"%c%c%c(%d)",'?','?','?',ctx_imp->tbl[i].cat); break;
}
fprintf(STDOUT," = ");
if (ctx_imp->tbl[i].asg)
{
if( i == ctx_imp->cnt - 1 && ! strcmp(ctx_imp->tbl[i].ide,CTX_VARG) )
{ int cnt = intCAST(((Abs_T*)ctx_imp->tbl[i].val)[0]), j;
fprintf(STDOUT,"%d",cnt);
for( j=1; j <= cnt; ++j )
{
fprintf(STDOUT,"\n %s(%3d) = ",CTX_VARG,j);
CTX_prVal(ctx_imp->tbl[i].typ,((Abs_T*)ctx_imp->tbl[i].val)[j],False);
}
}
else CTX_prVal(ctx_imp->tbl[i].typ,ctx_imp->tbl[i].val,False);
}
else
fprintf(STDOUT,"[UNDEFINED]");
NL;
}
}
static long Num_error(string val, string msg)
{
fprintf(STDOUT,"[Usage] : %s : %s\n",msg,val);
errcnt += 1; return 0;
}
static bool Num_less(bool sa, string va, bool sb, string vb)
/* whether to strings containing numbers are less w.r.t. numeric order */
/* sa, sb are the signs, true means negative */
/* va, vb are the digits without leading 0s */
{
if (sa != sb) return sa && !sb;
if (sa) return Num_less(0,vb,0,va);
if (strlen(va) != strlen(vb)) return strlen(va) < strlen(vb);
return strcmp(va,vb) < 0;
}
static long Num_conv(string val)
/* converts a string to an integer */
/* this routine is very general and not restricted to short, int or long */
{ bool sign = (val[0] == '-'); int slen = strlen(val), i, j; long res;
/* skip leading 0s */
if (val[sign] == 0)
return Num_error(val,"Zahl erwarted");
for (i = sign; i < slen-1; i++) if (val[i] != '0') break;
/* check digits */
for (j = i; j < slen; j++)
if ('0' > val[j] || val[j] > '9')
return Num_error(val,"Zahl erwarted");
/* check value range */
if (Num_less(sign,val+i,Num_MIN[0]=='-',Num_MIN+(Num_MIN[0]=='-')))
return Num_error(val,"zu kleine Zahl");
if (Num_less(Num_MAX[0]=='-',Num_MAX+(Num_MAX[0]=='-'),sign,val+i))
return Num_error(val,"zu grosse Zahl");
/* actual conversion */
res = 0;
for (j = i; j < slen; j++)
res = 10 * res + (val[j]-'0');
return sign ? -res : res;
}
static Abs_T CTX_convert(int typ, string val)
/* converts ctx-typed value val */
{
switch( typ )
{
case CTX_FLAG :
if (strcmp(val,"true" ) == 0) return (Abs_T) 1;
if (strcmp(val,"false") == 0) return (Abs_T) 0;
fprintf(STDERR,"[Usage]: '%s' is not a boolean value",val);
errcnt += 1; return (Abs_T) 0;
case CTX_PATH :
return (Abs_T) StrCopy(val);
case CTX_NAME :
return (Abs_T) StrCopy(val);
case CTX_STRING :
return (Abs_T) StrCopy(val);
case CTX_INT :
return (Abs_T) Num_conv(val);
default:
C_BUG; return (Abs_T) 0;
}
}
static void CTX_assing(int idx, string val)
{
if (idx < 0) return;
if (CONTEXT->tbl[idx].cat != CTX_OPT
&& CONTEXT->tbl[idx].cat != CTX_ARG
&& CONTEXT->tbl[idx].cat != CTX_ENV )
{
fprintf(STDERR,"[Usage]: cannot assign to option '%s'\n",
CONTEXT->tbl[idx].ide);
errcnt += 1; return;
}
if (CONTEXT->tbl[idx].asg)
{
fprintf(STDERR,"[Usage]: option '%s' assigned more than once\n",
CONTEXT->tbl[idx].ide);
errcnt += 1; return;
}
CONTEXT->tbl[idx].asg = True;
CONTEXT->tbl[idx].val = CTX_convert(CONTEXT->tbl[idx].typ,val);
}
static void CTX_varg_asgn(int vargc, string vargv[])
{ Abs_T* vargs = (Abs_T*)NewMem((vargc + 1) * sizeof(Abs_T)); int i;
vargs[0] = ABS_CAST(Abs_T,vargc);
for( i=0; i < vargc; ++i )
vargs[i+1] = CTX_convert(CONTEXT->tbl[CONTEXT->cnt-1].typ,vargv[i]);
CONTEXT->tbl[CONTEXT->cnt-1].asg = True;
CONTEXT->tbl[CONTEXT->cnt-1].val = (StdCPtr)vargs;
}
static void CTX_option_flag(string flg)
{ int idx = intCAST(CTX_eval(flg,True));
if (idx < 0)
{
fprintf(STDERR,"[Usage]: invalid option '%s'\n",flg);
errcnt += 1;
return;
}
if ((CONTEXT->tbl[idx].cat != CTX_OPT &&
CONTEXT->tbl[idx].cat != CTX_ENV ) ||
CONTEXT->tbl[idx].typ != CTX_FLAG )
{
fprintf(STDERR,"[Usage]: Option '%s' is not a flag\n",flg);
errcnt += 1;
}
CTX_assing(idx,strcmp(CONTEXT->tbl[idx].dft,"true")?"true":"false");
}
static void CTX_option_asgn(string var, string val)
/* NOTE: var must be freed */
{ int idx = intCAST(CTX_eval(var,True));
if (idx < 0)
{
fprintf(STDERR,"[Usage]: invalid option '%s'\n",var);
errcnt += 1;
}
else
CTX_assing(idx,val);
FreeMem(var);
}
static int CTX_args(void)
/* number of static arguments in current context */
{ int cnt = 0, i;
for (i = 0; i < CONTEXT->cnt; i++)
cnt += ( CONTEXT->tbl[i].cat == CTX_ARG &&
! CONTEXT->tbl[i].asg &&
strcmp(CONTEXT->tbl[i].ide,CTX_VARG) );
return cnt;
}
static void CTX_argument(string arg)
{ int i;
for (i = 0; i < CONTEXT->cnt; i++)
if (CONTEXT->tbl[i].cat == CTX_ARG && !CONTEXT->tbl[i].asg)
break;
if (i >= CONTEXT->cnt || ! strcmp(CONTEXT->tbl[i].ide,CTX_VARG))
{
fprintf(STDERR,"[Usage]: unexpected argument '%s'\n",arg);
errcnt += 1; return;
}
CTX_assing(i,arg);
}
static string loc_dirname; /* the path of the actual program executable */
string CTX_dirname(void)
/* path of the current program */
{
return loc_dirname;
}
static void prep_loc_dirname(string argv0)
/* prepares 'loc_dirname' */
{ int i,len = strlen(argv0);
loc_dirname = StrCopy(argv0);
for
(
i = len;
i>0 && loc_dirname[i-1] != '\\' && loc_dirname[i-1] != '/';
i--
); /* noop */
if (i>0) loc_dirname[i-1] = 0;
for (; i>=0; i--)
if (loc_dirname[i] == '\\')
loc_dirname[i] = '/';
}
void CTX_interprete(int argc, string argv[])
/* process current program context */
{ int first_varg = argc, i;
prep_loc_dirname(argv[0]);
if (argc == 2 && !strcmp(argv[1],"-?" )) { CTX_usage(CONTEXT); STD_ERREXIT; }
if (argc == 2 && !strcmp(argv[1],"-??")) { CTX_list (CONTEXT); STD_ERREXIT; }
if( CONTEXT->cnt && ! strcmp(CONTEXT->tbl[CONTEXT->cnt-1].ide,CTX_VARG) )
{ int cnt = CTX_args(), idx = 1;
for (i = 1; i < argc; i++)
if (argv[i][0] == '-') idx = i + 1;
else
{
if( cnt > 0 )
{
idx = i + 1; --cnt;
}
}
first_varg = idx;
}
/* process options */
for (i = 1; i < MIN(argc,first_varg); i++)
{
if (argv[i][0] == '-')
{ string opt = argv[i]; int sl = strlen(opt), j;
for( j = 0; j < sl; j++) if (opt[j] == '=') break;
if (j >= sl)
CTX_option_flag(argv[i]+1);
else
CTX_option_asgn(SubStrCopy(argv[i]+1,j-1),argv[i]+j+1);
}
}
/* process arguments */
for (i = 1; i < MIN(argc,first_varg); i++)
{
if (argv[i][0] != '-') CTX_argument(argv[i]);
}
/* process variable arguments */
if( CONTEXT->cnt && ! strcmp(CONTEXT->tbl[CONTEXT->cnt-1].ide,CTX_VARG) )
{
if( first_varg < argc )
CTX_varg_asgn(argc-first_varg,&argv[first_varg]);
else
CTX_varg_asgn(0,(string*)NULL);
}
/* process defaults */
for (i = 0; i < CONTEXT->cnt; i++)
if (!CONTEXT->tbl[i].asg)
{
switch( CONTEXT->tbl[i].cat )
{
case CTX_ARG :
fprintf(STDERR,"[Usage]: paramenter '%s' expected\n",
CONTEXT->tbl[i].ide);
errcnt += 1; break;
case CTX_OPT :
CTX_assing(i,CONTEXT->tbl[i].dft);
break;
case CTX_ENV :
if( !STR_EMPTY(getenv(CONTEXT->tbl[i].ide)) )
CTX_assing(i,getenv(CONTEXT->tbl[i].ide));
else
if( *(CONTEXT->tbl[i].dft) != '\0' )
CTX_assing(i,CONTEXT->tbl[i].dft);
else
{
fprintf(STDERR,"[Usage]: shell variable '%s' expected\n",
CONTEXT->tbl[i].ide);
errcnt += 1;
}
break;
default : C_BUG;
}
}
if (errcnt > 0)
CTX_usage(CONTEXT);
}
/*I------------------------ Application interface ------------------------- */
void CTX_init(int argc, string argv[])
/* initialize and process current program context */
{ CTX_T ctx; string stdnam;
assert0(argc>0,"interner Fehler bei der Uebergabe der Kommandozeile");
/* MSDOS produces d:\Path...\ProgId.EXE, the full pathname in argv[0] */
/* UNIX produces ProgId or Path/ProgId, in dependance of the call */
/* thus we remove prefixes and suffixes to get the program name */
stdnam = BaseFile(argv[0]);
CTX_ctx_set(CTX_new(1,"[CTX_init]"));
CTX_set(CONTEXT,0,"PATH",CTX_ENV,CTX_PATH,"");
CTX_interprete(1, argv);
ctx = CTX_get("PATH",stdnam);
CTX_free(CONTEXT);
CTX_ctx_set(ctx);
FreeMem(loc_dirname);
CTX_interprete(argc,argv);
FreeMem(stdnam);
}
void CTX_quit(void)
/* drop current program context */
{
CTX_free(CONTEXT);
FreeMem(loc_dirname);
}
styx-2.0.1/libutil/hpat.c 0000666 0001750 0001750 00000053727 07634405314 012236 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [hpat.c] Template / Pattern Evaluation */
/* */
/* Copyright (c) 1999 by D\olle, Manns, Steffen */
/* ------------------------------------------------------------------------ */
#include "standard.h"
#include "scn_base.h"
#include "symbols.h"
#include "otab.h"
#include "gls.h"
#include "hpat_int.h"
#include "hmap.h"
#include "hset.h"
#include "ptm.h"
#include "prs.h"
#include "ptm_gen.h"
#include "sink.h"
#include "pathes.h"
#include "line_scn.h"
#include "hpat_lim.h"
#include "hpat_pim.h"
/*!
*/
/*I------------------------- Types & Macros ----------------------------- */
#define HPAT_TOK_PATREF "PatRef"
#define HPAT_PREFIX_PATREF '&'
#define HPAT_FUN_REPLACE "REPLACE"
/*!
cod
Environment
BINSTYX : path = "." -- [.pim], [.lim] and [.ltbl] target directory
GENSTYX : path = "." -- [.c] target directory
SPESTYX : path = "." -- [.sty] source directory
styx-2.0.1/pgm/stypp.c 0000666 0001750 0001750 00000007222 10161654767 011574 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [stypp.c] Pretty Printer */
/* */
/* Copyright (c) 1993 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "ptm_pp.h"
#include "glo_tab.h"
#include "pgm_base.h"
#include "pgm_sopt.h" /* after ptm_pp.h becourse of naming conflicts */
#include "pgm_popt.h"
#include "styp_cim.h"
#define srclang CTX_EVAL(string,"srclang")
#define dstlang CTX_EVAL(string,"dstlang")
#define filename CTX_EVAL(string,"filename")
#define ppfun CTX_EVAL(string,"ppfun")
#define binpath CTX_EVAL(string,"BINSTYX")
int main(int argc, string argv[])
{ PLR_Tab PTabS, PTabD; Scn_T Scn;
Scn_Stream cStream; PT_Cfg PCfg; PTP_T ctx;
PT_Term PTreeS = (PT_Term)NULL, PTreeD = (PT_Term)NULL;
c_string pplib, s;
symbol (*fun)(symbol t_id, symbol t_src) = NULL;
/* init module */
PGM_init(argc,argv,CTX_init_stypp);
/* init user-defined pp token conversion handler */
if( strlen(ppfun) > 0 )
{
assert0
(
(s=strstr(ppfun,"@")) != (c_string)NULL, "missing ppfun-library"
);
pplib = s+1; *s = '\0';
fun = (symbol (*)(symbol tok, symbol val))Glo_load
(
stringToSymbol(pplib),stringToSymbol(ppfun),True
);
*s = '@';
}
/* init pre-processing */
PGM_initPreprocessing(prepar,premac,cset);
/* create & init scan & parse tables */
PTabS = PLR_getTab_env(binpath,srclang);
PTabD = PLR_getTab_env(binpath,dstlang);
Scn_get_env(binpath,srclang,&Scn);
/* create & init scan stream */
cStream = PGM_initScanStream
(
Scn,filename,prepar,prefun,False,cset,
skipset,CTX_EVAL(bool,"lookahead"),False
);
/* init parse configuration */
PCfg = PT_init(PTabS,cStream);
/* parse, transform and pp tree */
/* early --> parse, transform and pp partial trees */
PTreeS = PGM_parse(PCfg,start,shiftfun,reducefun,early,xaron);
PT_setErrorCnt(PT_synErrorCnt(PCfg));
if( early )
{
while( PTreeS != (PT_Term)NULL && PT_errorCnt() == 0 )
{
/* transform and pp partial source tree */
ctx = PTP_init_reentrant(PTabD);
if( fun != NULL ) PTP_tok_conv_reentrant(ctx,(symbol)NULL,fun);
PTreeD = PTP_transform_reentrant(ctx,PTreeS);
PTP_pp_reentrant(ctx,PTreeD,STDOUT);
PTP_quit_reentrant(ctx);
/* release partial source and target tree */
if( PTreeD != (PT_Term)NULL ) PT_delT(PTreeD);
PT_delT(PTreeS);
/* parse next partial source tree */
PTreeS = PGM_parse(PCfg,start,shiftfun,reducefun,early,xaron);
PT_setErrorCnt(PT_synErrorCnt(PCfg));
}
}
if( PTreeS != (PT_Term)NULL && PT_errorCnt() == 0 )
{
/* transform and pp source tree */
ctx = PTP_init_reentrant(PTabD);
if( fun != NULL ) PTP_tok_conv_reentrant(ctx,(symbol)NULL,fun);
PTreeD = PTP_transform_reentrant(ctx,PTreeS);
PTP_pp_reentrant(ctx,PTreeD,STDOUT);
PTP_quit_reentrant(ctx);
/* release target tree */
if( PTreeD != (PT_Term)NULL ) PT_delT(PTreeD);
}
/* quit parse configuration */
PT_quit(PCfg);
/* release source tree */
if( PTreeS != (PT_Term)NULL ) PT_delT(PTreeS);
/* release scan stream, scan & parse tables */
PGM_quitScanStream(cStream);
PLR_delTab(PTabD);
PLR_delTab(PTabS);
Scn_free(Scn);
/* quit preprocessing */
PGM_quitPreprocessing(prepar);
/* quit module */
PGM_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/pim2dot.c 0000666 0001750 0001750 00000017125 10136506720 011761 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [pim2dot.c] Parse table visualisation ( pim -> dot ) */
/* */
/* Copyright (c) 2004 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
#include "stdosx.h"
#include "prs.h"
#include "hset.h"
#include "literal.h"
#include "pgm_base.h"
#include "gstream.h"
#include "line_scn.h"
#include "pathes.h"
#include "sink.h"
#include "pim2dot_cim.h"
#define imgfile CTX_EVAL(string,"Img")
#define tmplfile CTX_EVAL(string,"Template")
#define outfile CTX_EVAL(string,"OutFile")
#define diatype CTX_EVAL(string,"DiaType")
static FILE* SysOut = NULL;
static void evalTemplate()
{
if( strlen(tmplfile) > 0 )
{ FILE* fp = OpnFile(tmplfile,"rb");
string line = Line_get(fp);
fprintf(SysOut,"\n");
while( line != NULL )
{
fprintf(SysOut,"%s\n",line);
FreeMem(line);
line = Line_get(fp);
}
fprintf(SysOut,"\n");
}
}
static MAP(long,long) collectTNodes(PLR_Tab ptab)
{ MAP(long,long) states = MAP_newPrimMap();
long i;
for( i=0; i < PLR_stateCnt(ptab); ++i )
{
MAP_dfndom(states,i,-1);
}
return states;
}
static string dotLiteral(string s, string q)
{ Sink res = Sink_open();
for (; *s != 0; s += 1)
switch(*s)
{
case '\"' :
case '\\' : Sink_putc(res,'\\'); Sink_putc(res, *s); break;
case '\r' : Sink_putc(res,'\\'); Sink_putc(res,'r'); break;
case '\n' : Sink_putc(res,'\\'); Sink_putc(res,'n'); break;
case '\f' : Sink_putc(res,'\\'); Sink_putc(res,'f'); break;
case '\t' : Sink_putc(res,'\\'); Sink_putc(res,'t'); break;
default : if( strchr(q,(*s)) != NULL )
{
Sink_putc(res,'\\'); Sink_putc(res,(*s));
}
else
if (!isspace(*s) && isprint(*s))
Sink_putc(res,*s);
else Sink_printf(res,"0x%02x",(*s)&0xff);
};
return Sink_close(res);
}
static void printRNode(PLR_Tab ptab, long nt)
{ c_bool start = C_False;
long i;
for( i=0; i < PLR_startCnt(ptab); ++i )
{
if( PLR_startSymbol(ptab,i) == nt )
{
start = C_True; break;
}
}
fprintf(SysOut,"\n node%ld [",nt);
fprintf(SysOut," label=\"%s\"",PLR_symName(ptab,nt));
if( start )
fprintf(SysOut," shape=box");
fprintf(SysOut,"]");
}
static void printTNode(PLR_Tab ptab, MAP(long,long) states, long state)
{ ROW(long) vaction = PLR_actionValues(ptab,state);
long l, p, s, t, i; c_string sym; c_bool reduce = C_False;
s = MAP_apply(long,states,state);
fprintf(SysOut,"\n node%ld [",state);
fprintf(SysOut," label=\"{%ld",state);
if( s >= 0 )
{
if( CFG_WCKEY(PLR_symType(ptab,s)) || CFG_KEY(PLR_symType(ptab,s)) )
{ string lbl = dotLiteral(PLR_symName(ptab,s),"<>{}|");
fprintf(SysOut,"|%s",lbl);
FreeMem(lbl);
}
else
{
fprintf(SysOut,"|%s",PLR_symName(ptab,s));
}
}
else
{
fprintf(SysOut,"|");
}
for( i=0; i < OT_CNT(vaction); i+=2 )
{
p = OT_GET(long,vaction,i);
t = OT_GET(long,vaction,i+1);
if( p >= -1 )
{
reduce = C_True;
if( p >= 0 )
{
l = PLR_prodSymCnt(ptab,p);
sym = PLR_symName(ptab,PLR_prodNonTerm(ptab,p));
fprintf(SysOut,"|%ld-%s.%s",l,sym,PLR_prodName(ptab,p));
}
else
if( t >= PLR_tokenCnt(ptab) )
{
s = t - PLR_tokenCnt(ptab);
sym = PLR_symName(ptab,PLR_startSymbol(ptab,s));
fprintf(SysOut,"|%s",sym);
}
}
}
fprintf(SysOut,"}\"");
fprintf(SysOut," shape=record");
if( reduce )
fprintf(SysOut," style=filled");
fprintf(SysOut,"]");
OT_DEL_T(vaction);
}
static void pim2tdot(PLR_Tab ptab)
{ MAP(long,long) edges = MAP_newPrimMap(),
states = collectTNodes(ptab);
MAPIT itr; long i, j, k, s1, s2, t, s;
fprintf(SysOut,"\ndigraph t_%s",PLR_language(ptab));
fprintf(SysOut,"\n{");
evalTemplate();
for( i=0; i < PLR_stateCnt(ptab); ++i )
{ ROW(int) vshift = PLR_shiftValues(ptab,i);
MAP_rmvall(edges);
for( k=0; k < OT_CNT(vshift); k+=2 )
{
s1 = OT_GET(long,vshift,k+1);
t = OT_GET(long,vshift,k);
MAP_ovrdom(edges,s1,i);
s = MAP_apply(long,states,s1);
assert0( s < 0 || s == t, "shift symbol mismatch");
MAP_ovrdom(states,s1,t); // t = 0..tokenCnt-1
}
MAP_forItrAsg(j,k,itr,edges)
{
fprintf(SysOut,"\n node%ld -> node%ld ",i,j);
}
OT_DEL_T(vshift);
}
for( i=0; i < PLR_nontermCnt(ptab); ++i )
{ ROW(int) vgoto = PLR_gotoValues(ptab,i);
MAP_rmvall(edges);
for( j=0; j < OT_CNT(vgoto); j+=2 )
{
s1 = OT_GET(long,vgoto,j+1);
s2 = OT_GET(long,vgoto,j);
s = MAP_apply(long,states,s2);
assert0( s < 0 || s == PLR_NTI_TO_NTS(ptab,i), "goto symbol mismatch");
MAP_ovrdom(states,s2,PLR_NTI_TO_NTS(ptab,i));
fprintf(SysOut,"\n node%ld -> node%ld ",s1,s2);
}
OT_DEL_T(vgoto);
}
for( i=0; i < PLR_stateCnt(ptab); ++i )
{
printTNode(ptab,states,i);
}
fprintf(SysOut,"\n}\n");
MAP_freeMap(edges);
MAP_freeMap(states);
}
static void pim2rdot(PLR_Tab ptab)
{ MAP(long,SET(long)) products = MAP_newPrimMap();
MAP(long,long) edges = MAP_newPrimMap();
SET(long) ntset, pset; long nt, p, s, i, j;
if( !strcmp(diatype,"R") )
fprintf(SysOut,"\ndigraph r_%s",PLR_language(ptab));
else
fprintf(SysOut,"\ndigraph a_%s",PLR_language(ptab));
fprintf(SysOut,"\n{");
evalTemplate();
for( i=0; i < PLR_nontermCnt(ptab); ++i )
{
s = PLR_NTI_TO_NTS(ptab,i);
if( !strcmp(diatype,"A") )
s = PLR_NTS_TO_NTC(ptab,s);
if( !MAP_defined(products,s) )
{
pset = HS_CREATE_ADTSET(long);
MAP_dfndom(products,s,pset);
printRNode(ptab,s);
}
}
for( i=0; i < PLR_prodCnt(ptab); ++i )
{
nt = PLR_prodNonTerm(ptab,i);
if( nt < PLR_tokenCnt(ptab) + PLR_nontermCnt(ptab) )
{
if( !strcmp(diatype,"A") )
nt = PLR_NTS_TO_NTC(ptab,nt);
pset = MAP_apply(SET(long),products,nt);
HS_SET_ELM(i,pset);
}
}
for( i=0; i < PLR_nontermCnt(ptab); ++i )
{ HS_Itr itr;
nt = PLR_NTI_TO_NTS(ptab,i);
if( !strcmp(diatype,"A") )
nt = PLR_NTS_TO_NTC(ptab,nt);
pset = MAP_apply(SET(long),products,nt);
if( pset != NULL )
{
ntset = HS_CREATE_ADTSET(long);
HS_FORALL(p,itr,pset)
{
for( j=0; j < PLR_prodSymCnt(ptab,p); ++j )
{
s = PLR_prodSymbol(ptab,p,j);
if( CFG_NTM(PLR_symType(ptab,s)) )
{
if( !strcmp(diatype,"A") )
s = PLR_NTS_TO_NTC(ptab,s);
HS_SET_ELM(s,ntset);
}
}
}
HS_FORALL(s,itr,ntset)
{
fprintf(SysOut,"\n node%ld -> node%ld ",nt,s);
}
HS_DROP_SET(ntset);
HS_DROP_SET(pset);
if( !strcmp(diatype,"A") )
MAP_ovrdom(products,nt,NULL);
}
}
fprintf(SysOut,"\n}\n");
MAP_freeMap(edges);
MAP_freeMap(products);
}
int main(int argc, string argv[])
{ PLR_Tab ptab;
/* init module */
PGM_init(argc,argv,CTX_init_pim2dot);
/* get the parse table */
ptab = PLR_getTab_file(imgfile);
/* produce the dot file */
if( strlen(outfile) > 0 )
SysOut = OpnFile(outfile,"wt");
else SysOut = stdout;
if( !strcmp(diatype,"T") ) pim2tdot(ptab);
else pim2rdot(ptab);
/* free the parse table */
PLR_delTab(ptab);
/* quit module */
PGM_quit();
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/ctoh.c 0000666 0001750 0001750 00000127634 11230631142 011340 0000000 0000000 /* ------------------------------------------------------------------------ */
/* */
/* [ctoh.c] Creates an Interface File from a C-Source */
/* */
/* Copyright (c) 1994 by D\olle, Manns */
/* ------------------------------------------------------------------------ */
/* [*.h] files should now look like */
/* */
/* Header ... */
/* */
/* #ifndef __MODNAME */
/* #define __MODNAME */
/* */
/* Includes ... */
/* */
/*+++ #ifdef __cplusplus */
/*+++ extern "C" { */
/*+++ #endif */
/* */
/* Signature ... */
/* */
/*+++ #ifdef __cplusplus */
/*+++ } */
/*+++ #endif */
/* #endif __MODNAME */
#include "stdosx.h"
#include "pathes.h"
#include "sink.h"
#include "dicts.h"
#include "line_scn.h"
#include "com_get.h"
#include "hmap.h"
#include "hset.h"
#include "symbols.h"
#include "ctoh_cim.h"
#include "binimg.h"
#include "scn_base.h"
#include "ccnv_lim.h"
static long pgmtim; /* the start time of this program */
static string null_line = "";
static string scan_line = (string)NULL;
static string line = (string)NULL;
static symbol ccls = (symbol)NULL;
static string cfid = (string)NULL;
static string lnam = (string)NULL;
static string hnam = (string)NULL;
static string cnam = (string)NULL;
static string enam = (string)NULL;
static FILE *SysIn = (FILE*)NULL;
static FILE *SysOut = (FILE*)NULL;
static FILE *SysExp = (FILE*)NULL;
static FILE *SysDoc = (FILE*)NULL;
static long lineno = 0; /* current line number */
static bool Patched = False; /* c/h patched in header comment */
static bool IncludeSeen = False; /* passed any includes */
static bool Shift = False; /* between '{' ... '}' */
static bool OnOff = True; /* 'INTERFACE_ON/OFF' */
static bool mainSeen = False; /* 'main' seen */
#define GenExp CTX_EVAL(string ,"exp")
#define GenApi CTX_EVAL(string ,"api")
static symbol ApiSym = (symbol)NULL;
#define CTypConv CTX_EVAL(bool,"ct")
static Scn_T pScn = (Scn_T)NULL;
#define DROOT CTX_EVAL(string ,"DROOT")
#define GET_REFERENCE(a,b) (getReference((void**)(a),(void (*)(void**))(b)))
#define PUT_REFERENCE(a,b) (putReference((void*)(a),(void (*)(void*))(b)))
#define LineLength 78
#define CommentMargin 40
#define HTML_DOCTYPE \
""
bool beginswith(string key)
{
return strncmp(line,key,strlen(key)) == 0;
}
bool endswith(string key)
{ int len = strlen(line), klen = strlen(key);
if( len < klen ) return False;
return strncmp(line+len-klen,key,klen) == 0;
}
void patchhead(void)
{ int fidlen = strlen(cfid), i, len = strlen(line);
for (i = 0; i < len; i++)
{
if (line[i] == '[' && strncmp(cfid,line+i+1,fidlen) == 0)
{ int j, k;
for( j=fidlen-1; j > 0; --j )
if( line[i+j] == '.' )
{
line[i+j+1] = 'h'; Patched = True; break;
}
k = i + fidlen + 1;
if( line[k] == '(' )
{ string s; int clslen = 0;
for( k=k+1; k < len; ++k )
if( line[k] == ')' )
{ ++k; break; }
else
{
if( isalpha(line[k]) || line[k] == '_' ) ++clslen;
else
{
fprintf(STDERR,"Warnung: %s bad module name.\n",cfid);
return;
}
}
s = SubStrCopy(line+i+fidlen+2,clslen);
ccls = stringToSymbol(s);
FreeMem(s);
}
if( line[k] != ']' )
{
fprintf(STDERR,"Warnung: %s missing closing bracket.\n",cfid);
return;
}
}
}
}
bool c_getline(void)
{
if( scan_line != NULL ) FreeMem(scan_line);
if ((scan_line = Line_get(SysIn)) == NULL)
{
line = null_line; return False;
}
else line = scan_line;
lineno += 1;
if (!Patched) patchhead();
if (line[0] == '{') Shift = True;
if (line[0] == '}') Shift = False;
mainSeen |= beginswith("main") || beginswith("int main");
return True;
}
static string convBlock(string szBlock)
/* C-Header-Block-Filter */
{ string szResult, szTxt;
Sink pSnk;
Scn_Stream pStream;
if (strstr(szBlock,"/*NOCONVERSION*/"))
return StrCopy(szBlock);
pSnk = Sink_open();
pStream = Stream_string(pScn, szBlock);
Stream_defEofId(pStream, -1);
Stream_defErrId(pStream, 0);
Stream_defTokId(pStream, "Ide", 1);
Stream_defTokId(pStream, "Inc", 2);
Stream_defTokId(pStream, "Com", 3);
Stream_defTokId(pStream, "Other", 4);
for(Stream_next(pStream); Stream_ctid(pStream) >= 0; Stream_next(pStream))
{
szTxt = symbolToString(Stream_csym(pStream));
if (Stream_ctid(pStream) == 1)
{
if( !strcmp(szTxt,"byte") ) Sink_printf(pSnk,"c_byte");
else
if( !strcmp(szTxt,"word") ) Sink_printf(pSnk,"c_word");
else
if( !strcmp(szTxt,"string") ) Sink_printf(pSnk,"c_string");
else
if( !strcmp(szTxt,"bool") ) Sink_printf(pSnk,"c_bool");
else
if( !strcmp(szTxt,"False") ) Sink_printf(pSnk,"C_False");
else
if( !strcmp(szTxt,"True") ) Sink_printf(pSnk,"C_True");
else Sink_printf(pSnk,"%s",szTxt);
}
else Sink_printf(pSnk,"%s",szTxt);
}
szResult = Sink_close(pSnk);
Stream_close(pStream);
Stream_free(pStream);
return szResult;
}
static bool Funpossible;
bool CppFunDef(void)
/* ob 'line' eine Methodendefinition einleitet */
{ int len = strlen(line), i;
/* assumes isLetter(line[0]) */
for( i=1; i < len-1; ++i )
{
if( line[i] == ':' && line[i+1] == ':' ) return( True );
if( ! ( islower(line[i]) ||
isupper(line[i]) ||
isdigit(line[i]) ||
line[i] == '*' ||
line[i] == '&' ||
line[i] == '_' ||
line[i] == ' ' ) ) return( False );
}
return( False );
}
bool BlockStart(void)
/* whether 'line' starts an interface block */
{
Funpossible = False;
if (Shift) return False;
if (!OnOff) return False;
if (beginswith("ExternalType"))
{
strncpy(line,"Abstract",8);
return True;
}
if (beginswith("ExternalDecl"))
{
strncpy(line,"AbstractType",12);
return True;
}
//18.10.98 _DLL_EXPORT_ startet einen Interface-Block !
if( beginswith("_DLL_EXPORT_") ||
(
( islower(line[0]) || isupper(line[0]) )
&& !beginswith("ConcreteType")
&& !beginswith("ConcreteImp")
&& !beginswith("static")
&& !beginswith("struct")
&& !beginswith("union")
&& !beginswith("typedef")
/* C++ - Rules */
&& !beginswith("class")
&& !beginswith("template")
&& !beginswith("inline")
&& !beginswith("namespace")
&& !beginswith("using")
&& !CppFunDef()
)
)
{
//Funpossible = (line[strlen(line)-1] == ')');
Funpossible = True;
return True;
}
if (beginswith("#include") && !IncludeSeen)
{ IncludeSeen = True; return True; }
if (beginswith("/*I-") || beginswith("/*I="))
{ line[2] = ' '; return True; }
return False;
}
static string replaceDocBlock(string block)
{ MAP(symbol,symbol) m = MAP_newPrimMap();
string res = (string)NULL;
MAP_dfndom(m,stringToSymbol("<"),stringToSymbol("<"));
MAP_dfndom(m,stringToSymbol(">"),stringToSymbol(">"));
MAP_dfndom(m,stringToSymbol("/*NOCONVERSION*/"),stringToSymbol(""));
res = Line_replace(block,m);
MAP_freeMap(m);
return res;
}
void writeDocFun
(
FILE* fp_doc, long idx, string funtyp, string funhdr, string funcom
)
/* writes a function declaration to the current document file */
/*
idx = -1 ==> multi line function definition in 'funhdr' or
end of single line function definitions
idx >= 0 ==> single line function definition [idx] in
'funtyp', 'funhdr', 'funcom'
*/
{ string dfuntyp, dfunhdr, dfuncom, t, t1, t2, t3;
if( idx == 0 || ( idx == -1 && funhdr != (string)NULL ) )
{
//if( idx == 0 ) fprintf(fp_doc,"
For an interpretative execution you may only need the binary
[$BINSTYX/Language.pim] and [$BINSTYX/Language.lim] image files which
contain the parser and scanner tables.
To process the derivation tree within your c/c++ program it's useful to
create the interface c source [$GENSTYX/Language(1,4)_int.c].
To process a derivation tree variant optimized wrt. memory usage it's useful
to create the special interface c source [$GENSTYX/Language(1,4)_ant.c].
Instead of using the table image files you can include the c sources
[$GENSTYX/Language(1,4)_pim.c] and [$GENSTYX/Language(1,4)_lim.c].
This option implies '-makeINT'.
In order to use the C++ scanner and parser classes you may only need the
file [$BINSTYX/Language.ltbl] which contains the scanner table definition and.
[$BINSTYX/Language.ptbl] which contains the parse table definition.
The given template file will be used for the export of the scanner and parse table
as constant string definitions in the format of the preferred programming language.
The placeholder @TABLE@ will be replaced by the concatenation of table type and
language ID.
The line containing the placeholder @LINE@ will be replicated for each
line of the current definition. Before substituting a quoted placeholder @LINE@
the actual definition line will be converted applying C-style quoting rules.
\n");
fprintf(fp_doc,"\n");
}
if( funhdr != (string)NULL )
{
dfunhdr = replaceDocBlock(funhdr);
fprintf(fp_doc,"
\n");
}
}
void writeDocBlock(FILE* fp_doc, string block, bool forcedDocBlock)
/* writes 'block' to the current document file */
{ string dblock, t1, t2, t3, t;
bool flag = False;
PIT itr;
if ( strstr(block,"AbstractType") == block ||
strstr(block,"AbstractHugeType") == block )
{
dblock = replaceDocBlock(block);
fprintf(fp_doc,"\n");
fprintf(fp_doc," ");
if( funtyp != (string)NULL )
{
dfuntyp = replaceDocBlock(funtyp);
fprintf(fp_doc," %s ",dfuntyp);
FreeMem(dfuntyp);
}
else
fprintf(fp_doc,"
\n",t1);
}
FreeMem(t1);
if( t2 != (string)NULL ) FreeMem(t2);
fprintf(fp_doc,"");
t1 = Line_withoutCCom(dfunhdr);
t = Line_clip(t1);
if( t1 != dfunhdr ) FreeMem(t1);
t1 = strstr(t,"#define ");
if( t1 != (string)NULL ) *t1 = '\0';
t2 = Line_getCFunNam(t);
if( t1 != (string)NULL ) *t1 = '#';
t1 = t;
if( t2 != (string)NULL )
{
t3 = strstr(t1,t2);
while( t < t3 )
{
fprintf(fp_doc,"%c",*t); t += 1;
}
fprintf(fp_doc,"%s",t2);
fprintf(fp_doc,"%s
\n",t3+strlen(t2));
}
else
{
fprintf(fp_doc,"%s");
if( funcom != (string)NULL )
{
dfuncom = replaceDocBlock(funcom);
fprintf ( fp_doc,"%s\n",dfuncom);
FreeMem(dfuncom);
}
else
{
t1 = Line_withCComText(dfunhdr);
if( t1 != (string)NULL )
{ Sink snk; PIT itr;
snk = Sink_open();
itr = PIT_make(t1); PIT_sep(itr,"\n");
while( ( t = PIT_read(itr) ) != NULL )
{
if( *t == '*' )
fprintf(fp_doc,"%s
\n",t+1);
else
Sink_printf(snk,"%s
\n",t);
}
t2 = Sink_close(snk);
fprintf(fp_doc,"%s",t2);
PIT_drop(itr);
FreeMem(t1);
FreeMem(t2);
}
else fprintf(fp_doc," ");
}
FreeMem(dfunhdr);
}
if( idx == -1 )
{
fprintf(fp_doc,"\n");
fprintf(fp_doc,"
\n");
fprintf(fp_doc,"\n");
itr = PIT_make(dblock); PIT_sep(itr,"\n");
while( ( t = PIT_read(itr) ) != NULL )
{
t1 = strstr(t,"("),
t2 = strrchr(t,')');
if( t1 != (string)NULL && t2 != (string)NULL && t1 < t2 )
{
fprintf(fp_doc,"
\n");
FreeMem(dblock);
}
else
if (strstr(block,"#include") == block)
{
dblock = replaceDocBlock(block);
t1 = Line_withoutCCom(dblock);
itr = PIT_make(t1); PIT_sep(itr,"\n");
while( ( t = PIT_read(itr) ) != NULL )
{
t2 = strstr(t,"#include");
if( t2 != (string)NULL )
{
t2 = strstr(t2,"\"");
if( t2 != (string)NULL )
{ Sink snk = Sink_open();
fprintf(fp_doc,"\n");
fprintf(fp_doc," ");
while( ( t1 += 1 ) < t2 )
{
fprintf(fp_doc,"%c",*t1);
}
fprintf(fp_doc,"\n");
fprintf(fp_doc," ");
t1 = Line_withCComText(t);
fprintf(fp_doc,"%s\n",t1==(string)NULL?"abstract type":t1);
if( t1 != (string)NULL ) FreeMem(t1);
fprintf(fp_doc,"\n");
}
}
PIT_drop(itr);
fprintf(fp_doc,"
#include \"%s.h\"\n",t3,t3);
FreeMem(t3);
}
else
{
fprintf(fp_doc,"
%s\n",t);
}
}
else
{
fprintf(fp_doc,"
%s\n",t);
}
}
PIT_drop(itr);
fprintf(fp_doc,"
\n");
if( t1 != dblock ) FreeMem(t1);
FreeMem(dblock);
}
else
if (strstr(block,"/* -") == block ||
(flag=(strstr(block,"/* =") == block)))
{
fprintf
(
fp_doc,
"%s",
"%", flag?"4":"2", flag?"":""
);
t1 = block + 3;
while( *t1 != '\0' && ( *t1 == '-' || *t1 == '=' ) )
t1 += 1;
t2 = t1 + strlen(t1);
while( t2 > t1 && *t2 != '/' )
t2 -= 1;
t2 -= 3;
while( t2 > t1 && ( *t2 == '-' || *t2 == '=' ) )
t2 -= 1;
while( t1 <= t2 )
{
if( *t1 == '<' )
fprintf(fp_doc,"<");
else
if( *t1 == '>' )
fprintf(fp_doc,">");
else
fprintf(fp_doc,"%c",*t1);
t1 += 1;
}
fprintf(fp_doc,"%s
\n",flag?"":"");
}
else
{
if( forcedDocBlock )
{
dblock = replaceDocBlock(block);
fprintf(fp_doc,"%s
\n",dblock);
FreeMem(dblock);
}
}
}
#define MaxFuncs 100
static struct
{
string typ;
string fun;
string com;
bool ext;
int ltyp;
int lfun;
int lcom;
}
Func[MaxFuncs];
static int topFunc = 0;
static int ltyp = 0;
static int lfun = 0;
static int lcom = 0;
void flushFuncs(void)
{ int i, xltyp, xlfun, xlcom;
if (topFunc == 0) return;
for (i = 0; i < topFunc; i++)
{
xltyp = (Func[i].ltyp==-1)?ltyp:Func[i].ltyp;
xlfun = (Func[i].lfun==-1)?lfun:Func[i].lfun;
xlcom = (Func[i].lcom==-1)?lcom:Func[i].lcom;
xlcom = MAX(xlcom,MIN(LineLength-CommentMargin+1,LineLength-xltyp-1-xlfun-2)-6);
if( Func[i].ext == False )
fprintf
(
SysOut, "%s%*s %s;%*s/* %s%*s */\n",
Func[i].typ, (int)(xltyp-strlen(Func[i].typ)),"",
Func[i].fun, (int)(xlfun-strlen(Func[i].fun)+
LineLength-xltyp-1-xlfun-1-xlcom-6),"",
Func[i].com, (int)(xlcom-strlen(Func[i].com)),""
);
else
fprintf
(
SysOut,"%s%s;\n\n",
( i>0&&Func[i-1].ext==False ) ? "\n" : "", Func[i].fun
);
if( SysDoc != (FILE*)NULL )
{
writeDocFun(SysDoc,i,Func[i].typ,Func[i].fun,Func[i].com);
}
if( Func[i].typ != (string)NULL ) FreeMem(Func[i].typ); FreeMem(Func[i].fun);
if( Func[i].com != (string)NULL ) FreeMem(Func[i].com);
}
fprintf(SysOut,"\n");
if( SysDoc != (FILE*)NULL )
{
writeDocFun(SysDoc,-1,(string)NULL,(string)NULL,(string)NULL);
}
topFunc = 0;
ltyp = 0;
lfun = 0;
lcom = 0;
}
void genFunExport(string CDecl)
{ string nam, t;
if( strstr(CDecl,"_NO_DLL_EXPORT_") == CDecl )
return;
t = strstr(CDecl,"#define");
if( t != (string)NULL ) *t = '\0';
nam = Line_getCFunNam(CDecl);
if( t != (string)NULL ) *t = '#';
if( nam != (string)NULL )
{
fprintf(SysExp,"/EXPORT:%s\n",nam);
FreeMem(nam);
}
}
void pushFuncLine(string h, string c)
{ int i, xltyp, xlfun, xlcom;
string typ, fun;
if(topFunc >= MaxFuncs) flushFuncs();
if( GenExp ) genFunExport(h);
for (i = 0; h[i] != 0 && h[i] != ' ' && h[i] != '('; i++);
if (h[i] != 0 && h[i] != '(')
{ h[i] = 0; typ = StrCopy(h); i+=1; }
else
{ i = 0; typ = StrCopy(""); }
while(h[i]==' ') i+=1;
fun = StrCopy(h+i);
FreeMem(h);
xltyp = strlen(typ);
xlfun = strlen(fun);
xlcom = strlen(c);
if (MAX(xltyp,ltyp)+1 + MAX(xlfun,lfun)+2 + MAX(xlcom,lcom)+6 > LineLength)
{
//flushFuncs();
for( i=topFunc-1; i >= 0; --i )
{
if( Func[i].ltyp == -1 )
{
Func[i].ltyp = ltyp;
Func[i].lfun = lfun;
Func[i].lcom = lcom;
}
}
ltyp = 0;
lfun = 0;
lcom = 0;
}
ltyp = MAX(xltyp,ltyp);
lfun = MAX(xlfun,lfun);
lcom = MAX(xlcom,lcom);
Func[topFunc].ltyp = -1;
Func[topFunc].lfun = -1;
Func[topFunc].lcom = -1;
Func[topFunc].typ = typ;
Func[topFunc].fun = fun;
Func[topFunc].com = c;
Func[topFunc].ext = False;
topFunc += 1;
}
void pushExtFuncLine(string fun)
{
if(topFunc >= MaxFuncs) flushFuncs();
Func[topFunc].ltyp = -1;
Func[topFunc].lfun = -1;
Func[topFunc].lcom = -1;
Func[topFunc].typ = (string)NULL;
Func[topFunc].fun = StrCopy(fun);
Func[topFunc].com = (string)NULL;
Func[topFunc].ext = True;
topFunc += 1;
}
void copyBlock(bool skipFirst, bool DocBlock, bool forcedDocBlock)
{ Sink snk = (Sink)NULL, ext = (Sink)NULL;
string temp = (string)NULL, s = (string)NULL, t;
bool expflg = ( !skipFirst && beginswith("_DLL_EXPORT_") ),
extflg = False;
if (Funpossible && !skipFirst && (line[strlen(line)-1] == ')'))
/* a simple function definition? */
{ int lft, rgh;
if( strlen(symbolToString(ApiSym)) > 0 && expflg )
{
s = line + strlen("_DLL_EXPORT_");
temp = Str_printf("_DLL_API_%s %s",symbolToString(ApiSym),s);
}
else temp = Str_printf("%s",line);
if( CTypConv )
{
t = convBlock(temp); FreeMem(temp); temp = t;
}
if( c_getline() && CTypConv )
{
t = convBlock(line); FreeMem(line); scan_line = line = t;
}
if
(
strstr(temp,"//") != (string)NULL ||
!(
line[0] == '{' ||
(beginswith("/*") && strcmp(line+strlen(line)-2,"*/") == 0)
) ||
( line[0] != '{' && strlen(temp) + strlen(line) + 2 > LineLength )
)
{
goto Ordinary;
}
if(line[0] == '{')
pushFuncLine(temp,StrCopy(""));
else
{
for (lft = 2; line[lft] == ' '; lft+=1);
for (rgh = strlen(line)-3; line[rgh] == ' '; rgh-=1);
if (rgh < lft)
rgh = lft-1;
line[rgh+1] = 0;
pushFuncLine(temp,StrCopy(line+lft));
}
while( line[0] != 0 && line[0] != '{') c_getline();
return;
Ordinary:
if( GenExp && line[0] != 0 )
{
if( line[0] == '{' ) genFunExport(temp);
else
{
ext = Sink_open();
Sink_printf(ext,"%s\n",temp);
}
}
if (line[0] == 0 || line[0] == '{')
{
t = Str_printf("%s\n",temp);
if( line[0] == '{' )
{
pushExtFuncLine(t);
}
else
{
flushFuncs();
fprintf(SysOut,"%s",t);
if( DocBlock )
writeDocBlock(SysDoc,t,forcedDocBlock);
}
FreeMem(temp); FreeMem(t);
return;
}
}
/* multiline function headers, macro definitions, ... */
snk = Sink_open();
if( temp != (string)NULL )
{
Sink_printf(snk,"%s\n",temp);
FreeMem(temp);
}
if (!skipFirst) Sink_printf(snk,"%s\n",line);
if( GenExp && Funpossible && !skipFirst &&
!beginswith("/*") && !beginswith("//") && !beginswith("#") )
{
extflg = True;
if( ext == (Sink)NULL )
ext = Sink_open();
Sink_printf(ext,"%s\n",line);
}
while(c_getline() && line[0] != 0 && line[0] != '{' )
{
if( extflg &=
( !beginswith("/*") && !beginswith("//") && !beginswith("#") ))
Sink_printf(ext,"%s\n",line);
if (beginswith("ExternalType"))
{
strncpy(line,"Abstract",8);
}
else
if (beginswith("ExternalDecl"))
{
strncpy(line,"AbstractType",12);
}
Sink_printf(snk,"%s\n",line);
}
temp = Sink_close(snk);
if( GenExp && Funpossible && !skipFirst )
{
t = Sink_close(ext);
if( line[0] == '{' ) genFunExport(t);
FreeMem(t);
}
if( CTypConv )
{
t = convBlock(temp); FreeMem(temp); temp = t;
}
if( strlen(symbolToString(ApiSym)) > 0 && expflg && s == (string)NULL )
{
t = Str_printf
(
"_DLL_API_%s %s%s",
symbolToString(ApiSym),temp + strlen("_DLL_EXPORT_"),
( line[0] == '{' ) ? "" : "\n"
);
}
else
t = Str_printf("%s%s",temp,( line[0] == '{' ) ? "" : "\n");
if( line[0] == '{' )
{
if( Funpossible && !skipFirst )
pushExtFuncLine(t);
else
{
flushFuncs();
fprintf(SysOut,"%s;\n\n",t);
if( DocBlock )
writeDocBlock(SysDoc,t,forcedDocBlock);
}
}
else
{
flushFuncs();
fprintf(SysOut,"%s",t);
if( DocBlock )
writeDocBlock(SysDoc,t,forcedDocBlock);
}
FreeMem(temp); FreeMem(t);
}
void skipDoc(void)
{
while(c_getline() && strcmp(line,"#endif") != 0) /* skip */;
}
void copyDoc
(
string szStartTagOri, string szStartTagNew, string szEndTag
)
{ string dline, t1, t2;
bool pretag = ( strstr(szStartTagOri,"!!") != (string)NULL );
if( SysDoc != (FILE*)NULL )
{
fprintf(SysDoc,"
");
if( pretag ) fprintf(SysDoc,"");
}
if( !strcmp(szStartTagOri,szStartTagNew) )
{
fprintf(SysOut,"%s\n",line);
}
else
{
fprintf(SysOut,"%s",szStartTagNew);
fprintf(SysOut,"%s\n",line+strlen(szStartTagOri));
}
t2 = strstr(line,szEndTag);
if( SysDoc != (FILE*)NULL )
{
dline = pretag?replaceDocBlock(line):StrCopy(line);
t2 = strstr(dline,szEndTag);
if( t2 != (string)NULL)
{
t1 = dline+strlen(szStartTagOri);
while( t1 < t2 )
{
fprintf(SysDoc,"%c",*t1); t1 += 1;
}
fprintf(SysDoc,"\n");
}
else
fprintf(SysDoc,"%s\n",dline+strlen(szStartTagOri));
FreeMem(dline);
}
if( t2 == (string)NULL)
{
while(c_getline() )
{
fprintf(SysOut,"%s\n",line);
if( (t2=strstr(line,szEndTag)) != (string)NULL)
{
if( SysDoc != (FILE*)NULL )
{
dline = pretag?replaceDocBlock(line):StrCopy(line);
t1 = dline;
t2 = strstr(dline,szEndTag);
while( t1 < t2 )
{
fprintf(SysDoc,"%c",*t1); t1 += 1;
}
fprintf(SysDoc,"\n");
FreeMem(dline);
}
break;
}
else
if( SysDoc != (FILE*)NULL )
{
dline = pretag?replaceDocBlock(line):StrCopy(line);
fprintf(SysDoc,"%s\n",dline);
FreeMem(dline);
}
}
}
fprintf(SysOut,"\n");
if( SysDoc != (FILE*)NULL )
{
if( pretag ) fprintf(SysDoc,"
");
fprintf(SysDoc,"\n");
}
}
void copyToI(string szEndTag, bool forcedDocBlock)
{ Sink pSnk = (Sink)NULL;
string dline, szIBlock, szCnvIBlock;
if( CTypConv ) pSnk = Sink_open();
if( forcedDocBlock )
fprintf(SysDoc,"\n");
while(c_getline() && strcmp(line,szEndTag) != 0)
{
if( CTypConv ) Sink_printf(pSnk,"%s\n",line);
else
{
fprintf(SysOut,"%s\n",line);
if( forcedDocBlock )
{
dline = replaceDocBlock(line);
fprintf(SysDoc,"%s\n",dline);
FreeMem(dline);
}
}
}
if( CTypConv )
{
szIBlock = Sink_close(pSnk);
szCnvIBlock = convBlock(szIBlock);
fprintf(SysOut,"%s\n",szCnvIBlock);
if( forcedDocBlock )
{
dline = replaceDocBlock(szCnvIBlock);
fprintf(SysDoc,"%s\n",dline);
FreeMem(dline);
}
FreeMem(szIBlock); FreeMem(szCnvIBlock);
}
else fprintf(SysOut,"\n");
if( forcedDocBlock )
fprintf(SysDoc,"
\n");
}
void printCLinkageOn(void)
{
fprintf(SysOut,"\n");
fprintf(SysOut,"#ifdef __cplusplus\n");
fprintf(SysOut,"extern \"C\" {\n");
fprintf(SysOut,"#endif\n");
fprintf(SysOut,"\n\n");
}
void convertText(void)
{ bool CLinkageFlag = False;
Patched = False;
lineno = 0;
IncludeSeen = False;
Funpossible = False;
Shift = False;
OnOff = True; /* INTERFACE_ON ! */
mainSeen = False;
if (c_getline()) copyBlock(False,False,False);
if (!Patched) fprintf(STDERR,"Warning: %s missing header comment.\n",cfid);
Patched = True;
fprintf(SysOut,"/* File generated by 'ctoh'. Don't change manually. */\n");
fprintf(SysOut,"\n");
fprintf(SysOut,"#ifndef %s_INCL\n",symbolToString(ccls));
fprintf(SysOut,"#define %s_INCL\n",symbolToString(ccls));
fprintf(SysOut,"\n\n");
if( strlen(symbolToString(ApiSym)) > 0 )
{
fprintf(SysOut,"#ifndef _DLL_API_%s\n",symbolToString(ApiSym));
fprintf(SysOut,"#ifdef _DLL_DFN_%s\n",symbolToString(ApiSym));
fprintf
(
SysOut,"#define _DLL_API_%s _DLL_EXPORT_DECL_\n",symbolToString(ApiSym)
);
fprintf(SysOut,"#else\n");
fprintf(SysOut,"#ifndef _NO_DLL_%s\n",symbolToString(ApiSym));
fprintf(SysOut,"#define _DLL_API_%s _DLL_IMPORT_\n",symbolToString(ApiSym));
fprintf(SysOut,"#endif\n");
fprintf(SysOut,"#endif\n");
fprintf(SysOut,"#endif\n");
fprintf(SysOut,"\n");
}
while (c_getline())
{
if( CLinkageFlag == False && IncludeSeen == True )
{
printCLinkageOn(); CLinkageFlag = True;
}
if(BlockStart())
{
if( CLinkageFlag == False && Funpossible == True )
{
printCLinkageOn(); CLinkageFlag = True;
}
copyBlock(False,(SysDoc!=(FILE*)NULL),False);
}
else
if(beginswith("/*!!"))
{
flushFuncs();
copyDoc("/*!!","/* ","*/");
}
else
if(beginswith("/*!"))
{
flushFuncs();
copyDoc("/*!","/* ","*/");
}
else
if(strcmp(line,"/*INTERFACE*/") == 0)
copyBlock(True,(SysDoc!=(FILE*)NULL),False);
else
if(strcmp(line,"/*DOC_INTERFACE*/") == 0)
{
copyBlock(True,(SysDoc!=(FILE*)NULL),True);
}
else
if(strcmp(line,"/*INTERFACE_OFF*/") == 0)
{
OnOff = False;
}
else
if(strcmp(line,"/*INTERFACE_ON*/") == 0)
{
OnOff = True;
}
else
if(strcmp(line,"/*INTERFACE_GROUP*/") == 0)
{
flushFuncs();
}
else
if(strcmp(line,"#ifdef INTERFACE") == 0)
{
flushFuncs();
copyToI("#endif",False);
}
else
if(strcmp(line,"#ifdef DOC_INTERFACE") == 0)
{
flushFuncs();
copyToI("#endif",(SysDoc!=(FILE*)NULL));
}
else
if(strcmp(line,"/*INTERFACE_COPY_ON*/") == 0)
{
flushFuncs();
copyToI("/*INTERFACE_COPY_OFF*/",False);
}
else
if(strcmp(line,"/*DOC_INTERFACE_COPY_ON*/") == 0)
{
flushFuncs();
copyToI("/*DOC_INTERFACE_COPY_OFF*/",(SysDoc!=(FILE*)NULL));
}
else
if(strcmp(line,"#ifdef DOCUMENT") == 0)
{
skipDoc();
}
else
if( CLinkageFlag == False && strcmp(line,"/*INTERFACE_LINKAGE_ON*/") == 0 )
{
flushFuncs();
printCLinkageOn(); CLinkageFlag = True;
}
}
flushFuncs();
fprintf(SysOut,"\n");
if( CLinkageFlag == True )
{
fprintf(SysOut,"#ifdef __cplusplus\n");
fprintf(SysOut,"}\n");
fprintf(SysOut,"#endif\n\n");
}
fprintf(SysOut,"#endif\n");
}
#define tnam "____ctoh.___"
ConcreteType( ModuleInfo )
{
symbol Path; /* only in 'newmap' ( C-Path; Base is dom ) */
symbol hext;
symbol scls;
long Ctim;
long Htim;
short prog; /* mainflag */
};
ModuleInfo mi_Copy(ModuleInfo mi)
{ ModuleInfo res = New(ModuleInfo);
res->Path = mi->Path;
res->hext = mi->hext;
res->scls = mi->scls;
res->Ctim = mi->Ctim;
res->Htim = mi->Htim;
res->prog = mi->prog;
return res;
}
void mi_Free(ModuleInfo mi)
{
FreeMem(mi);
}
MAPTY glotyp;
MAPTY clstyp;
MAP(symbol, ModuleInfo) newmap;
MAP(symbol, ModuleInfo) oldmap;
MAP(symbol, HS_Set) clsmap;
MAP(symbol, long ) oldtim;
MAP(symbol, long ) newtim;
int errcnt;
bool validModule(symbol Cpath, symbol BaseSy, long Ctime, long Htime)
{ bool res = False;
if (MAP_defined(oldmap,BaseSy))
{ ModuleInfo mi = MAP_apply(ModuleInfo,oldmap,BaseSy);
res = (mi->Path == Cpath && mi->Ctim == Ctime && mi->Htim == Htime);
if (res)
{
ccls = mi->scls; mainSeen = mi->prog;
}
mi_Free(mi);
}
return res;
}
void addModule(symbol ModSy, ModuleInfo mi)
{
if (MAP_defined(newmap,ModSy))
{ ModuleInfo mo = MAP_apply(ModuleInfo,newmap,ModSy);
fprintf
(
STDERR,"Module [%s.c(xx)] both in dictionary '%s' and in '%s'.\n",
symbolToString(ModSy),
symbolToString(mi->Path),
symbolToString(mo->Path)
);
mi_Free(mo);
errcnt += 1;
MAP_upddom(newmap,ModSy,mi);
}
else MAP_dfndom(newmap,ModSy,mi);
}
void PutMi(void)
/* put module info to [$PRJ/ctoh.cth] */
{ symbol fsy; MAPIT itr;
putBgn("PRJ","ctoh.cth","");
putHeader("[ctoh.cth] Binary image for 'ctoh'\n","cth",3,0);
putWord((short)MAP_count(newmap));
MAP_forItr(fsy,itr,newmap)
{ ModuleInfo mi = MAP_apply(ModuleInfo,newmap,fsy);
putSymbol(fsy);
PUT_REFERENCE(mi->Path,putSymbol);
PUT_REFERENCE(mi->hext,putSymbol);
PUT_REFERENCE(mi->scls,putSymbol);
putLong(mi->Ctim);
putLong(mi->Htim);
putWord(mi->prog);
mi_Free(mi);
}
putWord((short)MAP_count(newtim));
MAP_forItr(fsy,itr,newtim)
{ long tim = MAP_apply(long,newtim,fsy);
putSymbol(fsy);
putLong(tim);
}
putEnd();
}
void GetMi(void)
/* get module info from [$PRJ/ctoh.cth] */
{ short i,size;
{ string tmp = MkPath("PRJ","ctoh.cth","",'p');
if (!IsPath(tmp)) { FreeMem(tmp); return; } else FreeMem(tmp);
}
getBgn("PRJ","ctoh.cth","");
getHeader("cth",3,0);
getWord(&size);
for (i = 0; i < size; i++)
{ symbol fsy; ConcreteImp(ModuleInfo) mi;
getSymbol(&fsy);
GET_REFERENCE(&mi.Path,getSymbol);
GET_REFERENCE(&mi.hext,getSymbol);
GET_REFERENCE(&mi.scls,getSymbol);
getLong(&mi.Ctim);
getLong(&mi.Htim);
getWord(&mi.prog);
MAP_dfndom(oldmap,fsy,&mi);
}
getWord(&size);
for (i = 0; i < size; i++)
{ symbol fsy; long tim;
getSymbol(&fsy);
getLong(&tim);
MAP_dfndom(oldtim,fsy,tim);
}
getEnd();
}
bool FileEqual(string fna, string fnb)
/* whether files 'fna' and 'fnb' are binary equal */
{ FILE* fa = OpnFile(fna,"rb");
FILE* fb = OpnFile(fnb,"rb");
int ca, cb;
for
(
ca = fgetc(fa), cb = fgetc(fb);
ca != EOF && cb != EOF && ca == cb;
ca = fgetc(fa), cb = fgetc(fb)
);
fclose(fa); fclose(fb);
return ca == cb;
}
/* ----------------- Handling Multiple Implementations --------------------- */
string normalize_header_line(string line, string cfid, bool *hl)
/* returns a line, normalizing header line if '*hl == True' */
{
if (!*hl || line == NULL) return line;
{ int i,j,k,m, len = strlen(line), blen = strlen(cfid); string ext;
for (i = 0; i < len; i++)
{
if (strncmp(cfid,line+i,blen) == 0)
{
if (line[i+blen] != '(') return line;
for( j=blen-1; j > 0 && line[i+j] != '.' ; --j );
ext = SubStrCopy(line+i+j,blen-j);
for( j=0; line[i+blen+1+j] != 0 && line[i+blen+1+j] != ')'; ++j )
line[i+j] = line[i+blen+1+j];
for( k=0; k < strlen(ext); k++)
line[i+j+k] = ext[k];
line[i+j+k] = ']';
for(m = 1; m < j+2; m++)
line[i+j+k+m] = ' ';
FreeMem(ext);
*hl = False;
return line;
}
}
}
return line;
}
string Line_get_normal(FILE* f, string cfid, bool *hl)
{
return normalize_header_line(Line_get(f), cfid, hl);
}
bool FileNormalEqual(string fna, string cna, string fnb, string cnb)
/* whether files 'fna' and 'fnb' are binary equal */
{ FILE* fa = OpnFile(fna,"rt");
FILE* fb = OpnFile(fnb,"rt");
string sa, sb; bool ha = True, hb = True; long lna=1,lnb=1;
bool res;
for
(
sa = Line_get_normal(fa,cna,&ha), sb = Line_get_normal(fb,cnb,&hb);
sa != NULL && sb != NULL && strcmp(sa,sb) == 0;
sa = Line_get_normal(fa,cna,&ha), sb = Line_get_normal(fb,cnb,&hb)
)
{
FreeMem(sa); FreeMem(sb); lna+=1; lnb+=1;
};
fclose(fa); fclose(fb);
res = ((sa == sb) || strcmp(sa,sb) == 0);
if (sa != NULL) FreeMem(sa);
if (sb != NULL) FreeMem(sb);
if (!res)
{
fprintf(STDERR,"files %s(%ld), %s(%ld) differ.\n",fna,lna,fnb,lnb);
errcnt += 1;
}
return res;
}
void FileNormalize(string fna, string cna, string fnb)
/* normalizes header of file 'fna' */
{ FILE* fa; FILE* fb;
string sa; bool ha = True;
if (strcmp(fna,fnb) == 0) return;
fa = OpnFile(fna,"rt");
fb = OpnFile(tnam,"wt");
for
(
sa = Line_get_normal(fa,cna,&ha);
sa != NULL;
sa = Line_get_normal(fa,cna,&ha)
)
{
fprintf(fb,"%s\n",sa);
FreeMem(sa);
};
fclose(fa); fclose(fb);
if (IsPath(fnb) && FileEqual(fnb,tnam))
remove(tnam);
else
{
remove(fnb); rename(tnam,fnb);
fprintf(STDOUT,"-> %s\n",fnb);
}
}
void editClass(symbol sclass, symbol BaseSy)
/* adds/updates current class 'sclass' */
{ HS_Set cset;
if( ! MAP_defined(clsmap,sclass) )
{
cset = HS_CREATE_ADTSET(symbol);
MAP_dfndom(clsmap,sclass,cset);
MAP_dfndom
(
newtim,
sclass,
MAP_defined(oldtim,sclass)?MAP_apply(long,oldtim,sclass):0L
);
}
else cset = MAP_apply(HS_Set,clsmap,sclass);
HS_SET_ELM(BaseSy,cset);
}
void multipleH(bool Force)
/* handles multiple Implementations */
{ MAPIT itr; symbol dom; HMP_Rng rng;
MAP_forItrAsg(dom,rng,itr,clsmap)
{ HS_Itr hit; symbol elm; long youngest = 0L; bool ok = True;
symbol hext = (symbol)NULL; symbol firstH = (symbol)NULL; string s1;
HS_FORALL(elm,hit,rng)
{ ModuleInfo mi = MAP_apply(ModuleInfo,newmap,elm);
youngest = MAX(youngest,mi->Htim);
if( hext == (symbol)NULL ) hext = mi->hext;
else
{
if( hext != mi->hext )
{
fprintf
(
STDERR,"different Header Types for Class '%s'.\n",
symbolToString(dom)
);
errcnt += 1;
}
}
if( firstH == (symbol)NULL ) firstH = (symbol)elm;
FreeMem(mi);
}
s1 = MkPath("HPATH",symbolToString(dom),symbolToString(hext),'e');
if
(
Force ||
pgmtim <= youngest ||
!IsPath(s1) ||
PathMTime(s1) != MAP_apply(long,newtim,dom)
)
{ string s3=Str_printf("%s%s",symbolToString(firstH),symbolToString(hext));
string s4=Str_printf("%s%s",symbolToString(dom),symbolToString(hext));
string s2 = MkPath
(
"HPATH",symbolToString(firstH),symbolToString(hext),'e'
);
FileNormalize(s2,s3,s1);
HS_FORALL(elm,hit,rng)
{ string s5 = MkPath
(
"HPATH",symbolToString(elm),symbolToString(hext),'e'
);
string s6 = Str_printf("%s%s",symbolToString(elm),symbolToString(hext));
ok &= FileNormalEqual(s1,s4,s5,s6);
FreeMem(s5); FreeMem(s6);
}
FreeMem(s2); FreeMem(s3); FreeMem(s4);
}
MAP_upddom(newtim,dom,ok?PathMTime(s1):-1L);
FreeMem(s1);
}
}
FILE* BeginDocFile(string Dpath, string BaseName, string Ext)
{ FILE* fp_doc = (FILE*)NULL;
if( *Dpath != '\0' )
{ string dnam, title, tmp;
title = Com_GetEx(cnam);
tmp = strstr(title,"#");
if( tmp == (string)NULL )
{
dnam = MkPath(Dpath,BaseName,".htm",'d');
fp_doc = OpnFile(dnam,"w");
if( fp_doc != (FILE*)NULL )
{
fprintf(fp_doc,"%s\n",HTML_DOCTYPE);
fprintf
(
fp_doc,
"\n\n[%s.h] %s
\n",
BaseName,title
);
}
FreeMem(dnam);
}
else
{
*tmp = '\0';
if( strlen(title) == 0 )
title = BaseName;
dnam = MkPath(Dpath,title,".htm",'d');
fp_doc = OpnFile(dnam,"w");
if( fp_doc != (FILE*)NULL )
{
fprintf(fp_doc,"%s\n",HTML_DOCTYPE);
fprintf
(
fp_doc,
"\n\n[%s.h] %s
\n",
title,tmp+1
);
if( strlen(DROOT) > 0 )
fprintf
(
fp_doc,
"contents
\n",
DROOT
);
}
FreeMem(dnam);
}
}
return fp_doc;
}
void EndDocFile(FILE* fp_doc)
{
if( fp_doc != (FILE*)NULL )
{
fprintf(fp_doc,"\n\n\n");
fclose(fp_doc);
}
}
void htod
(
symbol HpathSy, string BaseName, string Ext, string Dpath
)
{
string Hpath = symbolToString(HpathSy), dline, t, t1;
bool header = True,
comblk = False,
pretag = False;
Sink snk = (Sink)NULL;
long lineno = 0;
cnam = MkPath(Hpath,BaseName,Ext,'d');
SysIn = OpnFile(cnam,"r");
SysDoc = BeginDocFile(Dpath,BaseName,Ext);
while ((line = Line_get(SysIn)) != (string)NULL)
{
if( header )
{
if( line[0] == '\0' ) header = False;
}
else
if( comblk )
{
dline = pretag?replaceDocBlock(line):StrCopy(line);
if( (t1=strstr(dline,"*/")) != (string)NULL )
{
t = dline;
while ( t < t1 )
{
Sink_printf(snk,"%c",*t); ++t;
}
Sink_printf(snk,"\n");
t1 = Sink_close(snk);
fprintf(SysDoc,"%s",t1);
if( pretag ) fprintf(SysDoc,"");
FreeMem(t1);
comblk = False;
}
else Sink_printf(snk,"%s\n",dline);
FreeMem(dline);
}
else
{
if( beginswith("/*!") )
{
pretag = ( beginswith("/*!!") );
dline = pretag?replaceDocBlock(line):StrCopy(line);
if( (t1=strstr(dline,"*/")) != (string)NULL )
{
fprintf(SysDoc,"%s\n",dline+4);
else
Sink_printf(snk,"
%s
",dline);
FreeMem(dline);
}
}
++lineno;
FreeMem(line);
}
EndDocFile(SysDoc);
fclose(SysIn);
FreeMem(cnam);
}
void ctoh
(
symbol CpathSy, string Hpath, string BaseName, string Ext,
bool Force, string Dpath
)
{ string Cpath = symbolToString(CpathSy); string HExt = StrCopy(Ext);
symbol BaseSy = stringToSymbol(BaseName);
long Ctime, Htime; ConcreteImp(ModuleInfo) mi;
ccls = BaseSy;
cnam = MkPath(Cpath,BaseName,Ext,'d');
HExt[1] = 'h';
hnam = MkPath(Hpath,BaseName,HExt,'d');
cfid = Str_printf("%s%s",BaseName,Ext);
lnam = StrToUpper(StrCopy(BaseName));
Ctime = PathMTime(cnam);
Htime = IsPath(hnam) ? PathMTime(hnam) : 0L;
if (validModule(CpathSy,BaseSy,Ctime,Htime) && !Force) goto Done;
SysDoc = BeginDocFile(Dpath,BaseName,Ext);
SysIn = OpnFile(cnam,"r");
SysOut = OpnFile(tnam,"w");
if( GenExp )
{
enam = MkPath(Hpath,BaseName,".exp",'d');
SysExp = OpnFile(enam,"w");
}
convertText();
if( GenExp )
{
fclose(SysExp);
FreeMem(enam);
}
fclose(SysOut);
fclose(SysIn);
EndDocFile(SysDoc);
if (mainSeen)
{
if( ccls != BaseSy )
{
fprintf(STDERR,"Program [%s.c(xx)] with multiple Headers.\n",BaseName);
errcnt += 1;
}
remove(tnam);
}
else
{
if (!Force && Htime != 0 && FileEqual(hnam,tnam)) remove(tnam);
else
{
remove(hnam); rename(tnam,hnam);
Htime = PathMTime(hnam);
fprintf(STDOUT,"-> %s%s\n",BaseName,HExt);
}
}
Done:
mi.Path = CpathSy; mi.hext = stringToSymbol(HExt); mi.scls = ccls;
mi.Ctim = Ctime; mi.Htim = Htime; mi.prog = mainSeen;
addModule(BaseSy,&mi);
if( !mainSeen ) editClass(ccls,BaseSy);
FreeMem(cnam); FreeMem(hnam); FreeMem(cfid); FreeMem(lnam); FreeMem(HExt);
}
void RemoveOldH(void)
/* removes all H-files in [$HPATH] no occuring in [ctoh.cth] */
{
DII dii; PIT pit; string srcpath;
pit = PIT_make(CTX_EVAL(string,"HPATH"));
while( ( srcpath = PIT_read(pit) ) != NULL )
{
DII_FORALL(dii,srcpath,"*.h")
{ string base = DII_get_base(dii);
if( !MAP_defined(newmap,stringToSymbol(base)) &&
!MAP_defined(clsmap,stringToSymbol(base)) )
{ string tmp = Str_printf("%s/%s.h",srcpath,base);
printf("-- %s.h\n",base);
remove(tmp); FreeMem(tmp);
}
FreeMem(base);
}
DII_FORALL(dii,srcpath,"*.hxx")
{ string base = DII_get_base(dii);
if( !MAP_defined(newmap,stringToSymbol(base)) &&
!MAP_defined(clsmap,stringToSymbol(base)) )
{ string tmp = Str_printf("%s/%s.hxx",srcpath,base);
printf("-- %s.hxx\n",base);
remove(tmp); FreeMem(tmp);
}
FreeMem(base);
}
}
PIT_drop(pit);
}
int main(int argc, string argv[])
{ DII dii; PIT pit;
string srcpath, srclib, tmp;
MAPIT itr; HMP_Dom dom; HMP_Rng rng;
CTX_init_ctoh(argc,argv);
bug0(strcmp(CTX_EVAL(string,"PRJ"),""),"Variable PRJ undefiniert");
initSymbols();
MAP_init();
pgmtim = time(NULL);
errcnt = 0;
glotyp = MAP_newTyp(primCopy,primFree,primEqual,primHash, mi_Copy,mi_Free);
clstyp = MAP_newTyp(primCopy,primFree,primEqual,primHash, primCopy,primFree);
newmap = MAP_newMap( glotyp );
oldmap = MAP_newMap( glotyp );
clsmap = MAP_newMap( clstyp );
oldtim = MAP_newMap( clstyp );
newtim = MAP_newMap( clstyp );
GetMi();
if( CTypConv ) Scn_get_ccnv(&pScn);
pit = PIT_make(CTX_EVAL(string,"CPATH"));
while( ( srcpath = PIT_read(pit) ) != NULL )
{ symbol psy;
ApiSym = stringToSymbol(GenApi);
tmp = strstr(srcpath,"~");
if( tmp != (string)NULL )
{
srclib = srcpath;
srcpath = tmp + 1;
*tmp = '\0';
ApiSym = stringToSymbol(srclib);
}
psy = stringToSymbol(srcpath);
DII_FORALL(dii,srcpath,"*.c")
{ string base = DII_get_base(dii);
ctoh
(
psy,
CTX_EVAL(string,"HPATH"),
base,
".c",
CTX_EVAL(bool ,"force"),
CTX_EVAL(string,"DPATH")
);
FreeMem(base);
}
DII_FORALL(dii,srcpath,"*.cxx")
{ string base = DII_get_base(dii);
ctoh
(
psy,
CTX_EVAL(string,"HPATH"),
base,
".cxx",
CTX_EVAL(bool ,"force"),
CTX_EVAL(string,"DPATH")
);
FreeMem(base);
}
DII_FORALL(dii,srcpath,"*.cpp")
{ string base = DII_get_base(dii);
ctoh
(
psy,
CTX_EVAL(string,"HPATH"),
base,
".cpp",
CTX_EVAL(bool ,"force"),
CTX_EVAL(string,"DPATH")
);
FreeMem(base);
}
if( *(CTX_EVAL(string,"DPATH")) != '\0' )
{
DII_FORALL(dii,srcpath,"*.h")
{ string base = DII_get_base(dii);
htod
(
psy, base, ".h", CTX_EVAL(string,"DPATH")
);
FreeMem(base);
}
}
}
PIT_drop(pit);
multipleH(CTX_EVAL(bool,"force"));
PutMi();
if( CTypConv ) Scn_free(pScn);
RemoveOldH();
MAP_freeMap(newmap);
MAP_freeMap(oldmap);
MAP_forItrAsg(dom,rng,itr,clsmap) HS_DROP_SET(rng);
MAP_freeMap(clsmap);
MAP_freeMap(oldtim);
MAP_freeMap(newtim);
MAP_freeTyp(glotyp);
MAP_freeTyp(clstyp);
MAP_quit();
freeSymbols();
CTX_quit();
if (errcnt > 0)
{
fprintf(STDERR,"total %d error(s).\n",errcnt);
STD_ERREXIT;
}
BUG_CORE;
return(0);
}
styx-2.0.1/pgm/styx.c 0000666 0001750 0001750 00000005606 10315553112 011407 0000000 0000000 /* ------------------------------------------------------------------------- */
/* */
/* [styx.c] STYX Compiler */
/* - realizes an abstract syntax tree - */
/* */
/* Copyright (c) 1993 by D\olle, Manns. */
/* ------------------------------------------------------------------------- */
#include "stdosx.h"
#include "pathes.h"
#include "styx_gen.h"
#include "styx_cim.h"
#define language CTX_EVAL(string,"Language")
#define verbose CTX_EVAL(bool,"verbose")
#define diagnose CTX_EVAL(bool,"diagnose")
#define makeIMG CTX_EVAL(bool,"makeIMG")
#define makeINT CTX_EVAL(bool,"makeINT")
#define makeANT CTX_EVAL(bool,"makeANT")
#define makeC CTX_EVAL(bool,"makeC")
#define export CTX_EVAL(bool,"export")
#define exportTMPL CTX_EVAL(string,"exportTMPL")
#define shortform CTX_EVAL(bool,"shortform")
#define conflicts CTX_EVAL(bool,"conflicts")
static void generate(Styx_T styctx)
{ PLR_Tab PTab = (PLR_Tab)NULL;
if( shortform ) STYX_set_shortform(styctx,shortform);
if( makeIMG ) STYX_createTabIMG(styctx,"BINSTYX");
if( makeC ) STYX_createTabC(styctx,"GENSTYX");
if( export ) STYX_exportTab(styctx,"BINSTYX",exportTMPL);
STYX_get_tables(styctx,&PTab,_);
if( PTab != (PLR_Tab)NULL )
{
STYX_createABS(styctx,"GENSTYX");
if( makeC || makeINT )
{
STYX_createIntC(styctx,"GENSTYX");
}
if( makeANT )
{
STYX_createAntC(styctx,"GENSTYX");
}
}
if( !makeIMG && !makeINT && !makeC && !export )
fprintf(STDERR,"Note: No file created.\n");
}
int main(int argc, string argv[])
{ StyxApp_T styapp; Styx_T styctx, rng;
MAP(symbol,Styx_T) embed = (MAP(_,_))NULL;
MAPIT itr; symbol dom; int rc;
CTX_init_styx(argc,argv);
if (verbose)
{
fprintf(STDERR,"Welcome to Styx %s as of '%s'\n",VERSION,__DATE__);
}
styapp = STYX_app_init();
if( styapp != (StyxApp_T)NULL )
{
styctx = STYX_init(styapp,language,NULL,verbose,diagnose);
if( styctx != (Styx_T)NULL )
{ c_string filename = MkPath("SPESTYX",language,".sty",'p');
STYX_set_conflict_policy(styctx,conflicts);
rc = STYX_compile_file(styctx,filename,"SPESTYX");
FreeMem(filename);
if( rc == 0 )
{
generate(styctx);
embed = STYX_get_embed(styctx);
if( embed != (MAP(_,_))NULL )
{
MAP_forItrAsg(dom,rng,itr,embed)
{
generate(rng);
}
MAP_freeMap(embed);
}
}
STYX_quit(styctx);
}
else fprintf(STDERR,"'%s' compilation init failed.\n",language);
}
else fprintf(STDERR,"Styx application init failed.\n");
STYX_app_quit(styapp);
CTX_quit();
BUG_CORE;
return 0;
}
styx-2.0.1/pgm/ctoh.cmd 0000666 0001750 0001750 00000014360 10373405111 011652 0000000 0000000 # [ctoh.cmd] command description for [ctoh.c]
Program ctoh -- C header file generation
doc
Overview
| Header ...
| #ifndef
Rules
In order to force the copy of certain c source lines to the interface the first line of such
a block must only contain the comment '/*INTERFACE*/'. This line will be skipped and not copied.
In addition to the previous method the following uses an explicit start and end tag to provide
more flexibility.
| /*INTERFACE_COPY_ON*/
| ...
| /*INTERFACE_COPY_OFF*/
The first and last line won't be copied.
The following mechanismn applies to text which should be placed in the interface but is not
visible in the c source file for the c/c++ compiler. This is done via the below mentioned
conditional preprocessor directive. As a consequence the macro name 'INTERFACE' can't be
defined.
| #ifdef INTERFACE
| ...
| #endif
The first and last line won't be copied.
| #ifdef DOCUMENT
| ...
| #endif
cod
Arguments
Options
CPATH : path = "." -- [DLL basename~]C source directory ; ... [*.c]
HPATH : path = "." -- H target directory [*.h]
PRJ : path = "." -- directory for project image file [ctoh.cth]
force : flag = false -- force the creation of the header files
ct : flag = false -- prefix type identifier string,bool,byte,word with 'c_'
exp : flag = false -- generate ms linker export directives / modul
DPATH : path = "" -- document target directory [*.htm]
DROOT : path = "index.html" -- root document file
api : string = ""
-- DLL basename for ms DLL-based ex/import directives, applied to functions prefixed with '_DLL_EXPORT_'
doc
*/
/*I------------------------- Type of regular sets ------------------------- */
AbstractType(RegSet_T); /* Regular Set */
/* -- Graph for finite automation -- */
#define RegSet_IMP(X) ((regset_t)(X))
#define RegSet_ADT(X) ((RegSet_T)(X))
ConcreteType(regset_t)
{
int id;
List(faNode) Nodes; /* !empty; fst == start */
};
ConcreteType(faNode)
{
int id;
regset_t Belongs;
List(faNode) Source; /* list of "source" nodes */
int term; /* terminal state if > 0 */
List(dfaEdge) Edges;
int flag1;
int flag2;
};
ConcreteType(dfaEdge)
{
wc_char dfa_lower;
wc_char dfa_upper;
faNode dfa_toNode;
};
ConcreteType(nfaEdge)
{
wc_char nfa_lower;
wc_char nfa_upper;
List(faNode) nfa_toNodes;
};
/* -- Edge constructor -- */
static dfaEdge newDfaEdge(wc_char lower, wc_char upper, faNode toNode)
{ dfaEdge res = New(dfaEdge);
res->dfa_lower = lower;
res->dfa_upper = upper;
res->dfa_toNode = toNode;
return res;
}
static nfaEdge newNfaEdge(wc_char lower, wc_char upper, List(faNode) toNodes)
{ nfaEdge res = New(nfaEdge);
res->nfa_lower = lower;
res->nfa_upper = upper;
res->nfa_toNodes = toNodes;
return res;
}
/*I-------------------------- Disposing ----------------------------------- */
static void freeNothing(Abs_T dummy)
{
}
static void freeNfaEdge(nfaEdge x)
{
freeList(x->nfa_toNodes, freeNothing);
FreeMem(x);
}
static void freeDfaNode(faNode x)
/* frees dfa node */
{
freeList(x->Source, freeNothing);
freeList(x->Edges, FreeMem);
FreeMem(x);
}
void RegSet_Free(RegSet_T g)
/* frees regular set 'g' */
{
freeList(RegSet_IMP(g)->Nodes, (void (*)(Abs_T x)) freeDfaNode);
FreeMem(g);
}
/*I-------------------------- RegSet Constructors ------------------------- */
/*!
*/
/*I-------------------- Types ------------------------------------------- */
ExternalType(Reg_T) // Abstract regular expression evaluation type
{
Scn_T pRScn; // common Regular Expression Scanner
Scn_T pVScn; // special Regular Expression Scanner
};
/*I-------------------- Creating & Disposing ---------------------------- */
static RegSet_T REG_String(c_string s)
{ RegSet_T reg; long len; c_bool ucs4;
wc_string tstring = LIT_styx_lit_str(&len,s,&ucs4);
reg = RegSet_StringN(tstring,len);
FreeMem(tstring);
return reg;
}
static RegSet_T REG_Cset(c_string s)
{ RegSet_T reg; long len; c_bool ucs4;
wc_string tstring = LIT_styx_lit_str(&len,s,&ucs4);
reg = RegSet_CsetN(tstring,len);
FreeMem(tstring); return reg;
}
static RegSet_T REG_self(RegSet_T pRegSet)
{
return pRegSet;
}
static RegSet_T REG_plus(RegSet_T pRegSet)
{ RegSet_T pRes = RegSet_Plus(pRegSet);
RegSet_Free(pRegSet);
return pRes;
}
static RegSet_T REG_option(RegSet_T pRegSet)
{ RegSet_T pRes = RegSet_Option(pRegSet);
RegSet_Free(pRegSet);
return pRes;
}
static RegSet_T REG_star(RegSet_T pRegSet)
{ RegSet_T pRes = RegSet_Star(pRegSet);
RegSet_Free(pRegSet);
return pRes;
}
static RegSet_T REG_concat(RegSet_T pLeft, RegSet_T pRight)
{
if( pLeft == (RegSet_T)NULL ) return pRight;
else
if( pRight == (RegSet_T)NULL ) return pLeft;
else
{ RegSet_T pRes = RegSet_Concat(pLeft,pRight);
RegSet_Free(pLeft); RegSet_Free(pRight);
return pRes;
}
}
static RegSet_T REG_diff(RegSet_T pLeft, RegSet_T pRight)
{ RegSet_T pRes = RegSet_Difference(pLeft,pRight);
RegSet_Free(pLeft); RegSet_Free(pRight);
return pRes;
}
static RegSet_T REG_union(RegSet_T pLeft, RegSet_T pRight)
{ RegSet_T pRes = RegSet_Union(pLeft,pRight);
RegSet_Free(pLeft); RegSet_Free(pRight);
return pRes;
}
static RegSet_T REG_range(RegSet_T pLeft, RegSet_T pRight)
{ RegSet_T pRes = (RegSet_T)NULL;
wc_char al, bu, x;
if(RegSet_isChar(pLeft) && RegSet_isChar(pRight))
{
al = RegSet_charVal(pLeft);
bu = RegSet_charVal(pRight);
if (al > bu)
{
x = al; al = bu; bu = x;
}
pRes = RegSet_Range(al,bu);
}
RegSet_Free(pLeft); RegSet_Free(pRight);
return pRes;
}
static RegSet_T REG_sigma(void)
/* FIXME: charset size */
{
return RegSet_Range((wc_char)0,(wc_char)((wc_char)(SCN_CHAR_SET_SIZE)-(wc_char)1));
}
static RegSet_T REG_plus_limited(RegSet_T pRegSet, int nMax)
{ RegSet_T pRes = RegSet_Plus_ntimes(pRegSet,nMax);
RegSet_Free(pRegSet);
return pRes;
}
static RegSet_T REG_plus_range(RegSet_T pRegSet, int nMin, int nMax)
{ RegSet_T pRes = (RegSet_T)NULL;
if( pRegSet != (RegSet_T)NULL )
{ int nI;
pRes = REG_plus_limited(RegSet_Copy(pRegSet),nMin);
for( nI=nMin+1; nI <= nMax; ++nI )
{ RegSet_T pTmp = REG_option(RegSet_Copy(pRegSet));
pRes = REG_concat(pRes,pTmp);
}
RegSet_Free(pRegSet);
}
return pRes;
}
static void REG_freeExps(ROW(RegSet_T) pRegRow)
{ long lCnt = OT_CNT(pRegRow), lI;
for( lI=0; lI < lCnt; ++lI )
RegSet_Free(OT_GET(RegSet_T,pRegRow,lI));
OT_CLEAR(pRegRow);
}
static RegSet_T REG_consExps(ROW(RegSet_T) pRegRow)
{ RegSet_T pRes = (RegSet_T)NULL, pRegSet;
long lCnt = OT_CNT(pRegRow), lI;
if( lCnt == 0 ) pRes = RegSet_Empty();
else
for( lI=0; lI < lCnt; ++lI )
{
pRegSet = OT_GET(RegSet_T,pRegRow,lI);
if( lI > 0 && pRes == (RegSet_T)NULL )
RegSet_Free(pRegSet);
else pRes = REG_concat(pRes,pRegSet);
}
OT_CLEAR(pRegRow);
return pRes;
}
static void REG_getLimits(c_string szToken, int* pnMin, int* pnMax)
{ int nI;
*pnMax = *pnMin = atoi(szToken);
for( nI=0; szToken[nI] != '\0'; ++nI )
if( szToken[nI] == ',' ) break;
if( szToken[nI] != '\0' )
for( ; szToken[nI] != '\0'; ++nI )
if( isdigit(szToken[nI]) ) break;
if( szToken[nI] != '\0' )
*pnMax = atoi(&szToken[nI]);
}
static RegSet_T REG_Exp(Scn_Stream pStream, int cEnd)
{ ROW(RegSet_T) pRegRow = OT_CREATE_ADT(RegSet_T);
RegSet_T (*pBRegFun)(RegSet_T pL, RegSet_T pR) = NULL;
RegSet_T (*pURegFun)(RegSet_T pRegSet) = NULL;
RegSet_T pRes = (RegSet_T)NULL, pRegSet1, pRegSet2;
long lRng = 0;
int cSym = 0;
for(Stream_next(pStream); Stream_ctid(pStream) > 0; Stream_next(pStream))
{ c_string szTxt = symbolToString(Stream_csym(pStream));
/*
if( !Stream_unicode(pStream) ) printf("TXT=%s\n",szTxt);
else GS_fprint_utf8(STDOUT,szTxt,C_True);
*/
if (Stream_ctid(pStream) == 4)
{ int nMin = -1, nMax = -1;
if( OT_CNT(pRegRow) == 0 ) break;
REG_getLimits(szTxt,&nMin,&nMax);
pRegSet1 = OT_TOP(RegSet_T,pRegRow); OT_POP(pRegRow);
pRegSet1 = REG_plus_range(pRegSet1,nMin,nMax);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
}
else
if (Stream_ctid(pStream) == 1)
{
if( szTxt[0] == '+' || szTxt[0] == '*' || szTxt[0] == '?' )
{
if( OT_CNT(pRegRow) == 0 ) break;
pRegSet1 = OT_TOP(RegSet_T,pRegRow); OT_POP(pRegRow);
pRegSet1 = szTxt[0]=='+'
? REG_plus(pRegSet1)
: szTxt[0]=='*'
? REG_plus(pRegSet1) : REG_option(pRegSet1);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
}
else
if( szTxt[0] == '.' && szTxt[1] == '.' )
{
if( OT_CNT(pRegRow) == 0 ) break;
lRng = OT_CNT(pRegRow)+1;
}
else
if( szTxt[0] == '|' || szTxt[0] == '-' )
{
if( OT_CNT(pRegRow) == 0 ) break;
pBRegFun = szTxt[0] == '|' ? REG_union : REG_diff;
pRegSet1 = REG_consExps(pRegRow);
if( pRegSet1 == (RegSet_T)NULL ) break;
pRegSet2 = REG_Exp(pStream,cEnd);
if( pRegSet2 == (RegSet_T)NULL ) break;
pRegSet1 = (*pBRegFun)(pRegSet1,pRegSet2);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
if( cEnd >= 0 ) { cSym = cEnd; break; }
}
else
if( szTxt[0] == '.' )
{
pRegSet1 = REG_sigma();
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
}
else
{
if( szTxt[0] == '(' ) pURegFun = REG_self;
else
if( szTxt[0] == '{' ) pURegFun = REG_star;
else
if( szTxt[0] == '[' ) pURegFun = REG_option;
else
if( szTxt[0] == ')' || szTxt[0] == '}' || szTxt[0] == ']' )
{
cSym = (int)(szTxt[0]==')'?'(':szTxt[0]=='}'?'{':'['); break;
}
else C_BUG;
pRegSet1 = REG_Exp(pStream, (int)szTxt[0]);
if( pRegSet1 == (RegSet_T)NULL ) break;
pRegSet1 = (*pURegFun)(pRegSet1);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
}
}
else
{
pRegSet1 = ( Stream_ctid(pStream) == 2 )
? REG_Cset(szTxt) : REG_String(szTxt);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
}
if( lRng == OT_CNT(pRegRow) )
{
pRegSet1 = OT_TOP(RegSet_T,pRegRow); OT_POP(pRegRow);
pRegSet2 = OT_TOP(RegSet_T,pRegRow); OT_POP(pRegRow);
pRegSet1 = REG_range(pRegSet1,pRegSet2);
if( pRegSet1 == (RegSet_T)NULL ) break;
OT_PUSH(pRegSet1,pRegRow);
lRng = 0;
}
}
if( Stream_ctid(pStream) == -1 ) cSym = -1;
/*
printf("RNG=%ld,SYM=%ld,END=%ld\n",lRng,cSym,cEnd);
*/
if( lRng > 0 || cSym != cEnd ) REG_freeExps(pRegRow);
else pRes = REG_consExps(pRegRow);
OT_DEL_T(pRegRow);
return pRes;
}
static Scn_T REG_Scanner
(
Scn_T pRScn, c_string szRegExp, long lLen, c_string szCharSet, c_byte ucFlags
)
{ Scn_Stream pStream = (Scn_Stream)NULL;
RegSet_T pRegSet = (RegSet_T)NULL;
Scn_T pVScn = (Scn_T)NULL;
if( STR_EMPTY(szCharSet) )
{
if( lLen < 0 )
pStream = Stream_string(pRScn, szRegExp);
else
{ c_string szTmp = SubStrCopy(szRegExp,lLen);
pStream = Stream_string(pRScn, szTmp);
FreeMem(szTmp);
}
}
else
{ Scn_Stream_Itr pItr = (Scn_Stream_Itr)NULL;
GStream_T pGS = (GStream_T)NULL;
pGS = GS_stream_string_new(szRegExp,lLen<0?strlen(szRegExp)+1:lLen,szCharSet);
if( pGS != (GStream_T)NULL )
pItr = Stream_Itr_new
(
GS_stream_get_wcrc, GS_fun_destruct(pGS), GS_ucs4_to_utf8,
GS_fun_seek(pGS), pGS, "Character set ' Literal ... ' String " Literal ... " Any character . Character range
Expression .. Expression
( single character expressions )Subexpression ( Expression ) Option [ Expression ] Expression ? Iteration ( 0.. ) { Expression } Expression * Iteration ( 1.. ) Expression + Iteration ( n ) Expression Number Iteration ( n..m ) Expression Number, Number Union Expression | Expression Difference Expression - Expression Concatenation Expression Expression
It is possible to define multiple startsymbols and comment tokens.
This creation process is not reentrant. You must synchronize the access
to the function within threads.
*/
/*!!
The following rules define the abstract syntax. On this base the nonterminal
classes are created.
A) well-formed productions:
1. let X :nil#* : <0 members>
2. let X :cons#*: Y Z <2 members: Y = member && Z = nonterminal>
3. let X :ign#+ : Y <1 nonterminal>
4. let X :name : X1 .. Xn