/** * \file * header file of ldf_parser */ #ifndef LDF_PARSER_H #define LDF_PARSER_H #include #include "generic.h" #include "buffer.h" extern struct LDFstruct; extern struct ProtoInterface; /*=================================================================== ======= TOKENIZER =================================================== ====================================================================*/ /** \defgroup tokenizer Tokenizer * \ingroup ldf_parser */ /** \{ */ /** Different token types detected by Tokenizer. */ enum TokenType { TOKENTYPE_UNKNOWN =0x00, TOKENTYPE_IDENT =0x01, TOKENTYPE_STRING =0x02, TOKENTYPE_NUMBER =0x04, TOKENTYPE_HEXNUMBER =0x08, TOKENTYPE_FLOAT =0x10, TOKENTYPE_COMMENT =0x20, }; /** Variables for Tokenizer. */ struct Tokenizer { BufferVector buffer; /**< Buffer which hold read characters from file. */ size_t nettoTokenSize; /**< Size of current token if any. */ size_t nettoTokenOffset; /**< Offset to the beginning of the reference data. */ enum TokenType tokenType; /**< Possible types of current token. */ size_t actSourceLine; /**< Source line in file. */ size_t actSourceColumn; /**< Source column in file. */ size_t tokenSourceLine; /**< Source line in file of current token. */ size_t tokenSourceColumn; /**< Source column in file of current token. */ size_t nextTokenOffset; /**< Offset to the beginning of next token in \ref Tokenizer::buffer. */ }; /** \} */ /*=================================================================== ======= GRAMMAR ===================================================== ====================================================================*/ /** \defgroup grammar Grammar * \ingroup ldf_parser */ /** \{ */ /** Stores reason of grammatically failure. */ enum GrammarState { GRAMMAR_OK, GRAMMAR_ERROR_CONTEXT, GRAMMAR_ERROR_VERSIONSTRING, GRAMMAR_SKIP_BLOCK_ERROR, GRAMMAR_SKIP_BLOCK_SILENT, }; /** Grammatically contexts. */ enum GrammarContext { GRAMMARCONTEXT_GLOBAL, GRAMMARCONTEXT_GLOBAL_LIN_DESCRIPTION_FILE, GRAMMARCONTEXT_GLOBAL_LIN_PROTOCOL_VERSION, GRAMMARCONTEXT_GLOBAL_LIN_LANGUAGE_VERSION, GRAMMARCONTEXT_GLOBAL_LIN_SPEED, GRAMMARCONTEXT_GLOBAL_CHANNEL_NAME, GRAMMARCONTEXT_GLOBAL_NODES, GRAMMARCONTEXT_GLOBAL_NODES_ATTRIBUTES, GRAMMARCONTEXT_GLOBAL_SIGNALS, GRAMMARCONTEXT_GLOBAL_DIAGNOSTIC_SIGNALS, GRAMMARCONTEXT_GLOBAL_FRAMES, GRAMMARCONTEXT_GLOBAL_DIAGNOSTIC_FRAMES, GRAMMARCONTEXT_GLOBAL_SPORADIC_FRAMES, GRAMMARCONTEXT_GLOBAL_EVENTTRIGGERED_FRAMES, GRAMMARCONTEXT_GLOBAL_SIGNAL_ENCODING_TYPES, GRAMMARCONTEXT_GLOBAL_SIGNAL_REPRESENTATION, GRAMMARCONTEXT_GLOBAL_COMPOSITE_NODES, GRAMMARCONTEXT_GLOBAL_SCHEDULE_TABLES, /*this and following (global) contexts in this part are skipped silently in LDFParser_grammarCheck*/ GRAMMARCONTEXT_GLOBAL_SIGNAL_GROUPS, GRAMMARCONTEXT_GLOBAL_DYNAMIC_FRAMES, GRAMMARCONTEXT_NODES_MASTERDEF, GRAMMARCONTEXT_NODES_SLAVESDEF, GRAMMARCONTEXT_NODEATTRIBUTEDEF, GRAMMARCONTEXT_NODEATTRIBUTEDEF_LIN_PROTOCOL, GRAMMARCONTEXT_NODEATTRIBUTEDEF_CONFIGURED_NAD, GRAMMARCONTEXT_NODEATTRIBUTEDEF_INITIAL_NAD, GRAMMARCONTEXT_NODEATTRIBUTEDEF_PRODUCT_ID, GRAMMARCONTEXT_NODEATTRIBUTEDEF_RESPONSE_ERROR, GRAMMARCONTEXT_NODEATTRIBUTEDEF_CONFIGURABLE_FRAMES, GRAMMARCONTEXT_NODEATTRIBUTEDEF_FAULT_STATE_SIGNALS, GRAMMARCONTEXT_NODEATTRIBUTEDEF_P2_MIN, GRAMMARCONTEXT_NODEATTRIBUTEDEF_ST_MIN, GRAMMARCONTEXT_NODEATTRIBUTEDEF_N_AS_TIMEOUT, GRAMMARCONTEXT_NODEATTRIBUTEDEF_N_CR_TIMEOUT, GRAMMARCONTEXT_NODEATTRIBUTEDEF_CONFIGURABLEFRAMESDEF_v20, GRAMMARCONTEXT_NODEATTRIBUTEDEF_CONFIGURABLEFRAMESDEF_v21, GRAMMARCONTEXT_SIGNALDEF, GRAMMARCONTEXT_SIGNALDEF_INITVALUES, GRAMMARCONTEXT_DIAGNOSTICSIGNALDEF, GRAMMARCONTEXT_FRAMEDEF, GRAMMARCONTEXT_FRAMEDEF_INCLUDEDSIGNALS, GRAMMARCONTEXT_DIAGNOSTICFRAMEDEF, GRAMMARCONTEXT_DIAGNOSTICFRAMEDEF_INCLUDEDSIGNALS, GRAMMARCONTEXT_SPORADICFRAMEDEF, GRAMMARCONTEXT_EVENTTRIGGEREDFRAMEDEF, GRAMMARCONTEXT_SIGNALENCODINGTYPE_DEF, GRAMMARCONTEXT_SIGNALENCODINGTYPEDEF_LOGICAL_VALUE, GRAMMARCONTEXT_SIGNALENCODINGTYPEDEF_PHYSICAL_VALUE, GRAMMARCONTEXT_SIGNALENCODINGTYPEDEF_BCD_VALUE, GRAMMARCONTEXT_SIGNALENCODINGTYPEDEF_ASCII_VALUE, GRAMMARCONTEXT_SIGNALREPRESENTATION_DEF, GRAMMARCONTEXT_COMPOSITENODE_CONFIGURATION, GRAMMARCONTEXT_COMPOSITENODE_DEF, }; /** Represent grammatically tokens. Used for e.g. for Grammar::expectedGrammarToken. */ enum GrammarToken { GRAMMARTOKEN_NOTOKEN =0, GRAMMARTOKEN_OPENBRACE =1<<0x00, GRAMMARTOKEN_CLOSEBRACE =1<<0x01, GRAMMARTOKEN_COLON =1<<0x02, GRAMMARTOKEN_SEMICOLON =1<<0x03, GRAMMARTOKEN_COMMA =1<<0x04, GRAMMARTOKEN_EQUALSIGN =1<<0x05, GRAMMARTOKEN_KBPS =1<<0x06, GRAMMARTOKEN_MS =1<<0x07, GRAMMARTOKEN_IDENT =1<<0x08, GRAMMARTOKEN_STRING =1<<0x09, GRAMMARTOKEN_NUMBER =1<<0x0A, GRAMMARTOKEN_HEXNUMBER =1<<0x0B, GRAMMARTOKEN_FLOAT =1<<0x0C, }; /** Variables for Grammar. */ struct Grammar { enum GrammarState grammarState; /**< Stores reason why LDFParser_grammarCheck() has failed. */ enum GrammarContext nextGrammarContext; /**< This context is valid only if Grammar::expectedGrammarToken will be found next. */ enum GrammarToken expectedGrammarToken; /**< The next token in current context has to be this. If not, their is a syntax error. Context of grammatically token is determined with Grammar::nextGrammarContext. */ int expectedGrammarSpecialValue; /**< Number which can be used in conjunction with Grammar::expectedGrammarToken. */ void *ldfContextp[2]; /**< This pointers (within the array) can point to some special structure within LDFstruct and is used in conjunction with Grammar::nextGrammarContext. */ enum GrammarToken weakExpectedGrammarToken; /**< The next token in current context can be this. If it is, their will be done something. */ enum GrammarToken actGrammarToken; /**< Current grammatically token of current tokenizer token. Will be set after calling LDFParser_grammarCheck(). */ unsigned int nOpenBraces; /**< Hold the current count of opening braces. Used to set the Grammar::weakExpectedGrammarToken to GrammarToken::GRAMMARTOKEN_NOTOKEN. */ unsigned char linDescriptionFilef; /**< Will be set if "Lin_descriptionfile;" occures. */ unsigned char compositeNodeConfigurationf; /**< Will be set if a correct composite configuration was found.*/ StackInt grammarContext; /**< Stack which holds the different accepted grammar contexts. */ }; /** \} */ /*=================================================================== ======= LDF_PARSER ================================================== ====================================================================*/ /** \defgroup ldf_parser LDF_Parser*/ /** \{ */ #define LDFPARSER_VERSION_STRING "0.1 (17. Sep 2007)" /** Different states of the ldf_parser. */ enum LDFParser_state { LDFPARSER_OK=0, LDFPARSER_DISABLED, LDFPARSER_ERROR_WRONGINPUTFILE, LDFPARSER_ERROR_FILEOPEN, LDFPARSER_ERROR_FILEREAD, LDFPARSER_ERROR_EOF, LDFPARSER_ERROR_EOF_INSIDE_TOKEN, LDFPARSER_ERROR_BUFFER_TOKENIZER, LDFPARSER_ERROR_STACK_GRAMMARCONTEXT, LDFPARSER_ERROR_LDF, }; /** Variables for ldf_parser. */ typedef struct LDFParser { struct ProtoInterface *protoInterfacep; /**< Pointer to object which handles error messages. */ enum LDFParser_state parserState; /**< Current state of parser. */ char filename[FILENAME_MAX + 1]; /**< Filename of file which is parsed. */ FILE *filehandle; /**< Handle to file which is parsed. */ struct LDFstruct *actLDFp; /**< Current LDFstruct where LDFParser_parse() will copy data to. */\ struct Grammar grammar; /**< Variables of Grammar. */ struct Tokenizer tokenizer; /**< Variables of Tokenizer. */ } LDFParser; int LDFParser_init(LDFParser *parserp, struct ProtoInterface *protoInterfacep, const char *filename, size_t buffer_initSize); void LDFParser_destroy(LDFParser *parserp); int LDFParser_parse(LDFParser *parserp, struct LDFstruct *ldfp); /**< Start parsing. */ void LDFParser_message_printState(LDFParser *parserp); /**< Prints message of current state to LDFParser::protoInterfacep. */ int LDFParser_DEBUG_dumpBuffer(LDFParser *parserp, FILE *outStream); int LDFParser_DEBUG_dumpTokenzierTokens(LDFParser *parserp); int LDFParser_DEBUG_dumpGrammarTokens(LDFParser *parserp); /** \} */ #endif