From f9fc35785b53aa097a09ab1b865d33497ee1802e Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 10 Jul 2012 13:01:48 +1000 Subject: Move antlr. Add `make test` to Makefile. --- antlr/libantlr3c-3.4/include/antlr3.h | 56 ++ .../libantlr3c-3.4/include/antlr3baserecognizer.h | 371 ++++++++++++ antlr/libantlr3c-3.4/include/antlr3basetree.h | 143 +++++ .../libantlr3c-3.4/include/antlr3basetreeadaptor.h | 152 +++++ antlr/libantlr3c-3.4/include/antlr3bitset.h | 119 ++++ antlr/libantlr3c-3.4/include/antlr3collections.h | 513 +++++++++++++++++ antlr/libantlr3c-3.4/include/antlr3commontoken.h | 367 ++++++++++++ antlr/libantlr3c-3.4/include/antlr3commontree.h | 167 ++++++ .../include/antlr3commontreeadaptor.h | 70 +++ .../include/antlr3commontreenodestream.h | 336 +++++++++++ antlr/libantlr3c-3.4/include/antlr3convertutf.h | 176 ++++++ antlr/libantlr3c-3.4/include/antlr3cyclicdfa.h | 97 ++++ .../include/antlr3debugeventlistener.h | 398 +++++++++++++ antlr/libantlr3c-3.4/include/antlr3defs.h | 632 +++++++++++++++++++++ antlr/libantlr3c-3.4/include/antlr3encodings.h | 38 ++ antlr/libantlr3c-3.4/include/antlr3errors.h | 53 ++ antlr/libantlr3c-3.4/include/antlr3exception.h | 218 +++++++ antlr/libantlr3c-3.4/include/antlr3filestream.h | 50 ++ antlr/libantlr3c-3.4/include/antlr3input.h | 281 +++++++++ antlr/libantlr3c-3.4/include/antlr3interfaces.h | 239 ++++++++ antlr/libantlr3c-3.4/include/antlr3intstream.h | 205 +++++++ antlr/libantlr3c-3.4/include/antlr3lexer.h | 193 +++++++ antlr/libantlr3c-3.4/include/antlr3memory.h | 36 ++ antlr/libantlr3c-3.4/include/antlr3parser.h | 93 +++ antlr/libantlr3c-3.4/include/antlr3parsetree.h | 85 +++ .../include/antlr3recognizersharedstate.h | 218 +++++++ .../libantlr3c-3.4/include/antlr3rewritestreams.h | 180 ++++++ antlr/libantlr3c-3.4/include/antlr3string.h | 272 +++++++++ antlr/libantlr3c-3.4/include/antlr3tokenstream.h | 303 ++++++++++ antlr/libantlr3c-3.4/include/antlr3treeparser.h | 81 +++ 30 files changed, 6142 insertions(+) create mode 100644 antlr/libantlr3c-3.4/include/antlr3.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3baserecognizer.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3basetree.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3basetreeadaptor.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3bitset.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3collections.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3commontoken.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3commontree.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3commontreeadaptor.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3commontreenodestream.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3convertutf.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3cyclicdfa.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3debugeventlistener.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3defs.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3encodings.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3errors.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3exception.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3filestream.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3input.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3interfaces.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3intstream.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3lexer.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3memory.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3parser.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3parsetree.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3recognizersharedstate.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3rewritestreams.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3string.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3tokenstream.h create mode 100644 antlr/libantlr3c-3.4/include/antlr3treeparser.h (limited to 'antlr/libantlr3c-3.4/include') diff --git a/antlr/libantlr3c-3.4/include/antlr3.h b/antlr/libantlr3c-3.4/include/antlr3.h new file mode 100644 index 0000000..2ead975 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3.h @@ -0,0 +1,56 @@ +#ifndef _ANTLR3_H +#define _ANTLR3_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3baserecognizer.h b/antlr/libantlr3c-3.4/include/antlr3baserecognizer.h new file mode 100644 index 0000000..0a269d4 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3baserecognizer.h @@ -0,0 +1,371 @@ +/** \file + * Defines the basic structure to support recognizing by either a lexer, + * parser, or tree parser. + * \addtogroup ANTLR3_BASE_RECOGNIZER + * @{ + */ +#ifndef _ANTLR3_BASERECOGNIZER_H +#define _ANTLR3_BASERECOGNIZER_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include +#include +#include +#include + +/** Type indicator for a lexer recognizer + */ +#define ANTLR3_TYPE_LEXER 0x0001 + +/** Type indicator for a parser recognizer + */ +#define ANTLR3_TYPE_PARSER 0x0002 + +/** Type indicator for a tree parser recognizer + */ +#define ANTLR3_TYPE_TREE_PARSER 0x0004 + +#ifdef __cplusplus +extern "C" { +#endif + +/** \brief Base tracking context structure for all types of + * recognizers. + */ +typedef struct ANTLR3_BASE_RECOGNIZER_struct +{ + /// Whatever super structure is providing this interface needs a pointer to itself + /// so that this can be passed back to it whenever the api functions + /// are called back from here. + /// + void * super; + + /// Indicates the type of recognizer that we are an instance of. + /// The programmer may set this to anything of course, but the default + /// implementations of the interface only really understand the built in + /// types, so new error handlers etc would probably be required to as well. + /// + /// Valid types are: + /// + /// - #ANTLR3_TYPE_LEXER + /// - #ANTLR3_TYPE_PARSER + /// - #ANTLR3_TYPE_TREE_PARSER + /// + ANTLR3_UINT32 type; + + /// A pointer to the shared recognizer state, such that multiple + /// recognizers can use the same inputs streams and so on (in + /// the case of grammar inheritance for instance. + /// + pANTLR3_RECOGNIZER_SHARED_STATE state; + + /// If set to something other than NULL, then this structure is + /// points to an instance of the debugger interface. In general, the + /// debugger is only referenced internally in recovery/error operations + /// so that it does not cause overhead by having to check this pointer + /// in every function/method + /// + pANTLR3_DEBUG_EVENT_LISTENER debugger; + + + /// Pointer to a function that matches the current input symbol + /// against the supplied type. the function causes an error if a + /// match is not found and the default implementation will also + /// attempt to perform one token insertion or deletion if that is + /// possible with the input stream. You can override the default + /// implementation by installing a pointer to your own function + /// in this interface after the recognizer has initialized. This can + /// perform different recovery options or not recover at all and so on. + /// To ignore recovery altogether, see the comments in the default + /// implementation of this function in antlr3baserecognizer.c + /// + /// Note that errors are signalled by setting the error flag below + /// and creating a new exception structure and installing it in the + /// exception pointer below (you can chain these if you like and handle them + /// in some customized way). + /// + void * (*match) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_UINT32 ttype, pANTLR3_BITSET_LIST follow); + + /// Pointer to a function that matches the next token/char in the input stream + /// regardless of what it actually is. + /// + void (*matchAny) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /// Pointer to a function that decides if the token ahead of the current one is the + /// one we were loking for, in which case the curernt one is very likely extraneous + /// and can be reported that way. + /// + ANTLR3_BOOLEAN + (*mismatchIsUnwantedToken) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, pANTLR3_INT_STREAM input, ANTLR3_UINT32 ttype); + + /// Pointer to a function that decides if the current token is one that can logically + /// follow the one we were looking for, in which case the one we were looking for is + /// probably missing from the input. + /// + ANTLR3_BOOLEAN + (*mismatchIsMissingToken) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, pANTLR3_INT_STREAM input, pANTLR3_BITSET_LIST follow); + + /** Pointer to a function that works out what to do when a token mismatch + * occurs, so that Tree parsers can behave differently to other recognizers. + */ + void (*mismatch) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_UINT32 ttype, pANTLR3_BITSET_LIST follow); + + /** Pointer to a function to call to report a recognition problem. You may override + * this function with your own function, but refer to the standard implementation + * in antlr3baserecognizer.c for guidance. The function should recognize whether + * error recovery is in force, so that it does not print out more than one error messages + * for the same error. From the java comments in BaseRecognizer.java: + * + * This method sets errorRecovery to indicate the parser is recovering + * not parsing. Once in recovery mode, no errors are generated. + * To get out of recovery mode, the parser must successfully match + * a token (after a resync). So it will go: + * + * 1. error occurs + * 2. enter recovery mode, report error + * 3. consume until token found in resynch set + * 4. try to resume parsing + * 5. next match() will reset errorRecovery mode + */ + void (*reportError) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that is called to display a recognition error message. You may + * override this function independently of (*reportError)() above as that function calls + * this one to do the actual exception printing. + */ + void (*displayRecognitionError) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, pANTLR3_UINT8 * tokenNames); + + /// Get number of recognition errors (lexer, parser, tree parser). Each + /// recognizer tracks its own number. So parser and lexer each have + /// separate count. Does not count the spurious errors found between + /// an error and next valid token match + /// + /// \see reportError() + /// + ANTLR3_UINT32 + (*getNumberOfSyntaxErrors) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that recovers from an error found in the input stream. + * Generally, this will be a #ANTLR3_EXCEPTION_NOVIABLE_ALT but it could also + * be from a mismatched token that the (*match)() could not recover from. + */ + void (*recover) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that is a hook to listen to token consumption during error recovery. + * This is mainly used by the debug parser to send events to the listener. + */ + void (*beginResync) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that is a hook to listen to token consumption during error recovery. + * This is mainly used by the debug parser to send events to the listener. + */ + void (*endResync) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that is a hook to listen to token consumption during error recovery. + * This is mainly used by the debug parser to send events to the listener. + */ + void (*beginBacktrack) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, ANTLR3_UINT32 level); + + /** Pointer to a function that is a hook to listen to token consumption during error recovery. + * This is mainly used by the debug parser to send events to the listener. + */ + void (*endBacktrack) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, ANTLR3_UINT32 level, ANTLR3_BOOLEAN successful); + + /** Pointer to a function to computer the error recovery set for the current rule. + * \see antlr3ComputeErrorRecoverySet() for details. + */ + pANTLR3_BITSET (*computeErrorRecoverySet) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that computes the context-sensitive FOLLOW set for the + * current rule. + * \see antlr3ComputeCSRuleFollow() for details. + */ + pANTLR3_BITSET (*computeCSRuleFollow) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function to combine follow bitsets. + * \see antlr3CombineFollows() for details. + */ + pANTLR3_BITSET (*combineFollows) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_BOOLEAN exact); + + /** Pointer to a function that recovers from a mismatched token in the input stream. + * \see antlr3RecoverMismatch() for details. + */ + void * (*recoverFromMismatchedToken) + (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_UINT32 ttype, + pANTLR3_BITSET_LIST follow); + + /** Pointer to a function that recovers from a mismatched set in the token stream, in a similar manner + * to (*recoverFromMismatchedToken) + */ + void * (*recoverFromMismatchedSet) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_BITSET_LIST follow); + + /** Pointer to common routine to handle single token insertion for recovery functions. + */ + ANTLR3_BOOLEAN (*recoverFromMismatchedElement) + (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_BITSET_LIST follow); + + /** Pointer to function that consumes input until the next token matches + * the given token. + */ + void (*consumeUntil) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_UINT32 tokenType); + + /** Pointer to function that consumes input until the next token matches + * one in the given set. + */ + void (*consumeUntilSet) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_BITSET set); + + /** Pointer to function that returns an ANTLR3_LIST of the strings that identify + * the rules in the parser that got you to this point. Can be overridden by installing your + * own function set. + * + * \todo Document how to override invocation stack functions. + */ + pANTLR3_STACK (*getRuleInvocationStack) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + pANTLR3_STACK (*getRuleInvocationStackNamed) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_UINT8 name); + + /** Pointer to a function that converts an ANLR3_LIST of tokens to an ANTLR3_LIST of + * string token names. As this is mostly used in string template processing it may not be useful + * in the C runtime. + */ + pANTLR3_HASH_TABLE (*toStrings) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_HASH_TABLE); + + /** Pointer to a function to return whether the rule has parsed input starting at the supplied + * start index before. If the rule has not parsed input starting from the supplied start index, + * then it will return ANTLR3_MEMO_RULE_UNKNOWN. If it has parsed from the suppled start point + * then it will return the point where it last stopped parsing after that start point. + */ + ANTLR3_MARKER (*getRuleMemoization) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_INTKEY ruleIndex, + ANTLR3_MARKER ruleParseStart); + + /** Pointer to function that determines whether the rule has parsed input at the current index + * in the input stream + */ + ANTLR3_BOOLEAN (*alreadyParsedRule) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_MARKER ruleIndex); + + /** Pointer to function that records whether the rule has parsed the input at a + * current position successfully or not. + */ + void (*memoize) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + ANTLR3_MARKER ruleIndex, + ANTLR3_MARKER ruleParseStart); + + /// Pointer to a function that returns the current input symbol. + /// The is placed into any label for the associated token ref; e.g., x=ID. Token + /// and tree parsers need to return different objects. Rather than test + /// for input stream type or change the IntStream interface, I use + /// a simple method to ask the recognizer to tell me what the current + /// input symbol is. + /// + /// This is ignored for lexers and the lexer implementation of this + /// function should return NULL. + /// + void * (*getCurrentInputSymbol) ( struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_INT_STREAM istream); + + /// Conjure up a missing token during error recovery. + /// + /// The recognizer attempts to recover from single missing + /// symbols. But, actions might refer to that missing symbol. + /// For example, x=ID {f($x);}. The action clearly assumes + /// that there has been an identifier matched previously and that + /// $x points at that token. If that token is missing, but + /// the next token in the stream is what we want we assume that + /// this token is missing and we keep going. Because we + /// have to return some token to replace the missing token, + /// we have to conjure one up. This method gives the user control + /// over the tokens returned for missing tokens. Mostly, + /// you will want to create something special for identifier + /// tokens. For literals such as '{' and ',', the default + /// action in the parser or tree parser works. It simply creates + /// a CommonToken of the appropriate type. The text will be the token. + /// If you change what tokens must be created by the lexer, + /// override this method to create the appropriate tokens. + /// + void * (*getMissingSymbol) ( struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, + pANTLR3_INT_STREAM istream, + pANTLR3_EXCEPTION e, + ANTLR3_UINT32 expectedTokenType, + pANTLR3_BITSET_LIST follow); + + /** Pointer to a function that returns whether the supplied grammar function + * will parse the current input stream or not. This is the way that syntactic + * predicates are evaluated. Unlike java, C is perfectly happy to invoke code + * via a pointer to a function (hence that's what all the ANTLR3 C interfaces + * do. + */ + ANTLR3_BOOLEAN (*synpred) ( struct ANTLR3_BASE_RECOGNIZER_struct * recognizer, void * ctx, + void (*predicate)(void * ctx)); + + /** Pointer to a function that can construct a generic exception structure + * with such information as the input stream can provide. + */ + void (*exConstruct) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Reset the recognizer + */ + void (*reset) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + + /** Pointer to a function that knows how to free the resources of a base recognizer. + */ + void (*free) (struct ANTLR3_BASE_RECOGNIZER_struct * recognizer); + +} + ANTLR3_BASE_RECOGNIZER; + +#ifdef __cplusplus +} +#endif + +#include +#include +#include + +/// @} +/// + +#endif /* _ANTLR3_BASERECOGNIZER_H */ + diff --git a/antlr/libantlr3c-3.4/include/antlr3basetree.h b/antlr/libantlr3c-3.4/include/antlr3basetree.h new file mode 100644 index 0000000..023c4c2 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3basetree.h @@ -0,0 +1,143 @@ +/// \file +/// Definition of the ANTLR3 base tree. +/// + +#ifndef _ANTLR3_BASE_TREE_H +#define _ANTLR3_BASE_TREE_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// A generic tree implementation with no payload. You must subclass to +/// actually have any user data. ANTLR v3 uses a list of children approach +/// instead of the child-sibling approach in v2. A flat tree (a list) is +/// an empty node whose children represent the list. An empty (as in it does not +/// have payload itself), but non-null node is called "nil". +/// +typedef struct ANTLR3_BASE_TREE_struct +{ + + /// Implementers of this interface sometimes require a pointer to their selves. + /// + void * super; + + /// Generic void pointer allows the grammar programmer to attach any structure they + /// like to a tree node, in many cases saving the need to create their own tree + /// and tree adaptors. ANTLR does not use this pointer, but will copy it for you and so on. + /// + void * u; + + /// The list of all the children that belong to this node. They are not part of the node + /// as they belong to the common tree node that implements this. + /// + pANTLR3_VECTOR children; + + /// This is used to store the current child index position while descending + /// and ascending trees as the tree walk progresses. + /// + ANTLR3_MARKER savedIndex; + + /// A string factory to produce strings for toString etc + /// + pANTLR3_STRING_FACTORY strFactory; + + /// A pointer to a function that returns the common token pointer + /// for the payload in the supplied tree. + /// + pANTLR3_COMMON_TOKEN (*getToken) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*addChild) (struct ANTLR3_BASE_TREE_struct * tree, void * child); + + void (*addChildren) (struct ANTLR3_BASE_TREE_struct * tree, pANTLR3_LIST kids); + + void (*createChildrenList) (struct ANTLR3_BASE_TREE_struct * tree); + + void * (*deleteChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i); + + void (*replaceChildren) (struct ANTLR3_BASE_TREE_struct * parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, struct ANTLR3_BASE_TREE_struct * t); + + void * (*dupNode) (struct ANTLR3_BASE_TREE_struct * dupNode); + + void * (*dupTree) (struct ANTLR3_BASE_TREE_struct * tree); + + ANTLR3_UINT32 (*getCharPositionInLine) (struct ANTLR3_BASE_TREE_struct * tree); + + void * (*getChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i); + + void (*setChildIndex) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_INT32 ); + + ANTLR3_INT32 (*getChildIndex) (struct ANTLR3_BASE_TREE_struct * tree ); + + ANTLR3_UINT32 (*getChildCount) (struct ANTLR3_BASE_TREE_struct * tree); + + struct ANTLR3_BASE_TREE_struct * (*getParent) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*setParent) (struct ANTLR3_BASE_TREE_struct * tree, struct ANTLR3_BASE_TREE_struct * parent); + + ANTLR3_UINT32 (*getType) (struct ANTLR3_BASE_TREE_struct * tree); + + void * (*getFirstChildWithType) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 type); + + ANTLR3_UINT32 (*getLine) (struct ANTLR3_BASE_TREE_struct * tree); + + pANTLR3_STRING (*getText) (struct ANTLR3_BASE_TREE_struct * tree); + + ANTLR3_BOOLEAN (*isNilNode) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*setChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i, void * child); + + pANTLR3_STRING (*toStringTree) (struct ANTLR3_BASE_TREE_struct * tree); + + pANTLR3_STRING (*toString) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*freshenPACIndexesAll) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*freshenPACIndexes) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 offset); + + void (*reuse) (struct ANTLR3_BASE_TREE_struct * tree); + + void (*free) (struct ANTLR3_BASE_TREE_struct * tree); + +} + ANTLR3_BASE_TREE; + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3basetreeadaptor.h b/antlr/libantlr3c-3.4/include/antlr3basetreeadaptor.h new file mode 100644 index 0000000..bf9a72a --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3basetreeadaptor.h @@ -0,0 +1,152 @@ +/** \file + * Definition of the ANTLR3 base tree adaptor. + */ + +#ifndef _ANTLR3_BASE_TREE_ADAPTOR_H +#define _ANTLR3_BASE_TREE_ADAPTOR_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_BASE_TREE_ADAPTOR_struct +{ + /** Pointer to any enclosing structure/interface that + * contains this structure. + */ + void * super; + + /** We need a string factory for creating imaginary tokens, we take this + * from the stream we are supplied to walk. + */ + pANTLR3_STRING_FACTORY strFactory; + + /* And we also need a token factory for creating imaginary tokens + * this is also taken from the input source. + */ + pANTLR3_TOKEN_FACTORY tokenFactory; + + /// If set to something other than NULL, then this structure is + /// points to an instance of the debugger interface. In general, the + /// debugger is only referenced internally in recovery/error operations + /// so that it does not cause overhead by having to check this pointer + /// in every function/method + /// + pANTLR3_DEBUG_EVENT_LISTENER debugger; + + void * (*nilNode) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor); + + + void * (*dupTree) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * tree); + void * (*dupTreeTT) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, void * tree); + + void (*addChild) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, void * child); + void (*addChildToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, pANTLR3_COMMON_TOKEN child); + void (*setParent) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * child, void * parent); + void * (*getParent) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * child); + + void * (*errorNode) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_TOKEN_STREAM tnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e); + ANTLR3_BOOLEAN (*isNilNode) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + void * (*becomeRoot) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * newRoot, void * oldRoot); + + void * (*rulePostProcessing) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * root); + + void * (*becomeRootToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * newRoot, void * oldRoot); + + void * (*create) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_COMMON_TOKEN payload); + void * (*createTypeToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_COMMON_TOKEN fromToken); + void * (*createTypeTokenText) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_COMMON_TOKEN fromToken, pANTLR3_UINT8 text); + void * (*createTypeText) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text); + + void * (*dupNode) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * treeNode); + + ANTLR3_UINT32 (*getType) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + void (*setType) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 type); + + pANTLR3_STRING (*getText) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + void (*setText) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_STRING t); + void (*setText8) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_UINT8 t); + + void * (*getChild) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i); + void (*setChild) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i, void * child); + void (*deleteChild) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i); + void (*setChildIndex) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i); + ANTLR3_INT32 (*getChildIndex) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + ANTLR3_UINT32 (*getChildCount) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void *); + + ANTLR3_UINT32 (*getUniqueID) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void *); + + pANTLR3_COMMON_TOKEN (*createToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text); + pANTLR3_COMMON_TOKEN (*createTokenFromToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_COMMON_TOKEN fromToken); + pANTLR3_COMMON_TOKEN (*getToken) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + void (*setTokenBoundaries) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken); + + ANTLR3_MARKER (*getTokenStartIndex) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + ANTLR3_MARKER (*getTokenStopIndex) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t); + + void (*setDebugEventListener)(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_DEBUG_EVENT_LISTENER debugger); + + /// Produce a DOT (see graphviz freeware suite) from a base tree + /// + pANTLR3_STRING (*makeDot) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * theTree); + + /// Replace from start to stop child index of parent with t, which might + /// be a list. Number of children may be different + /// after this call. + /// + /// If parent is null, don't do anything; must be at root of overall tree. + /// Can't replace whatever points to the parent externally. Do nothing. + /// + void (*replaceChildren) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, void * t); + + void (*free) (struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor); + +} + ANTLR3_TREE_ADAPTOR, *pANTLR3_TREE_ADAPTOR; +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3bitset.h b/antlr/libantlr3c-3.4/include/antlr3bitset.h new file mode 100644 index 0000000..7d816ab --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3bitset.h @@ -0,0 +1,119 @@ +/** + * \file + * Defines the basic structures of an ANTLR3 bitset. this is a C version of the + * cut down Bitset class provided with the java version of antlr 3. + * + * + */ +#ifndef _ANTLR3_BITSET_H +#define _ANTLR3_BITSET_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +/** How many bits in the elements + */ +#define ANTLR3_BITSET_BITS 64 + +/** How many bits in a nible of bits + */ +#define ANTLR3_BITSET_NIBBLE 4 + +/** log2 of ANTLR3_BITSET_BITS 2^ANTLR3_BITSET_LOG_BITS = ANTLR3_BITSET_BITS + */ +#define ANTLR3_BITSET_LOG_BITS 6 + +/** We will often need to do a mod operator (i mod nbits). + * For powers of two, this mod operation is the + * same as: + * - (i & (nbits-1)). + * + * Since mod is relatively slow, we use an easily + * precomputed mod mask to do the mod instead. + */ +#define ANTLR3_BITSET_MOD_MASK ANTLR3_BITSET_BITS - 1 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_BITSET_LIST_struct +{ + /// Pointer to the allocated array of bits for this bit set, which + /// is an array of 64 bit elements (of the architecture). If we find a + /// machine/C compiler that does not know anything about 64 bit values + /// then it should be easy enough to produce a 32 bit (or less) version + /// of the bitset code. Note that the pointer here may be static if laid down + /// by the code generation, and it must be copied if it is to be manipulated + /// to perform followset calculations. + /// + pANTLR3_BITWORD bits; + + /// Length of the current bit set in ANTLR3_UINT64 units. + /// + ANTLR3_UINT32 length; +} + ANTLR3_BITSET_LIST; + +typedef struct ANTLR3_BITSET_struct +{ + /// The actual bits themselves + /// + ANTLR3_BITSET_LIST blist; + + pANTLR3_BITSET (*clone) (struct ANTLR3_BITSET_struct * inSet); + pANTLR3_BITSET (*bor) (struct ANTLR3_BITSET_struct * bitset1, struct ANTLR3_BITSET_struct * bitset2); + void (*borInPlace) (struct ANTLR3_BITSET_struct * bitset, struct ANTLR3_BITSET_struct * bitset2); + ANTLR3_UINT32 (*size) (struct ANTLR3_BITSET_struct * bitset); + void (*add) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_INT32 bit); + void (*grow) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_INT32 newSize); + ANTLR3_BOOLEAN (*equals) (struct ANTLR3_BITSET_struct * bitset1, struct ANTLR3_BITSET_struct * bitset2); + ANTLR3_BOOLEAN (*isMember) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_UINT32 bit); + ANTLR3_UINT32 (*numBits) (struct ANTLR3_BITSET_struct * bitset); + void (*remove) (struct ANTLR3_BITSET_struct * bitset, ANTLR3_UINT32 bit); + ANTLR3_BOOLEAN (*isNilNode) (struct ANTLR3_BITSET_struct * bitset); + pANTLR3_INT32 (*toIntList) (struct ANTLR3_BITSET_struct * bitset); + + void (*free) (struct ANTLR3_BITSET_struct * bitset); + + +} + ANTLR3_BITSET; + +#ifdef __cplusplus +} +#endif + + + +#endif + diff --git a/antlr/libantlr3c-3.4/include/antlr3collections.h b/antlr/libantlr3c-3.4/include/antlr3collections.h new file mode 100644 index 0000000..7c73e36 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3collections.h @@ -0,0 +1,513 @@ +#ifndef ANTLR3COLLECTIONS_H +#define ANTLR3COLLECTIONS_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#define ANTLR3_HASH_TYPE_INT 0 /**< Indicates the hashed file has integer keys */ +#define ANTLR3_HASH_TYPE_STR 1 /**< Indicates the hashed file has numeric keys */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_HASH_KEY_struct +{ + ANTLR3_UINT8 type; /**< One of ##ANTLR3_HASH_TYPE_INT or ##ANTLR3_HASH_TYPE_STR */ + + union + { + pANTLR3_UINT8 sKey; /**< Used if type is ANTLR3_HASH_TYPE_STR */ + ANTLR3_INTKEY iKey; /**< used if type is ANTLR3_HASH_TYPE_INT */ + } + key; + +} ANTLR3_HASH_KEY, *pANTLR3_HASH_KEY; + +/** Internal structure representing an element in a hash bucket. + * Stores the original key so that duplicate keys can be rejected + * if necessary, and contains function can be supported. If the hash key + * could be unique I would have invented the perfect compression algorithm ;-) + */ +typedef struct ANTLR3_HASH_ENTRY_struct +{ + /** Key that created this particular entry + */ + ANTLR3_HASH_KEY keybase; + + /** Pointer to the data for this particular entry + */ + void * data; + + /** Pointer to routine that knows how to release the memory + * structure pointed at by data. If this is NULL then we assume + * that the data pointer does not need to be freed when the entry + * is deleted from the table. + */ + void (ANTLR3_CDECL *free)(void * data); + + /** Pointer to the next entry in this bucket if there + * is one. Sometimes different keys will hash to the same bucket (especially + * if the number of buckets is small). We could implement dual hashing algorithms + * to minimize this, but that seems over the top for what this is needed for. + */ + struct ANTLR3_HASH_ENTRY_struct * nextEntry; +} + ANTLR3_HASH_ENTRY; + +/** Internal structure of a hash table bucket, which tracks + * all keys that hash to the same bucket. + */ +typedef struct ANTLR3_HASH_BUCKET_struct +{ + /** Pointer to the first entry in the bucket (if any, it + * may be NULL). Duplicate entries are chained from + * here. + */ + pANTLR3_HASH_ENTRY entries; + +} + ANTLR3_HASH_BUCKET; + +/** Structure that tracks a hash table + */ +typedef struct ANTLR3_HASH_TABLE_struct +{ + /** Indicates whether the table allows duplicate keys + */ + int allowDups; + + /** Number of buckets available in this table + */ + ANTLR3_UINT32 modulo; + + /** Points to the memory where the array of buckets + * starts. + */ + pANTLR3_HASH_BUCKET buckets; + + /** How many elements currently exist in the table. + */ + ANTLR3_UINT32 count; + + /** Whether the hash table should strdup the keys it is given or not. + */ + ANTLR3_BOOLEAN doStrdup; + + /** Pointer to function to completely delete this table + */ + void (*free) (struct ANTLR3_HASH_TABLE_struct * table); + + /* String keyed hashtable functions */ + void (*del) (struct ANTLR3_HASH_TABLE_struct * table, void * key); + pANTLR3_HASH_ENTRY (*remove) (struct ANTLR3_HASH_TABLE_struct * table, void * key); + void * (*get) (struct ANTLR3_HASH_TABLE_struct * table, void * key); + ANTLR3_INT32 (*put) (struct ANTLR3_HASH_TABLE_struct * table, void * key, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + + /* Integer based hash functions */ + void (*delI) (struct ANTLR3_HASH_TABLE_struct * table, ANTLR3_INTKEY key); + pANTLR3_HASH_ENTRY (*removeI) (struct ANTLR3_HASH_TABLE_struct * table, ANTLR3_INTKEY key); + void * (*getI) (struct ANTLR3_HASH_TABLE_struct * table, ANTLR3_INTKEY key); + ANTLR3_INT32 (*putI) (struct ANTLR3_HASH_TABLE_struct * table, ANTLR3_INTKEY key, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + + ANTLR3_UINT32 (*size) (struct ANTLR3_HASH_TABLE_struct * table); +} + ANTLR3_HASH_TABLE; + + +/** Internal structure representing an enumeration of a table. + * This is returned by antlr3Enumeration() + * Allows the programmer to traverse the table in hash order without + * knowing what is in the actual table. + * + * Note that it is up to the caller to ensure that the table + * structure does not change in the hash bucket that is currently being + * enumerated as this structure just tracks the next pointers in the + * bucket series. + */ +typedef struct ANTLR3_HASH_ENUM_struct +{ + /* Pointer to the table we are enumerating + */ + pANTLR3_HASH_TABLE table; + + /* Bucket we are currently enumerating (if NULL then we are done) + */ + ANTLR3_UINT32 bucket; + + /* Next entry to return, if NULL, then move to next bucket if any + */ + pANTLR3_HASH_ENTRY entry; + + /* Interface + */ + int (*next) (struct ANTLR3_HASH_ENUM_struct * en, pANTLR3_HASH_KEY *key, void ** data); + void (*free) (struct ANTLR3_HASH_ENUM_struct * table); +} + ANTLR3_HASH_ENUM; + +/** Structure that represents a LIST collection + */ +typedef struct ANTLR3_LIST_struct +{ + /** Hash table that is storing the list elements + */ + pANTLR3_HASH_TABLE table; + + void (*free) (struct ANTLR3_LIST_struct * list); + void (*del) (struct ANTLR3_LIST_struct * list, ANTLR3_INTKEY key); + void * (*get) (struct ANTLR3_LIST_struct * list, ANTLR3_INTKEY key); + void * (*remove) (struct ANTLR3_LIST_struct * list, ANTLR3_INTKEY key); + ANTLR3_INT32 (*add) (struct ANTLR3_LIST_struct * list, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + ANTLR3_INT32 (*put) (struct ANTLR3_LIST_struct * list, ANTLR3_INTKEY key, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + ANTLR3_UINT32 (*size) (struct ANTLR3_LIST_struct * list); + +} + ANTLR3_LIST; + +/** Structure that represents a Stack collection + */ +typedef struct ANTLR3_STACK_struct +{ + /** List that supports the stack structure + */ + pANTLR3_VECTOR vector; + + /** Used for quick access to the top of the stack + */ + void * top; + void (*free) (struct ANTLR3_STACK_struct * stack); + void * (*pop) (struct ANTLR3_STACK_struct * stack); + void * (*get) (struct ANTLR3_STACK_struct * stack, ANTLR3_INTKEY key); + ANTLR3_BOOLEAN (*push) (struct ANTLR3_STACK_struct * stack, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + ANTLR3_UINT32 (*size) (struct ANTLR3_STACK_struct * stack); + void * (*peek) (struct ANTLR3_STACK_struct * stack); + +} + ANTLR3_STACK; + +/* Structure that represents a vector element + */ +typedef struct ANTLR3_VECTOR_ELEMENT_struct +{ + void * element; + void (ANTLR3_CDECL *freeptr)(void *); +} + ANTLR3_VECTOR_ELEMENT, *pANTLR3_VECTOR_ELEMENT; + +#define ANTLR3_VECTOR_INTERNAL_SIZE 16 +/* Structure that represents a vector collection. A vector is a simple list + * that contains a pointer to the element and a pointer to a function that + * that can free the element if it is removed. It auto resizes but does not + * use hash techniques as it is referenced by a simple numeric index. It is not a + * sparse list, so if any element is deleted, then the ones following are moved + * down in memory and the count is adjusted. + */ +typedef struct ANTLR3_VECTOR_struct +{ + /** Array of pointers to vector elements + */ + pANTLR3_VECTOR_ELEMENT elements; + + /** Number of entries currently in the list; + */ + ANTLR3_UINT32 count; + + /** Many times, a vector holds just a few nodes in an AST and it + * is too much overhead to malloc the space for elements so + * at the expense of a few bytes of memory, we hold the first + * few elements internally. It means we must copy them when + * we grow beyond this initial size, but that is less overhead than + * the malloc/free callas we would otherwise require. + */ + ANTLR3_VECTOR_ELEMENT internal[ANTLR3_VECTOR_INTERNAL_SIZE]; + + /** Indicates if the structure was made by a factory, in which + * case only the factory can free the memory for the actual vector, + * though the vector free function is called and will recurse through its + * entries calling any free pointers for each entry. + */ + ANTLR3_BOOLEAN factoryMade; + + /** Total number of entries in elements at any point in time + */ + ANTLR3_UINT32 elementsSize; + + void (ANTLR3_CDECL *free) (struct ANTLR3_VECTOR_struct * vector); + void (*del) (struct ANTLR3_VECTOR_struct * vector, ANTLR3_UINT32 entry); + void * (*get) (struct ANTLR3_VECTOR_struct * vector, ANTLR3_UINT32 entry); + void * (*remove) (struct ANTLR3_VECTOR_struct * vector, ANTLR3_UINT32 entry); + void (*clear) (struct ANTLR3_VECTOR_struct * vector); + ANTLR3_BOOLEAN (*swap) (struct ANTLR3_VECTOR_struct *, ANTLR3_UINT32 entry1, ANTLR3_UINT32 entry2); + ANTLR3_UINT32 (*add) (struct ANTLR3_VECTOR_struct * vector, void * element, void (ANTLR3_CDECL *freeptr)(void *)); + ANTLR3_UINT32 (*set) (struct ANTLR3_VECTOR_struct * vector, ANTLR3_UINT32 entry, void * element, void (ANTLR3_CDECL *freeptr)(void *), ANTLR3_BOOLEAN freeExisting); + ANTLR3_UINT32 (*size) (struct ANTLR3_VECTOR_struct * vector); +} + ANTLR3_VECTOR; + +/** Default vector pool size if otherwise unspecified + */ +#define ANTLR3_FACTORY_VPOOL_SIZE 256 + +/** Structure that tracks vectors in a vector and auto deletes the vectors + * in the vector factory when closed. + */ +typedef struct ANTLR3_VECTOR_FACTORY_struct +{ + + /** List of all vector pools allocated so far + */ + pANTLR3_VECTOR *pools; + + /** Count of the vector pools allocated so far (current active pool) + */ + ANTLR3_INT32 thisPool; + + /** The next vector available in the pool + */ + ANTLR3_UINT32 nextVector; + + /** Trick to quickly initialize a new vector via memcpy and not a function call + */ + ANTLR3_VECTOR unTruc; + + /** Consumers from the factory can release a factory produced vector + * back to the factory so that it may be reused (and thus conserve memory) + * by another caller. The available vectors are stored here. Note that + * the only vectors avaible in the free chain are produced by this factory, so they + * need not be explicitly freed when the factory is closed. + */ + pANTLR3_STACK freeStack; + + /** Function to close the vector factory + */ + void (*close) (struct ANTLR3_VECTOR_FACTORY_struct * factory); + + /** Function to supply a new vector + */ + pANTLR3_VECTOR (*newVector) (struct ANTLR3_VECTOR_FACTORY_struct * factory); + + /// Function to return a vector to the factory for reuse + /// + void (*returnVector) (struct ANTLR3_VECTOR_FACTORY_struct * factory, pANTLR3_VECTOR vector); + +} +ANTLR3_VECTOR_FACTORY; + + +/* -------------- TRIE Interfaces ---------------- */ + + +/** Structure that holds the payload entry in an ANTLR3_INT_TRIE or ANTLR3_STRING_TRIE + */ +typedef struct ANTLR3_TRIE_ENTRY_struct +{ + ANTLR3_UINT32 type; + void (ANTLR3_CDECL *freeptr)(void *); + union + { + ANTLR3_INTKEY intVal; + void * ptr; + } data; + + struct ANTLR3_TRIE_ENTRY_struct * next; /* Allows duplicate entries for same key in insertion order */ +} +ANTLR3_TRIE_ENTRY, * pANTLR3_TRIE_ENTRY; + + +/** Structure that defines an element/node in an ANTLR3_INT_TRIE + */ +typedef struct ANTLR3_INT_TRIE_NODE_struct +{ + ANTLR3_UINT32 bitNum; /**< This is the left/right bit index for traversal along the nodes */ + ANTLR3_INTKEY key; /**< This is the actual key that the entry represents if it is a terminal node */ + pANTLR3_TRIE_ENTRY buckets; /**< This is the data bucket(s) that the key indexes, which may be NULL */ + struct ANTLR3_INT_TRIE_NODE_struct * leftN; /**< Pointer to the left node from here when sKey & bitNum = 0 */ + struct ANTLR3_INT_TRIE_NODE_struct * rightN; /**< Pointer to the right node from here when sKey & bitNum, = 1 */ +} + ANTLR3_INT_TRIE_NODE, * pANTLR3_INT_TRIE_NODE; + +/** Structure that defines an ANTLR3_INT_TRIE. For this particular implementation, + * as you might expect, the key is turned into a "string" by looking at bit(key, depth) + * of the integer key. Using 64 bit keys gives us a depth limit of 64 (or bit 0..63) + * and potentially a huge trie. This is the algorithm for a Patricia Trie. + * Note also that this trie [can] accept multiple entries for the same key and is + * therefore a kind of elastic bucket patricia trie. + * + * If you find this code useful, please feel free to 'steal' it for any purpose + * as covered by the BSD license under which ANTLR is issued. You can cut the code + * but as the ANTLR library is only about 50K (Windows Vista), you might find it + * easier to just link the library. Please keep all comments and licenses and so on + * in any version of this you create of course. + * + * Jim Idle. + * + */ +typedef struct ANTLR3_INT_TRIE_struct +{ + pANTLR3_INT_TRIE_NODE root; /* Root node of this integer trie */ + pANTLR3_INT_TRIE_NODE current; /* Used to traverse the TRIE with the next() method */ + ANTLR3_UINT32 count; /* Current entry count */ + ANTLR3_BOOLEAN allowDups; /* Whether this trie accepts duplicate keys */ + + + pANTLR3_TRIE_ENTRY (*get) (struct ANTLR3_INT_TRIE_struct * trie, ANTLR3_INTKEY key); + ANTLR3_BOOLEAN (*del) (struct ANTLR3_INT_TRIE_struct * trie, ANTLR3_INTKEY key); + ANTLR3_BOOLEAN (*add) (struct ANTLR3_INT_TRIE_struct * trie, ANTLR3_INTKEY key, ANTLR3_UINT32 type, ANTLR3_INTKEY intVal, void * data, void (ANTLR3_CDECL *freeptr)(void *)); + void (*free) (struct ANTLR3_INT_TRIE_struct * trie); + +} + ANTLR3_INT_TRIE; + +/** + * A topological sort system that given a set of dependencies of a node m on node n, + * can sort them in dependency order. This is a generally useful utility object + * that does not care what the things are it is sorting. Generally the set + * to be sorted will be numeric indexes into some other structure such as an ANTLR3_VECTOR. + * I have provided a sort method that given ANTLR3_VECTOR as an input will sort + * the vector entries in place, as well as a sort method that just returns an + * array of the sorted noded indexes, in case you are not sorting ANTLR3_VECTORS but + * some set of your own device. + * + * Of the two main algorithms that could be used, I chose to use the depth first + * search for unvisited nodes as a) This runs in linear time, and b) it is what + * we used in the ANTLR Tool to perform a topological sort of the input grammar files + * based on their dependencies. + */ +typedef struct ANTLR3_TOPO_struct +{ + /** + * A vector of vectors of edges, built by calling the addEdge method() + * to indicate that node number n depends on node number m. Each entry in the vector + * contains a bitset, which has a bit index set for each node upon which the + * entry node depends. + */ + pANTLR3_BITSET * edges; + + /** + * A vector used to build up the sorted output order. Note that + * as the vector contains UINT32 then the maximum node index is + * 'limited' to 2^32, as nodes should be zero based. + */ + pANTLR3_UINT32 sorted; + + /** + * A vector used to detect cycles in the edge dependecies. It is used + * as a stack and each time we descend a node to one of its edges we + * add the node into this stack. If we find a node that we have already + * visited in the stack, then it means there wasa cycle such as 9->8->1->9 + * as the only way a node can be on the stack is if we are currently + * descnding from it as we remove it from the stack as we exit from + * descending its dependencies + */ + pANTLR3_UINT32 cycle; + + /** + * A flag that indicates the algorithm found a cycle in the edges + * such as 9->8->1->9 + * If this flag is set after you have called one of the sort routines + * then the detected cycle will be contained in the cycle array and + * cycleLimit will point to the one after the last entry in the cycle. + */ + ANTLR3_BOOLEAN hasCycle; + + /** + * A watermark used to accumulate potential cycles in the cycle array. + * This should be zero when we are done. Check hasCycle after calling one + * of the sort methods and if it is ANTLR3_TRUE then you can find the cycle + * in cycle[0]...cycle[cycleMark-1] + */ + ANTLR3_UINT32 cycleMark; + + /** + * One more than the largest node index that is contained in edges/sorted. + */ + ANTLR3_UINT32 limit; + + /** + * The set of visited nodes as determined by a set entry in + * the bitmap. + */ + pANTLR3_BITSET visited; + + /** + * A method that adds an edge from one node to another. An edge + * of n -> m indicates that node n is dependent on node m. Note that + * while building these edges, it is perfectly OK to add nodes out of + * sequence. So, if you have edges: + * + * 3 -> 0 + * 2 -> 1 + * 1 -> 3 + * + * The you can add them in that order and so add node 3 before nodes 2 and 1 + * + */ + void (*addEdge) (struct ANTLR3_TOPO_struct * topo, ANTLR3_UINT32 edge, ANTLR3_UINT32 dependency); + + + /** + * A method that returns a pointer to an array of sorted node indexes. + * The array is sorted in topological sorted order. Note that the array + * is only as large as the largest node index you created an edge for. This means + * that if you had an input of 32 nodes, but that largest node with an edge + * was 16, then the returned array will be the sorted order of the first 16 + * nodes and the last 16 nodes of your array are basically fine as they are + * as they had no dependencies and do not need any particular sort order. + * + * NB: If the structure that contains the array is freed, then the sorted + * array will be freed too so you should use the value of limit to + * make a long term copy of this array if you do not want to keep the topo + * structure around as well. + */ + pANTLR3_UINT32 (*sortToArray) (struct ANTLR3_TOPO_struct * topo); + + /** + * A method that sorts the supplied ANTLR3_VECTOR in place based + * on the previously supplied edge data. + */ + void (*sortVector) (struct ANTLR3_TOPO_struct * topo, pANTLR3_VECTOR v); + + /** + * A method to free this structure and any associated memory. + */ + void (*free) (struct ANTLR3_TOPO_struct * topo); +} + ANTLR3_TOPO; + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/antlr/libantlr3c-3.4/include/antlr3commontoken.h b/antlr/libantlr3c-3.4/include/antlr3commontoken.h new file mode 100644 index 0000000..c48068e --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3commontoken.h @@ -0,0 +1,367 @@ +/** \file + * \brief Defines the interface for a common token. + * + * All token streams should provide their tokens using an instance + * of this common token. A custom pointer is provided, wher you may attach + * a further structure to enhance the common token if you feel the need + * to do so. The C runtime will assume that a token provides implementations + * of the interface functions, but all of them may be rplaced by your own + * implementation if you require it. + */ +#ifndef _ANTLR3_COMMON_TOKEN_H +#define _ANTLR3_COMMON_TOKEN_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +/** How many tokens to allocate at once in the token factory + */ +#define ANTLR3_FACTORY_POOL_SIZE 1024 + +/* Base token types, which all lexer/parser tokens come after in sequence. + */ + +/** Indicator of an invalid token + */ +#define ANTLR3_TOKEN_INVALID 0 + +#define ANTLR3_EOR_TOKEN_TYPE 1 + +/** Imaginary token type to cause a traversal of child nodes in a tree parser + */ +#define ANTLR3_TOKEN_DOWN 2 + +/** Imaginary token type to signal the end of a stream of child nodes. + */ +#define ANTLR3_TOKEN_UP 3 + +/** First token that can be used by users/generated code + */ + +#define ANTLR3_MIN_TOKEN_TYPE ANTLR3_TOKEN_UP + 1 + +/** End of file token + */ +#define ANTLR3_TOKEN_EOF (ANTLR3_CHARSTREAM_EOF & 0xFFFFFFFF) + +/** Default channel for a token + */ +#define ANTLR3_TOKEN_DEFAULT_CHANNEL 0 + +/** Reserved channel number for a HIDDEN token - a token that + * is hidden from the parser. + */ +#define HIDDEN 99 + +#ifdef __cplusplus +extern "C" { +#endif + +// Indicates whether this token is carrying: +// +// State | Meaning +// ------+-------------------------------------- +// 0 | Nothing (neither rewrite text, nor setText) +// 1 | char * to user supplied rewrite text +// 2 | pANTLR3_STRING because of setText or similar action +// +#define ANTLR3_TEXT_NONE 0 +#define ANTLR3_TEXT_CHARP 1 +#define ANTLR3_TEXT_STRING 2 + +/** The definition of an ANTLR3 common token structure, which all implementations + * of a token stream should provide, installing any further structures in the + * custom pointer element of this structure. + * + * \remark + * Token streams are in essence provided by lexers or other programs that serve + * as lexers. + */ +typedef struct ANTLR3_COMMON_TOKEN_struct +{ + /** The actual type of this token + */ + ANTLR3_UINT32 type; + + /** Indicates that a token was produced from the token factory and therefore + * the the freeToken() method should not do anything itself because + * token factory is responsible for deleting it. + */ + ANTLR3_BOOLEAN factoryMade; + + /// A string factory that we can use if we ever need the text of a token + /// and need to manufacture a pANTLR3_STRING + /// + pANTLR3_STRING_FACTORY strFactory; + + /** The line number in the input stream where this token was derived from + */ + ANTLR3_UINT32 line; + + /** The offset into the input stream that the line in which this + * token resides starts. + */ + void * lineStart; + + /** The character position in the line that this token was derived from + */ + ANTLR3_INT32 charPosition; + + /** The virtual channel that this token exists in. + */ + ANTLR3_UINT32 channel; + + /** Pointer to the input stream that this token originated in. + */ + pANTLR3_INPUT_STREAM input; + + /** What the index of this token is, 0, 1, .., n-2, n-1 tokens + */ + ANTLR3_MARKER index; + + /** The character offset in the input stream where the text for this token + * starts. + */ + ANTLR3_MARKER start; + + /** The character offset in the input stream where the text for this token + * stops. + */ + ANTLR3_MARKER stop; + + /// Indicates whether this token is carrying: + /// + /// State | Meaning + /// ------+-------------------------------------- + /// 0 | Nothing (neither rewrite text, nor setText) + /// 1 | char * to user supplied rewrite text + /// 2 | pANTLR3_STRING because of setText or similar action + /// + /// Affects the union structure tokText below + /// (uses 32 bit so alignment is always good) + /// + ANTLR3_UINT32 textState; + + union + { + /// Pointer that is used when the token just has a pointer to + /// a char *, such as when a rewrite of an imaginary token supplies + /// a string in the grammar. No sense in constructing a pANTLR3_STRING just + /// for that, as mostly the text will not be accessed - if it is, then + /// we will build a pANTLR3_STRING for it a that point. + /// + pANTLR3_UCHAR chars; + + /// Some token types actually do carry around their associated text, hence + /// (*getText)() will return this pointer if it is not NULL + /// + pANTLR3_STRING text; + } + tokText; + + /** Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN + * as the standard structure for a token, a number of user programmable + * elements are allowed in a token. This is one of them. + */ + ANTLR3_UINT32 user1; + + /** Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN + * as the standard structure for a token, a number of user programmable + * elements are allowed in a token. This is one of them. + */ + ANTLR3_UINT32 user2; + + /** Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN + * as the standard structure for a token, a number of user programmable + * elements are allowed in a token. This is one of them. + */ + ANTLR3_UINT32 user3; + + /** Pointer to a custom element that the ANTLR3 programmer may define and install + */ + void * custom; + + /** Pointer to a function that knows how to free the custom structure when the + * token is destroyed. + */ + void (*freeCustom)(void * custom); + + /* ============================== + * API + */ + + /** Pointer to function that returns the text pointer of a token, use + * toString() if you want a pANTLR3_STRING version of the token. + */ + pANTLR3_STRING (*getText)(struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that 'might' be able to set the text associated + * with a token. Imaginary tokens such as an ANTLR3_CLASSIC_TOKEN may actually + * do this, however many tokens such as ANTLR3_COMMON_TOKEN do not actaully have + * strings associated with them but just point into the current input stream. These + * tokens will implement this function with a function that errors out (probably + * drastically. + */ + void (*setText)(struct ANTLR3_COMMON_TOKEN_struct * token, pANTLR3_STRING text); + + /** Pointer to a function that 'might' be able to set the text associated + * with a token. Imaginary tokens such as an ANTLR3_CLASSIC_TOKEN may actually + * do this, however many tokens such as ANTLR3_COMMON_TOKEN do not actully have + * strings associated with them but just point into the current input stream. These + * tokens will implement this function with a function that errors out (probably + * drastically. + */ + void (*setText8)(struct ANTLR3_COMMON_TOKEN_struct * token, pANTLR3_UINT8 text); + + /** Pointer to a function that returns the token type of this token + */ + ANTLR3_UINT32 (*getType)(struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the type of this token + */ + void (*setType)(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 ttype); + + /** Pointer to a function that gets the 'line' number where this token resides + */ + ANTLR3_UINT32 (*getLine)(struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the 'line' number where this token reside + */ + void (*setLine)(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 line); + + /** Pointer to a function that gets the offset in the line where this token exists + */ + ANTLR3_INT32 (*getCharPositionInLine) (struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the offset in the line where this token exists + */ + void (*setCharPositionInLine) (struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_INT32 pos); + + /** Pointer to a function that gets the channel that this token was placed in (parsers + * can 'tune' to these channels. + */ + ANTLR3_UINT32 (*getChannel) (struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the channel that this token should belong to + */ + void (*setChannel) (struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 channel); + + /** Pointer to a function that returns an index 0...n-1 of the token in the token + * input stream. + */ + ANTLR3_MARKER (*getTokenIndex) (struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that can set the token index of this token in the token + * input stream. + */ + void (*setTokenIndex) (struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER); + + /** Pointer to a function that gets the start index in the input stream for this token. + */ + ANTLR3_MARKER (*getStartIndex) (struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the start index in the input stream for this token. + */ + void (*setStartIndex) (struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER index); + + /** Pointer to a function that gets the stop index in the input stream for this token. + */ + ANTLR3_MARKER (*getStopIndex) (struct ANTLR3_COMMON_TOKEN_struct * token); + + /** Pointer to a function that sets the stop index in the input stream for this token. + */ + void (*setStopIndex) (struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER index); + + /** Pointer to a function that returns this token as a text representation that can be + * printed with embedded control codes such as \n replaced with the printable sequence "\\n" + * This also yields a string structure that can be used more easily than the pointer to + * the input stream in certain situations. + */ + pANTLR3_STRING (*toString) (struct ANTLR3_COMMON_TOKEN_struct * token); +} + ANTLR3_COMMON_TOKEN; + +/** \brief ANTLR3 Token factory interface to create lots of tokens efficiently + * rather than creating and freeing lots of little bits of memory. + */ +typedef struct ANTLR3_TOKEN_FACTORY_struct +{ + /** Pointers to the array of tokens that this factory has produced so far + */ + pANTLR3_COMMON_TOKEN *pools; + + /** Current pool tokens we are allocating from + */ + ANTLR3_INT32 thisPool; + + /** Maximum pool count we have available + */ + ANTLR3_INT32 maxPool; + + /** The next token to throw out from the pool, will cause a new pool allocation + * if this exceeds the available tokenCount + */ + ANTLR3_UINT32 nextToken; + + /** Trick to initialize tokens and their API quickly, we set up this token when the + * factory is created, then just copy the memory it uses into the new token. + */ + ANTLR3_COMMON_TOKEN unTruc; + + /** Pointer to an input stream that is using this token factory (may be NULL) + * which will be assigned to the tokens automatically. + */ + pANTLR3_INPUT_STREAM input; + + /** Pointer to a function that returns a new token + */ + pANTLR3_COMMON_TOKEN (*newToken) (struct ANTLR3_TOKEN_FACTORY_struct * factory); + + /** Pointer to a function that resets the factory so you can reuse the pools it + * has laready allocated + */ + void (*reset) (struct ANTLR3_TOKEN_FACTORY_struct * factory); + + /** Pointer to a function that changes teh curent inptu stream so that + * new tokens are created with reference to their originating text. + */ + void (*setInputStream) (struct ANTLR3_TOKEN_FACTORY_struct * factory, pANTLR3_INPUT_STREAM input); + /** Pointer to a function the destroys the factory + */ + void (*close) (struct ANTLR3_TOKEN_FACTORY_struct * factory); +} + ANTLR3_TOKEN_FACTORY; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3commontree.h b/antlr/libantlr3c-3.4/include/antlr3commontree.h new file mode 100644 index 0000000..1516ecc --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3commontree.h @@ -0,0 +1,167 @@ +/** Interface for an ANTLR3 common tree which is what gets + * passed around by the AST producing parser. + */ + +#ifndef _ANTLR3_COMMON_TREE_H +#define _ANTLR3_COMMON_TREE_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_COMMON_TREE_struct +{ + + /// Not used by ANTLR, but if a super structure is created above + /// this structure, it can be used to point to the start of the super + /// structure, where additional data and function pointers can be stored. + /// + void * super; + + /// Start token index that encases this tree + /// + ANTLR3_MARKER startIndex; + + /// End token that encases this tree + /// + ANTLR3_MARKER stopIndex; + + /// A single token, this is the payload for the tree + /// + pANTLR3_COMMON_TOKEN token; + + /// Points to the node that has this node as a child. + /// If this is NULL, then this is the root node. + /// + pANTLR3_COMMON_TREE parent; + + /// What index is this particular node in the child list it + /// belongs to? + /// + ANTLR3_INT32 childIndex; + + /// Pointer to the tree factory that manufactured this + /// token. This can be used by duplication methods and so on + /// to manufacture another auto-tracked common tree structure + /// + pANTLR3_ARBORETUM factory; + + /// An encapsulated BASE TREE structure (NOT a pointer) + /// that performs a lot of the dirty work of node management + /// To this we add just a few functions that are specific to the + /// payload. You can further abstract common tree so long + /// as you always have a baseTree pointer in the top structure + /// and copy it from the next one down. + /// So, lets say we have a structure JIMS_TREE. + /// It needs an ANTLR3_BASE_TREE that will support all the + /// general tree duplication stuff. + /// It needs a ANTLR3_COMMON_TREE structure embedded or completely + /// provides the equivalent interface. + /// It provides it's own methods and data. + /// To create a new one of these, the function provided to + /// the tree adaptor (see comments there) should allocate the + /// memory for a new JIMS_TREE structure, then call + /// antlr3InitCommonTree() + /// antlr3BaseTreeNew() + /// The interfaces for BASE_TREE and COMMON_TREE will then + /// be initialized. You then call and you can override them or just init + /// JIMS_TREE (note that the base tree in common tree will be ignored) + /// just the top level base tree is used). Codegen will take care of the rest. + /// + ANTLR3_BASE_TREE baseTree; + +} + ANTLR3_COMMON_TREE; + +/// \brief ANTLR3 Tree factory interface to create lots of trees efficiently +/// rather than creating and freeing lots of little bits of memory. +/// +typedef struct ANTLR3_ARBORETUM_struct +{ + /// Pointers to the array of tokens that this factory has produced so far + /// + pANTLR3_COMMON_TREE *pools; + + /// Current pool tokens we are allocating from + /// + ANTLR3_INT32 thisPool; + + /// The next token to throw out from the pool, will cause a new pool allocation + /// if this exceeds the available tokenCount + /// + ANTLR3_UINT32 nextTree; + + /// Trick to initialize tokens and their API quickly, we set up this token when the + /// factory is created, then just copy the memory it uses into the new token. + /// + ANTLR3_COMMON_TREE unTruc; + + /// Pointer to a vector factory that is used to create child list vectors + /// for any child nodes that need them. This means that we auto track the + /// vectors and auto free them when we close the factory. It also means + /// that all rewriting trees can use the same tree factory and the same + /// vector factory and we do not dup any nodes unless we must do so + /// explicitly because of context such as an empty rewrite stream and + /// ->IMAGINARY[ID] so on. This makes memory tracking much simpler and + /// tempts no errors. + /// + pANTLR3_VECTOR_FACTORY vFactory; + + /// A resuse stack for reclaiming Nil nodes that were used in rewrites + /// and are now dead. The nilNode() method will eat one of these before + /// creating a new node. + /// + pANTLR3_STACK nilStack; + + /// Pointer to a function that returns a new tree + /// + pANTLR3_BASE_TREE (*newTree) (struct ANTLR3_ARBORETUM_struct * factory); + pANTLR3_BASE_TREE (*newFromTree) (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TREE tree); + pANTLR3_BASE_TREE (*newFromToken) (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TOKEN token); + + /// Pointer to a function the destroys the factory + /// + void (*close) (struct ANTLR3_ARBORETUM_struct * factory); +} + ANTLR3_ARBORETUM; + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/antlr/libantlr3c-3.4/include/antlr3commontreeadaptor.h b/antlr/libantlr3c-3.4/include/antlr3commontreeadaptor.h new file mode 100644 index 0000000..4827997 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3commontreeadaptor.h @@ -0,0 +1,70 @@ +/** \file + * Definition of the ANTLR3 common tree adaptor. + */ + +#ifndef _ANTLR3_COMMON_TREE_ADAPTOR_H +#define _ANTLR3_COMMON_TREE_ADAPTOR_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_COMMON_TREE_ADAPTOR_struct +{ + /** Any enclosing structure/class can use this pointer to point to its own interface. + */ + void * super; + + /** Base interface implementation, embedded structure + */ + ANTLR3_TREE_ADAPTOR baseAdaptor; + + /** Tree factory for producing new nodes as required without needing to track + * memory allocation per node. + */ + pANTLR3_ARBORETUM arboretum; + +} + ANTLR3_COMMON_TREE_ADAPTOR; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3commontreenodestream.h b/antlr/libantlr3c-3.4/include/antlr3commontreenodestream.h new file mode 100644 index 0000000..beb0534 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3commontreenodestream.h @@ -0,0 +1,336 @@ +/// \file +/// Definition of the ANTLR3 common tree node stream. +/// + +#ifndef _ANTLR3_COMMON_TREE_NODE_STREAM__H +#define _ANTLR3_COMMON_TREE_NODE_STREAM__H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include +#include + +/// Token buffer initial size settings ( will auto increase) +/// +#define DEFAULT_INITIAL_BUFFER_SIZE 100 +#define INITIAL_CALL_STACK_SIZE 10 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_TREE_NODE_STREAM_struct +{ + /// Any interface that implements this interface (is a + /// super structure containing this structure), may store the pointer + /// to itself here in the super pointer, which is not used by + /// the tree node stream. This will point to an implementation + /// of ANTLR3_COMMON_TREE_NODE_STREAM in this case. + /// + pANTLR3_COMMON_TREE_NODE_STREAM ctns; + + /// All input streams implement the ANTLR3_INT_STREAM interface... + /// + pANTLR3_INT_STREAM istream; + + /// Get tree node at current input pointer + i ahead where i=1 is next node. + /// i<0 indicates nodes in the past. So LT(-1) is previous node, but + /// implementations are not required to provide results for k < -1. + /// LT(0) is undefined. For i>=n, return null. + /// Return NULL for LT(0) and any index that results in an absolute address + /// that is negative (beyond the start of the list). + /// + /// This is analogous to the LT() method of the TokenStream, but this + /// returns a tree node instead of a token. Makes code gen identical + /// for both parser and tree grammars. :) + /// + pANTLR3_BASE_TREE (*_LT) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, ANTLR3_INT32 k); + + /// Where is this stream pulling nodes from? This is not the name, but + /// the object that provides node objects. + /// + pANTLR3_BASE_TREE (*getTreeSource) (struct ANTLR3_TREE_NODE_STREAM_struct * tns); + + /// What adaptor can tell me how to interpret/navigate nodes and + /// trees. E.g., get text of a node. + /// + pANTLR3_BASE_TREE_ADAPTOR (*getTreeAdaptor) (struct ANTLR3_TREE_NODE_STREAM_struct * tns); + + /// As we flatten the tree, we use UP, DOWN nodes to represent + /// the tree structure. When debugging we need unique nodes + /// so we have to instantiate new ones. When doing normal tree + /// parsing, it's slow and a waste of memory to create unique + /// navigation nodes. Default should be false; + /// + void (*setUniqueNavigationNodes) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, ANTLR3_BOOLEAN uniqueNavigationNodes); + + pANTLR3_STRING (*toString) (struct ANTLR3_TREE_NODE_STREAM_struct * tns); + + /// Return the text of all nodes from start to stop, inclusive. + /// If the stream does not buffer all the nodes then it can still + /// walk recursively from start until stop. You can always return + /// null or "" too, but users should not access $ruleLabel.text in + /// an action of course in that case. + /// + pANTLR3_STRING (*toStringSS) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, pANTLR3_BASE_TREE start, pANTLR3_BASE_TREE stop); + + /// Return the text of all nodes from start to stop, inclusive, into the + /// supplied buffer. + /// If the stream does not buffer all the nodes then it can still + /// walk recursively from start until stop. You can always return + /// null or "" too, but users should not access $ruleLabel.text in + /// an action of course in that case. + /// + void (*toStringWork) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, pANTLR3_BASE_TREE start, pANTLR3_BASE_TREE stop, pANTLR3_STRING buf); + + /// Release up any and all space the the interface allocate, including for this structure. + /// + void (*free) (struct ANTLR3_TREE_NODE_STREAM_struct * tns); + + /// Get a tree node at an absolute index i; 0..n-1. + /// If you don't want to buffer up nodes, then this method makes no + /// sense for you. + /// + pANTLR3_BASE_TREE (*get) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, ANTLR3_INT32 i); + + // REWRITING TREES (used by tree parser) + + /// Replace from start to stop child index of parent with t, which might + /// be a list. Number of children may be different + /// after this call. The stream is notified because it is walking the + /// tree and might need to know you are monkeying with the underlying + /// tree. Also, it might be able to modify the node stream to avoid + /// restreaming for future phases. + /// + /// If parent is null, don't do anything; must be at root of overall tree. + /// Can't replace whatever points to the parent externally. Do nothing. + /// + void (*replaceChildren) (struct ANTLR3_TREE_NODE_STREAM_struct * tns, pANTLR3_BASE_TREE parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, pANTLR3_BASE_TREE t); + +} + ANTLR3_TREE_NODE_STREAM; + +typedef struct ANTLR3_COMMON_TREE_NODE_STREAM_struct +{ + /// Any interface that implements this interface (is a + /// super structure containing this structure), may store the pointer + /// to itself here in the super pointer, which is not used by + /// the common tree node stream. + /// + void * super; + + /// Pointer to the tree node stream interface + /// + pANTLR3_TREE_NODE_STREAM tnstream; + + /// String factory for use by anything that wishes to create strings + /// such as a tree representation or some copy of the text etc. + /// + pANTLR3_STRING_FACTORY stringFactory; + + /// Dummy tree node that indicates a descent into a child + /// tree. Initialized by a call to create a new interface. + /// + ANTLR3_COMMON_TREE DOWN; + + /// Dummy tree node that indicates a descent up to a parent + /// tree. Initialized by a call to create a new interface. + /// + ANTLR3_COMMON_TREE UP; + + /// Dummy tree node that indicates the termination point of the + /// tree. Initialized by a call to create a new interface. + /// + ANTLR3_COMMON_TREE EOF_NODE; + + /// Dummy node that is returned if we need to indicate an invalid node + /// for any reason. + /// + ANTLR3_COMMON_TREE INVALID_NODE; + + /// The complete mapping from stream index to tree node. + /// This buffer includes pointers to DOWN, UP, and EOF nodes. + /// It is built upon ctor invocation. The elements are type + /// Object as we don't what the trees look like. + /// + /// Load upon first need of the buffer so we can set token types + /// of interest for reverseIndexing. Slows us down a wee bit to + /// do all of the if p==-1 testing everywhere though, though in C + /// you won't really be able to measure this. + /// + /// Must be freed when the tree node stream is torn down. + /// + pANTLR3_VECTOR nodes; + + /// If set to ANTLR3_TRUE then the navigation nodes UP, DOWN are + /// duplicated rather than reused within the tree. + /// + ANTLR3_BOOLEAN uniqueNavigationNodes; + + /// Which tree are we navigating ? + /// + pANTLR3_BASE_TREE root; + + /// Pointer to tree adaptor interface that manipulates/builds + /// the tree. + /// + pANTLR3_BASE_TREE_ADAPTOR adaptor; + + /// As we walk down the nodes, we must track parent nodes so we know + /// where to go after walking the last child of a node. When visiting + /// a child, push current node and current index (current index + /// is first stored in the tree node structure to avoid two stacks. + /// + pANTLR3_STACK nodeStack; + + /// The current index into the nodes vector of the current tree + /// we are parsing and possibly rewriting. + /// + ANTLR3_INT32 p; + + /// Which node are we currently visiting? + /// + pANTLR3_BASE_TREE currentNode; + + /// Which node did we last visit? Used for LT(-1) + /// + pANTLR3_BASE_TREE previousNode; + + /// Which child are we currently visiting? If -1 we have not visited + /// this node yet; next consume() request will set currentIndex to 0. + /// + ANTLR3_INT32 currentChildIndex; + + /// What node index did we just consume? i=0..n-1 for n node trees. + /// IntStream.next is hence 1 + this value. Size will be same. + /// + ANTLR3_MARKER absoluteNodeIndex; + + /// Buffer tree node stream for use with LT(i). This list grows + /// to fit new lookahead depths, but consume() wraps like a circular + /// buffer. + /// + pANTLR3_BASE_TREE * lookAhead; + + /// Number of elements available in the lookahead buffer at any point in + /// time. This is the current size of the array. + /// + ANTLR3_UINT32 lookAheadLength; + + /// lookAhead[head] is the first symbol of lookahead, LT(1). + /// + ANTLR3_UINT32 head; + + /// Add new lookahead at lookahead[tail]. tail wraps around at the + /// end of the lookahead buffer so tail could be less than head. + /// + ANTLR3_UINT32 tail; + + /// Calls to mark() may be nested so we have to track a stack of + /// them. The marker is an index into this stack. Index 0 is + /// the first marker. This is a List + /// + pANTLR3_VECTOR markers; + + // INTERFACE + // + void (*fill) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns, ANTLR3_INT32 k); + + void (*addLookahead) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns, pANTLR3_BASE_TREE node); + + ANTLR3_BOOLEAN (*hasNext) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + pANTLR3_BASE_TREE (*next) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + pANTLR3_BASE_TREE (*handleRootnode) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + pANTLR3_BASE_TREE (*visitChild) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns, ANTLR3_UINT32 child); + + void (*addNavigationNode) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns, ANTLR3_UINT32 ttype); + + pANTLR3_BASE_TREE (*newDownNode) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + pANTLR3_BASE_TREE (*newUpNode) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + void (*walkBackToMostRecentNodeWithUnvisitedChildren) + (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + ANTLR3_BOOLEAN (*hasUniqueNavigationNodes) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + ANTLR3_UINT32 (*getLookaheadSize) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + void (*push) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns, ANTLR3_INT32 index); + + ANTLR3_INT32 (*pop) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + void (*reset) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + void (*free) (struct ANTLR3_COMMON_TREE_NODE_STREAM_struct * ctns); + + /// Indicates whether this node stream was derived from a prior + /// node stream to be used by a rewriting tree parser for instance. + /// If this flag is set to ANTLR3_TRUE, then when this stream is + /// closed it will not free the root tree as this tree always + /// belongs to the origniating node stream. + /// + ANTLR3_BOOLEAN isRewriter; + +} + ANTLR3_COMMON_TREE_NODE_STREAM; + +/** This structure is used to save the state information in the treenodestream + * when walking ahead with cyclic DFA or for syntactic predicates, + * we need to record the state of the tree node stream. This + * class wraps up the current state of the CommonTreeNodeStream. + * Calling mark() will push another of these on the markers stack. + */ +typedef struct ANTLR3_TREE_WALK_STATE_struct +{ + ANTLR3_UINT32 currentChildIndex; + ANTLR3_MARKER absoluteNodeIndex; + pANTLR3_BASE_TREE currentNode; + pANTLR3_BASE_TREE previousNode; + ANTLR3_UINT32 nodeStackSize; + pANTLR3_BASE_TREE * lookAhead; + ANTLR3_UINT32 lookAheadLength; + ANTLR3_UINT32 tail; + ANTLR3_UINT32 head; +} + ANTLR3_TREE_WALK_STATE; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3convertutf.h b/antlr/libantlr3c-3.4/include/antlr3convertutf.h new file mode 100644 index 0000000..79cc82c --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3convertutf.h @@ -0,0 +1,176 @@ +/* + * Copyright 2001-2004 Unicode, Inc. + * + * Disclaimer + * + * This source code is provided as is by Unicode, Inc. No claims are + * made as to fitness for any particular purpose. No warranties of any + * kind are expressed or implied. The recipient agrees to determine + * applicability of information provided. If this file has been + * purchased on magnetic or optical media from Unicode, Inc., the + * sole remedy for any claim will be exchange of defective media + * within 90 days of receipt. + * + * Limitations on Rights to Redistribute This Code + * + * Unicode, Inc. hereby grants the right to freely use the information + * supplied in this file in the creation of products supporting the + * Unicode Standard, and to make copies of this file in any form + * for internal or external distribution as long as this notice + * remains attached. + */ + +/* --------------------------------------------------------------------- + + Conversions between UTF32, UTF-16, and UTF-8. Header file. + + Several functions are included here, forming a complete set of + conversions between the three formats. UTF-7 is not included + here, but is handled in a separate source file. + + Each of these routines takes pointers to input buffers and output + buffers. The input buffers are const. + + Each routine converts the text between *sourceStart and sourceEnd, + putting the result into the buffer between *targetStart and + targetEnd. Note: the end pointers are *after* the last item: e.g. + *(sourceEnd - 1) is the last item. + + The return result indicates whether the conversion was successful, + and if not, whether the problem was in the source or target buffers. + (Only the first encountered problem is indicated.) + + After the conversion, *sourceStart and *targetStart are both + updated to point to the end of last text successfully converted in + the respective buffers. + + Input parameters: + sourceStart - pointer to a pointer to the source buffer. + The contents of this are modified on return so that + it points at the next thing to be converted. + targetStart - similarly, pointer to pointer to the target buffer. + sourceEnd, targetEnd - respectively pointers to the ends of the + two buffers, for overflow checking only. + + These conversion functions take a ConversionFlags argument. When this + flag is set to strict, both irregular sequences and isolated surrogates + will cause an error. When the flag is set to lenient, both irregular + sequences and isolated surrogates are converted. + + Whether the flag is strict or lenient, all illegal sequences will cause + an error return. This includes sequences such as: , , + or in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code + must check for illegal sequences. + + When the flag is set to lenient, characters over 0x10FFFF are converted + to the replacement character; otherwise (when the flag is set to strict) + they constitute an error. + + Output parameters: + The value "sourceIllegal" is returned from some routines if the input + sequence is malformed. When "sourceIllegal" is returned, the source + value will point to the illegal value that caused the problem. E.g., + in UTF-8 when a sequence is malformed, it points to the start of the + malformed sequence. + + Author: Mark E. Davis, 1994. + Rev History: Rick McGowan, fixes & updates May 2001. + Fixes & updates, Sept 2001. + +------------------------------------------------------------------------ */ + +/* --------------------------------------------------------------------- + The following 4 definitions are compiler-specific. + The C standard does not guarantee that wchar_t has at least + 16 bits, so wchar_t is no less portable than unsigned short! + All should be unsigned values to avoid sign extension during + bit mask & shift operations. +------------------------------------------------------------------------ */ + + +// Changes for ANTLR3 - Jim Idle, January 2008. +// builtin types defined for Unicode types changed to +// aliases for the types that are system determined by +// ANTLR at compile time. +// +// typedef unsigned long UTF32; /* at least 32 bits */ +// typedef unsigned short UTF16; /* at least 16 bits */ +// typedef unsigned char UTF8; /* typically 8 bits */ +// typedef unsigned char Boolean; /* 0 or 1 */ + +#ifndef _ANTLR3_CONVERTUTF_H +#define _ANTLR3_CONVERTUTF_H + +#include + +typedef ANTLR3_UINT32 UTF32; /* at least 32 bits */ +typedef ANTLR3_UINT16 UTF16; /* at least 16 bits */ +typedef ANTLR3_UINT8 UTF8; /* typically 8 bits */ + +/* Some fundamental constants */ +#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD +#define UNI_MAX_BMP (UTF32)0x0000FFFF +#define UNI_MAX_UTF16 (UTF32)0x0010FFFF +#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF +#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF + +#define UNI_SUR_HIGH_START (UTF32)0xD800 +#define UNI_SUR_HIGH_END (UTF32)0xDBFF +#define UNI_SUR_LOW_START (UTF32)0xDC00 +#define UNI_SUR_LOW_END (UTF32)0xDFFF +#define false ANTLR3_FALSE +#define true ANTLR3_TRUE +#define halfShift ((UTF32)10) +#define halfBase ((UTF32)0x0010000UL) +#define halfMask ((UTF32)0x3FFUL) + +typedef enum { + conversionOK, /* conversion successful */ + sourceExhausted, /* partial character in source, but hit end */ + targetExhausted, /* insuff. room in target for conversion */ + sourceIllegal /* source sequence is illegal/malformed */ +} ConversionResult; + +typedef enum { + strictConversion = 0, + lenientConversion +} ConversionFlags; + +/* This is for C++ and does no harm in C */ +#ifdef __cplusplus +extern "C" { +#endif + +ConversionResult ConvertUTF8toUTF16 ( + const UTF8** sourceStart, const UTF8* sourceEnd, + UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); + +ConversionResult ConvertUTF16toUTF8 ( + const UTF16** sourceStart, const UTF16* sourceEnd, + UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); + +ConversionResult ConvertUTF8toUTF32 ( + const UTF8** sourceStart, const UTF8* sourceEnd, + UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); + +ConversionResult ConvertUTF32toUTF8 ( + const UTF32** sourceStart, const UTF32* sourceEnd, + UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); + +ConversionResult ConvertUTF16toUTF32 ( + const UTF16** sourceStart, const UTF16* sourceEnd, + UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); + +ConversionResult ConvertUTF32toUTF16 ( + const UTF32** sourceStart, const UTF32* sourceEnd, + UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); + +ANTLR3_BOOLEAN isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd); + +#ifdef __cplusplus +} +#endif + +#endif + +/* --------------------------------------------------------------------- */ diff --git a/antlr/libantlr3c-3.4/include/antlr3cyclicdfa.h b/antlr/libantlr3c-3.4/include/antlr3cyclicdfa.h new file mode 100644 index 0000000..78708a0 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3cyclicdfa.h @@ -0,0 +1,97 @@ +/// Definition of a cyclic dfa structure such that it can be +/// initialized at compile time and have only a single +/// runtime function that can deal with all cyclic dfa +/// structures and show Java how it is done ;-) +/// +#ifndef ANTLR3_CYCLICDFA_H +#define ANTLR3_CYCLICDFA_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#ifdef __cplusplus +extern "C" { + +// If this header file is included as part of a generated recognizer that +// is being compiled as if it were C++, and this is Windows, then the const elements +// of the structure cause the C++ compiler to (rightly) point out that +// there can be no instantiation of the structure because it needs a constructor +// that can initialize the data, however these structures are not +// useful for C++ as they are pre-generated and static in the recognizer. +// So, we turn off those warnings, which are only at /W4 anyway. +// +#ifdef ANTLR3_WINDOWS +#pragma warning (push) +#pragma warning (disable : 4510) +#pragma warning (disable : 4512) +#pragma warning (disable : 4610) +#endif +#endif + +typedef struct ANTLR3_CYCLIC_DFA_struct +{ + /// Decision number that a particular static structure + /// represents. + /// + const ANTLR3_INT32 decisionNumber; + + /// What this decision represents + /// + const pANTLR3_UCHAR description; + + ANTLR3_INT32 (*specialStateTransition) (void * ctx, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_INT_STREAM is, struct ANTLR3_CYCLIC_DFA_struct * dfa, ANTLR3_INT32 s); + + ANTLR3_INT32 (*specialTransition) (void * ctx, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_INT_STREAM is, struct ANTLR3_CYCLIC_DFA_struct * dfa, ANTLR3_INT32 s); + + ANTLR3_INT32 (*predict) (void * ctx, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_INT_STREAM is, struct ANTLR3_CYCLIC_DFA_struct * dfa); + + const ANTLR3_INT32 * const eot; + const ANTLR3_INT32 * const eof; + const ANTLR3_INT32 * const min; + const ANTLR3_INT32 * const max; + const ANTLR3_INT32 * const accept; + const ANTLR3_INT32 * const special; + const ANTLR3_INT32 * const * const transition; + +} + ANTLR3_CYCLIC_DFA; + +typedef ANTLR3_INT32 (*CDFA_SPECIAL_FUNC) (void * , pANTLR3_BASE_RECOGNIZER , pANTLR3_INT_STREAM , struct ANTLR3_CYCLIC_DFA_struct * , ANTLR3_INT32); + +#ifdef __cplusplus +} +#ifdef ANTLR3_WINDOWS +#pragma warning (pop) +#endif +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3debugeventlistener.h b/antlr/libantlr3c-3.4/include/antlr3debugeventlistener.h new file mode 100644 index 0000000..c9cd6ce --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3debugeventlistener.h @@ -0,0 +1,398 @@ +/** + * \file + * The definition of all debugging events that a recognizer can trigger. + * + * \remark + * From the java implementation by Terence Parr... + * I did not create a separate AST debugging interface as it would create + * lots of extra classes and DebugParser has a dbg var defined, which makes + * it hard to change to ASTDebugEventListener. I looked hard at this issue + * and it is easier to understand as one monolithic event interface for all + * possible events. Hopefully, adding ST debugging stuff won't be bad. Leave + * for future. 4/26/2006. + */ + +#ifndef ANTLR3_DEBUG_EVENT_LISTENER_H +#define ANTLR3_DEBUG_EVENT_LISTENER_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include + + +/// Default debugging port +/// +#define DEFAULT_DEBUGGER_PORT 0xBFCC; + +#ifdef __cplusplus +extern "C" { +#endif + +/** The ANTLR3 debugging interface for communicating with ANLTR Works. Function comments + * mostly taken from the Java version. + */ +typedef struct ANTLR3_DEBUG_EVENT_LISTENER_struct +{ + /// The port number which the debug listener should listen on for a connection + /// + ANTLR3_UINT32 port; + + /// The socket structure we receive after a successful accept on the serverSocket + /// + SOCKET socket; + + /** The version of the debugging protocol supported by the providing + * instance of the debug event listener. + */ + int PROTOCOL_VERSION; + + /// The name of the grammar file that we are debugging + /// + pANTLR3_STRING grammarFileName; + + /// Indicates whether we have already connected or not + /// + ANTLR3_BOOLEAN initialized; + + /// Used to serialize the values of any particular token we need to + /// send back to the debugger. + /// + pANTLR3_STRING tokenString; + + + /// Allows the debug event system to access the adapter in use + /// by the recognizer, if this is a tree parser of some sort. + /// + pANTLR3_BASE_TREE_ADAPTOR adaptor; + + /// Wait for a connection from the debugger and initiate the + /// debugging session. + /// + ANTLR3_BOOLEAN (*handshake) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + /** The parser has just entered a rule. No decision has been made about + * which alt is predicted. This is fired AFTER init actions have been + * executed. Attributes are defined and available etc... + */ + void (*enterRule) (pANTLR3_DEBUG_EVENT_LISTENER delboy, const char * grammarFileName, const char * ruleName); + + /** Because rules can have lots of alternatives, it is very useful to + * know which alt you are entering. This is 1..n for n alts. + */ + void (*enterAlt) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int alt); + + /** This is the last thing executed before leaving a rule. It is + * executed even if an exception is thrown. This is triggered after + * error reporting and recovery have occurred (unless the exception is + * not caught in this rule). This implies an "exitAlt" event. + */ + void (*exitRule) (pANTLR3_DEBUG_EVENT_LISTENER delboy, const char * grammarFileName, const char * ruleName); + + /** Track entry into any (...) subrule other EBNF construct + */ + void (*enterSubRule) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int decisionNumber); + + void (*exitSubRule) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int decisionNumber); + + /** Every decision, fixed k or arbitrary, has an enter/exit event + * so that a GUI can easily track what LT/consume events are + * associated with prediction. You will see a single enter/exit + * subrule but multiple enter/exit decision events, one for each + * loop iteration. + */ + void (*enterDecision) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int decisionNumber); + + void (*exitDecision) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int decisionNumber); + + /** An input token was consumed; matched by any kind of element. + * Trigger after the token was matched by things like match(), matchAny(). + */ + void (*consumeToken) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_COMMON_TOKEN t); + + /** An off-channel input token was consumed. + * Trigger after the token was matched by things like match(), matchAny(). + * (unless of course the hidden token is first stuff in the input stream). + */ + void (*consumeHiddenToken) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_COMMON_TOKEN t); + + /** Somebody (anybody) looked ahead. Note that this actually gets + * triggered by both LA and LT calls. The debugger will want to know + * which Token object was examined. Like consumeToken, this indicates + * what token was seen at that depth. A remote debugger cannot look + * ahead into a file it doesn't have so LT events must pass the token + * even if the info is redundant. + */ + void (*LT) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int i, pANTLR3_COMMON_TOKEN t); + + /** The parser is going to look arbitrarily ahead; mark this location, + * the token stream's marker is sent in case you need it. + */ + void (*mark) (pANTLR3_DEBUG_EVENT_LISTENER delboy, ANTLR3_MARKER marker); + + /** After an arbitrarily long lookahead as with a cyclic DFA (or with + * any backtrack), this informs the debugger that stream should be + * rewound to the position associated with marker. + */ + void (*rewind) (pANTLR3_DEBUG_EVENT_LISTENER delboy, ANTLR3_MARKER marker); + + /** Rewind to the input position of the last marker. + * Used currently only after a cyclic DFA and just + * before starting a sem/syn predicate to get the + * input position back to the start of the decision. + * Do not "pop" the marker off the state. mark(i) + * and rewind(i) should balance still. + */ + void (*rewindLast) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + void (*beginBacktrack) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int level); + + void (*endBacktrack) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int level, ANTLR3_BOOLEAN successful); + + /** To watch a parser move through the grammar, the parser needs to + * inform the debugger what line/charPos it is passing in the grammar. + * For now, this does not know how to switch from one grammar to the + * other and back for island grammars etc... + * + * This should also allow breakpoints because the debugger can stop + * the parser whenever it hits this line/pos. + */ + void (*location) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int line, int pos); + + /** A recognition exception occurred such as NoViableAltException. I made + * this a generic event so that I can alter the exception hierarchy later + * without having to alter all the debug objects. + * + * Upon error, the stack of enter rule/subrule must be properly unwound. + * If no viable alt occurs it is within an enter/exit decision, which + * also must be rewound. Even the rewind for each mark must be unwound. + * In the Java target this is pretty easy using try/finally, if a bit + * ugly in the generated code. The rewind is generated in DFA.predict() + * actually so no code needs to be generated for that. For languages + * w/o this "finally" feature (C++?), the target implementor will have + * to build an event stack or something. + * + * Across a socket for remote debugging, only the RecognitionException + * data fields are transmitted. The token object or whatever that + * caused the problem was the last object referenced by LT. The + * immediately preceding LT event should hold the unexpected Token or + * char. + * + * Here is a sample event trace for grammar: + * + * b : C ({;}A|B) // {;} is there to prevent A|B becoming a set + * | D + * ; + * + * The sequence for this rule (with no viable alt in the subrule) for + * input 'c c' (there are 3 tokens) is: + * + * commence + * LT(1) + * enterRule b + * location 7 1 + * enter decision 3 + * LT(1) + * exit decision 3 + * enterAlt1 + * location 7 5 + * LT(1) + * consumeToken [c/<4>,1:0] + * location 7 7 + * enterSubRule 2 + * enter decision 2 + * LT(1) + * LT(1) + * recognitionException NoViableAltException 2 1 2 + * exit decision 2 + * exitSubRule 2 + * beginResync + * LT(1) + * consumeToken [c/<4>,1:1] + * LT(1) + * endResync + * LT(-1) + * exitRule b + * terminate + */ + void (*recognitionException) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_EXCEPTION e); + + /** Indicates the recognizer is about to consume tokens to resynchronize + * the parser. Any consume events from here until the recovered event + * are not part of the parse--they are dead tokens. + */ + void (*beginResync) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + /** Indicates that the recognizer has finished consuming tokens in order + * to resynchronize. There may be multiple beginResync/endResync pairs + * before the recognizer comes out of errorRecovery mode (in which + * multiple errors are suppressed). This will be useful + * in a gui where you want to probably grey out tokens that are consumed + * but not matched to anything in grammar. Anything between + * a beginResync/endResync pair was tossed out by the parser. + */ + void (*endResync) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + /** A semantic predicate was evaluate with this result and action text + */ + void (*semanticPredicate) (pANTLR3_DEBUG_EVENT_LISTENER delboy, ANTLR3_BOOLEAN result, const char * predicate); + + /** Announce that parsing has begun. Not technically useful except for + * sending events over a socket. A GUI for example will launch a thread + * to connect and communicate with a remote parser. The thread will want + * to notify the GUI when a connection is made. ANTLR parsers + * trigger this upon entry to the first rule (the ruleLevel is used to + * figure this out). + */ + void (*commence) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + /** Parsing is over; successfully or not. Mostly useful for telling + * remote debugging listeners that it's time to quit. When the rule + * invocation level goes to zero at the end of a rule, we are done + * parsing. + */ + void (*terminate) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + /// Retrieve acknowledge response from the debugger. in fact this + /// response is never used at the moment. So we just read whatever + /// is in the socket buffer and throw it away. + /// + void (*ack) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + + // T r e e P a r s i n g + + /** Input for a tree parser is an AST, but we know nothing for sure + * about a node except its type and text (obtained from the adaptor). + * This is the analog of the consumeToken method. The ID is usually + * the memory address of the node. + * If the type is UP or DOWN, then + * the ID is not really meaningful as it's fixed--there is + * just one UP node and one DOWN navigation node. + * + * Note that unlike the Java version, the node type of the C parsers + * is always fixed as pANTLR3_BASE_TREE because all such structures + * contain a super pointer to their parent, which is generally COMMON_TREE and within + * that there is a super pointer that can point to a user type that encapsulates it. + * Almost akin to saying that it is an interface pointer except we don't need to + * know what the interface is in full, just those bits that are the base. + * @param t + */ + void (*consumeNode) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE t); + + /** The tree parser looked ahead. If the type is UP or DOWN, + * then the ID is not really meaningful as it's fixed--there is + * just one UP node and one DOWN navigation node. + */ + void (*LTT) (pANTLR3_DEBUG_EVENT_LISTENER delboy, int i, pANTLR3_BASE_TREE t); + + + // A S T E v e n t s + + /** A nil was created (even nil nodes have a unique ID... + * they are not "null" per se). As of 4/28/2006, this + * seems to be uniquely triggered when starting a new subtree + * such as when entering a subrule in automatic mode and when + * building a tree in rewrite mode. + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only t.ID is set. + */ + void (*nilNode) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE t); + + /** If a syntax error occurs, recognizers bracket the error + * with an error node if they are building ASTs. This event + * notifies the listener that this is the case + */ + void (*errorNode) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE t); + + /** Announce a new node built from token elements such as type etc... + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only t.ID, type, text are + * set. + */ + void (*createNode) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE t); + + /** Announce a new node built from an existing token. + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only node.ID and token.tokenIndex + * are set. + */ + void (*createNodeTok) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE node, pANTLR3_COMMON_TOKEN token); + + /** Make a node the new root of an existing root. See + * + * Note: the newRootID parameter is possibly different + * than the TreeAdaptor.becomeRoot() newRoot parameter. + * In our case, it will always be the result of calling + * TreeAdaptor.becomeRoot() and not root_n or whatever. + * + * The listener should assume that this event occurs + * only when the current subrule (or rule) subtree is + * being reset to newRootID. + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only IDs are set. + * + * @see org.antlr.runtime.tree.TreeAdaptor.becomeRoot() + */ + void (*becomeRoot) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE newRoot, pANTLR3_BASE_TREE oldRoot); + + /** Make childID a child of rootID. + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only IDs are set. + * + * @see org.antlr.runtime.tree.TreeAdaptor.addChild() + */ + void (*addChild) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE root, pANTLR3_BASE_TREE child); + + /** Set the token start/stop token index for a subtree root or node. + * + * If you are receiving this event over a socket via + * RemoteDebugEventSocketListener then only t.ID is set. + */ + void (*setTokenBoundaries) (pANTLR3_DEBUG_EVENT_LISTENER delboy, pANTLR3_BASE_TREE t, ANTLR3_MARKER tokenStartIndex, ANTLR3_MARKER tokenStopIndex); + + /// Free up the resources allocated to this structure + /// + void (*free) (pANTLR3_DEBUG_EVENT_LISTENER delboy); + +} + ANTLR3_DEBUG_EVENT_LISTENER; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/antlr/libantlr3c-3.4/include/antlr3defs.h b/antlr/libantlr3c-3.4/include/antlr3defs.h new file mode 100644 index 0000000..2435b02 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3defs.h @@ -0,0 +1,632 @@ +/** \file + * Basic type and constant definitions for ANTLR3 Runtime. + */ +#ifndef _ANTLR3DEFS_H +#define _ANTLR3DEFS_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* Following are for generated code, they are not referenced internally!!! + */ +#if !defined(ANTLR3_HUGE) && !defined(ANTLR3_AVERAGE) && !defined(ANTLR3_SMALL) +#define ANTLR3_AVERAGE +#endif + +#ifdef ANTLR3_HUGE +#ifndef ANTLR3_SIZE_HINT +#define ANTLR3_SIZE_HINT 2049 +#endif +#ifndef ANTLR3_LIST_SIZE_HINT +#define ANTLR3_LIST_SIZE_HINT 127 +#endif +#endif + +#ifdef ANTLR3_AVERAGE +#ifndef ANTLR3_SIZE_HINT +#define ANTLR3_SIZE_HINT 1025 +#define ANTLR3_LIST_SIZE_HINT 63 +#endif +#endif + +#ifdef ANTLR3_SMALL +#ifndef ANTLR3_SIZE_HINT +#define ANTLR3_SIZE_HINT 211 +#define ANTLR3_LIST_SIZE_HINT 31 +#endif +#endif + +// Definitions that indicate the encoding scheme character streams and strings etc +// +/// Indicates Big Endian for encodings where this makes sense +/// +#define ANTLR3_BE 1 + +/// Indicates Little Endian for encoidngs where this makes sense +/// +#define ANTLR3_LE 2 + +/// General latin-1 or other 8 bit encoding scheme such as straight ASCII +/// +#define ANTLR3_ENC_8BIT 4 + +/// UTF-8 encoding scheme +/// +#define ANTLR3_ENC_UTF8 8 + +/// UTF-16 encoding scheme (which also covers UCS2 as that does not have surrogates) +/// +#define ANTLR3_ENC_UTF16 16 +#define ANTLR3_ENC_UTF16BE 16 + ANTLR3_BE +#define ANTLR3_ENC_UTF16LE 16 + ANTLR3_LE + +/// UTF-32 encoding scheme (basically straight 32 bit) +/// +#define ANTLR3_ENC_UTF32 32 +#define ANTLR3_ENC_UTF32BE 32 + ANTLR3_BE +#define ANTLR3_ENC_UTF32LE 32 + ANTLR3_LE + +/// Input is 8 bit EBCDIC (which we convert to 8 bit ASCII on the fly +/// +#define ANTLR3_ENC_EBCDIC 64 + +/* Common definitions come first + */ +#include + +/* Work out what operating system/compiler this is. We just do this once + * here and use an internal symbol after this. + */ +#ifdef _WIN64 + +# ifndef ANTLR3_WINDOWS +# define ANTLR3_WINDOWS +# endif +# define ANTLR3_WIN64 +# define ANTLR3_USE_64BIT + +#else + +#ifdef _WIN32 +# ifndef ANTLR3_WINDOWS +# define ANTLR3_WINDOWS +# endif + +#define ANTLR3_WIN32 +#endif + +#endif + +#ifdef ANTLR3_WINDOWS + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +/* Allow VC 8 (vs2005) and above to use 'secure' versions of various functions such as sprintf + */ +#ifndef _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define ANTLR3_API __declspec(dllexport) +#define ANTLR3_CDECL __cdecl +#define ANTLR3_FASTCALL __fastcall + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MINGW32__ +// Standard Windows types +// +typedef INT32 ANTLR3_CHAR, *pANTLR3_CHAR; +typedef UINT32 ANTLR3_UCHAR, *pANTLR3_UCHAR; + +typedef INT8 ANTLR3_INT8, *pANTLR3_INT8; +typedef INT16 ANTLR3_INT16, *pANTLR3_INT16; +typedef INT32 ANTLR3_INT32, *pANTLR3_INT32; +typedef INT64 ANTLR3_INT64, *pANTLR3_INT64; +typedef UINT8 ANTLR3_UINT8, *pANTLR3_UINT8; +typedef UINT16 ANTLR3_UINT16, *pANTLR3_UINT16; +typedef UINT32 ANTLR3_UINT32, *pANTLR3_UINT32; +typedef UINT64 ANTLR3_UINT64, *pANTLR3_UINT64; +typedef UINT64 ANTLR3_BITWORD, *pANTLR3_BITWORD; +typedef UINT8 ANTLR3_BOOLEAN, *pANTLR3_BOOLEAN; + +#else +// Mingw uses stdint.h and fails to define standard Microsoft typedefs +// such as UINT16, hence we must use stdint.h for Mingw. +// +#include +typedef int32_t ANTLR3_CHAR, *pANTLR3_CHAR; +typedef uint32_t ANTLR3_UCHAR, *pANTLR3_UCHAR; + +typedef int8_t ANTLR3_INT8, *pANTLR3_INT8; +typedef int16_t ANTLR3_INT16, *pANTLR3_INT16; +typedef int32_t ANTLR3_INT32, *pANTLR3_INT32; +typedef int64_t ANTLR3_INT64, *pANTLR3_INT64; + +typedef uint8_t ANTLR3_UINT8, *pANTLR3_UINT8; +typedef uint16_t ANTLR3_UINT16, *pANTLR3_UINT16; +typedef uint32_t ANTLR3_UINT32, *pANTLR3_UINT32; +typedef uint64_t ANTLR3_UINT64, *pANTLR3_UINT64; +typedef uint64_t ANTLR3_BITWORD, *pANTLR3_BITWORD; + +typedef uint8_t ANTLR3_BOOLEAN, *pANTLR3_BOOLEAN; + +#endif + + + +#define ANTLR3_UINT64_LIT(lit) lit##ULL + +#define ANTLR3_INLINE __inline + +typedef FILE * ANTLR3_FDSC; +typedef struct stat ANTLR3_FSTAT_STRUCT; + +#ifdef ANTLR3_USE_64BIT +#define ANTLR3_FUNC_PTR(ptr) (void *)((ANTLR3_UINT64)(ptr)) +#define ANTLR3_UINT64_CAST(ptr) (ANTLR3_UINT64)(ptr)) +#define ANTLR3_UINT32_CAST(ptr) (ANTLR3_UINT32)((ANTLR3_UINT64)(ptr)) +typedef ANTLR3_INT64 ANTLR3_MARKER; +typedef ANTLR3_UINT64 ANTLR3_INTKEY; +#else +#define ANTLR3_FUNC_PTR(ptr) (void *)((ANTLR3_UINT32)(ptr)) +#define ANTLR3_UINT64_CAST(ptr) (ANTLR3_UINT64)((ANTLR3_UINT32)(ptr)) +#define ANTLR3_UINT32_CAST(ptr) (ANTLR3_UINT32)(ptr) +typedef ANTLR3_INT32 ANTLR3_MARKER; +typedef ANTLR3_UINT32 ANTLR3_INTKEY; +#endif + +#ifdef ANTLR3_WIN32 +#endif + +#ifdef ANTLR3_WIN64 +#endif + + +typedef int ANTLR3_SALENT; // Type used for size of accept structure +typedef struct sockaddr_in ANTLR3_SOCKADDRT, * pANTLR3_SOCKADDRT; // Type used for socket address declaration +typedef struct sockaddr ANTLR3_SOCKADDRC, * pANTLR3_SOCKADDRC; // Type used for cast on accept() + +#define ANTLR3_CLOSESOCKET closesocket + +#ifdef __cplusplus +} +#endif + +/* Warnings that are over-zealous such as complaining about strdup, we + * can turn off. + */ + +/* Don't complain about "deprecated" functions such as strdup + */ +#pragma warning( disable : 4996 ) + +#else + +/* Include configure generated header file + */ +#include + +#include + +#if HAVE_STDINT_H +# include +#endif + +#if HAVE_SYS_TYPES_H +# include +#endif + +#if HAVE_SYS_STAT_H +# include +#endif + +#if STDC_HEADERS +# include +# include +# include +#else +# if HAVE_STDLIB_H +# include +# endif +# if HAVE_STDARG_H +# include +# endif +#endif + +#if HAVE_STRING_H +# if !STDC_HEADERS && HAVE_MEMORY_H +# include +# endif +# include +#endif + +#if HAVE_STRINGS_H +# include +#endif + +#if HAVE_INTTYPES_H +# include +#endif + +#if HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_SOCKET_H +# include +#else +# if HAVE_SYS_SOCKET_H +# include +# endif +#endif + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + +#ifdef HAVE_ARPA_NAMESER_H +#include /* DNS HEADER struct */ +#endif + +#ifdef HAVE_NETDB_H +#include +#endif + + +#ifdef HAVE_SYS_RESOLVE_H +#include +#endif + +#ifdef HAVE_RESOLVE_H +#include +#endif + + +#ifdef HAVE_MALLOC_H +# include +#else +# ifdef HAVE_SYS_MALLOC_H +# include +# endif +#endif + +#ifdef HAVE_CTYPE_H +# include +#endif + +/* Some platforms define a macro, index() in string.h. AIX is + * one of these for instance. We must get rid of that definition + * as we use ->index all over the place. defining macros like this in system header + * files is a really bad idea, but I doubt that IBM will listen to me ;-) + */ +#ifdef index +#undef index +#endif + +#define _stat stat + +// SOCKET not defined on Unix +// +typedef int SOCKET; + +#define ANTLR3_API +#define ANTLR3_CDECL +#define ANTLR3_FASTCALL + +#ifdef __hpux + + // HPUX is always different usually for no good reason. Tru64 should have kicked it + // into touch and everyone knows it ;-) + // + typedef struct sockaddr_in ANTLR3_SOCKADDRT, * pANTLR3_SOCKADDRT; // Type used for socket address declaration + typedef void * pANTLR3_SOCKADDRC; // Type used for cast on accept() + typedef int ANTLR3_SALENT; + +#else + +# if defined(_AIX) || __GNUC__ > 3 + + typedef socklen_t ANTLR3_SALENT; + +# else + + typedef size_t ANTLR3_SALENT; + +# endif + + typedef struct sockaddr_in ANTLR3_SOCKADDRT, * pANTLR3_SOCKADDRT; // Type used for socket address declaration + typedef struct sockaddr * pANTLR3_SOCKADDRC; // Type used for cast on accept() + +#endif + +#define INVALID_SOCKET ((SOCKET)-1) +#define ANTLR3_CLOSESOCKET close + +#ifdef __cplusplus +extern "C" { +#endif + +/* Inherit type definitions for autoconf + */ +typedef int32_t ANTLR3_CHAR, *pANTLR3_CHAR; +typedef uint32_t ANTLR3_UCHAR, *pANTLR3_UCHAR; + +typedef int8_t ANTLR3_INT8, *pANTLR3_INT8; +typedef int16_t ANTLR3_INT16, *pANTLR3_INT16; +typedef int32_t ANTLR3_INT32, *pANTLR3_INT32; +typedef int64_t ANTLR3_INT64, *pANTLR3_INT64; + +typedef uint8_t ANTLR3_UINT8, *pANTLR3_UINT8; +typedef uint16_t ANTLR3_UINT16, *pANTLR3_UINT16; +typedef uint32_t ANTLR3_UINT32, *pANTLR3_UINT32; +typedef uint64_t ANTLR3_UINT64, *pANTLR3_UINT64; +typedef uint64_t ANTLR3_BITWORD, *pANTLR3_BITWORD; + +typedef uint32_t ANTLR3_BOOLEAN, *pANTLR3_BOOLEAN; + +#define ANTLR3_INLINE inline +#define ANTLR3_API + +typedef FILE * ANTLR3_FDSC; +typedef struct stat ANTLR3_FSTAT_STRUCT; + +#ifdef ANTLR3_USE_64BIT +#define ANTLR3_FUNC_PTR(ptr) (void *)((ANTLR3_UINT64)(ptr)) +#define ANTLR3_UINT64_CAST(ptr) (ANTLR3_UINT64)(ptr)) +#define ANTLR3_UINT32_CAST(ptr) (ANTLR3_UINT32)((ANTLR3_UINT64)(ptr)) +typedef ANTLR3_INT64 ANTLR3_MARKER; +typedef ANTLR3_UINT64 ANTLR3_INTKEY; +#else +#define ANTLR3_FUNC_PTR(ptr) (void *)((ANTLR3_UINT32)(ptr)) +#define ANTLR3_UINT64_CAST(ptr) (ANTLR3_UINT64)((ANTLR3_UINT32)(ptr)) +#define ANTLR3_UINT32_CAST(ptr) (ANTLR3_UINT32)(ptr) +typedef ANTLR3_INT32 ANTLR3_MARKER; +typedef ANTLR3_UINT32 ANTLR3_INTKEY; +#endif +#define ANTLR3_UINT64_LIT(lit) lit##ULL + +#ifdef __cplusplus +} +#endif + +#endif + +#ifdef ANTLR3_USE_64BIT +#define ANTLR3_TRIE_DEPTH 63 +#else +#define ANTLR3_TRIE_DEPTH 31 +#endif +/* Pre declare the typedefs for all the interfaces, then + * they can be inter-dependant and we will let the linker + * sort it out for us. + */ +#include + +// Include the unicode.org conversion library header. +// +#include + +/* Prototypes + */ +#ifndef ANTLR3_MALLOC +/// Default definition of ANTLR3_MALLOC. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_MALLOC(request) malloc ((size_t)(request)) +#endif + +#ifndef ANTLR3_CALLOC +/// Default definition of ANTLR3_CALLOC. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_CALLOC(numEl, elSize) calloc (numEl, (size_t)(elSize)) +#endif + +#ifndef ANTLR3_REALLOC +/// Default definition of ANTLR3_REALLOC. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_REALLOC(current, request) realloc ((void *)(current), (size_t)(request)) +#endif +#ifndef ANTLR3_FREE +/// Default definition of ANTLR3_FREE. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_FREE(ptr) free ((void *)(ptr)) +#endif +#ifndef ANTLR3_FREE_FUNC +/// Default definition of ANTLR3_FREE_FUNC. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_FREE_FUNC free +#endif +#ifndef ANTLR3_STRDUP +/// Default definition of ANTLR3_STRDUP. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_STRDUP(instr) (pANTLR3_UINT8)(strdup ((const char *)(instr))) +#endif +#ifndef ANTLR3_MEMCPY +/// Default definition of ANTLR3_MEMCPY. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_MEMCPY(target, source, size) memcpy((void *)(target), (const void *)(source), (size_t)(size)) +#endif +#ifndef ANTLR3_MEMMOVE +/// Default definition of ANTLR3_MEMMOVE. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_MEMMOVE(target, source, size) memmove((void *)(target), (const void *)(source), (size_t)(size)) +#endif +#ifndef ANTLR3_MEMSET +/// Default definition of ANTLR3_MEMSET. You can override this before including +/// antlr3.h if you wish to use your own implementation. +/// +#define ANTLR3_MEMSET(target, byte, size) memset((void *)(target), (int)(byte), (size_t)(size)) +#endif + +#ifndef ANTLR3_PRINTF +/// Default definition of printf, set this to something other than printf before including antlr3.h +/// if your system does not have a printf. Note that you can define this to be // +/// without harming the runtime. +/// +#define ANTLR3_PRINTF printf +#endif + +#ifndef ANTLR3_FPRINTF +/// Default definition of fprintf, set this to something other than fprintf before including antlr3.h +/// if your system does not have a fprintf. Note that you can define this to be // +/// without harming the runtime. +/// +#define ANTLR3_FPRINTF fprintf +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +ANTLR3_API pANTLR3_INT_TRIE antlr3IntTrieNew (ANTLR3_UINT32 depth); + +ANTLR3_API pANTLR3_BITSET antlr3BitsetNew (ANTLR3_UINT32 numBits); +ANTLR3_API pANTLR3_BITSET antlr3BitsetOf (ANTLR3_INT32 bit, ...); +ANTLR3_API pANTLR3_BITSET antlr3BitsetList (pANTLR3_HASH_TABLE list); +ANTLR3_API pANTLR3_BITSET antlr3BitsetCopy (pANTLR3_BITSET_LIST blist); +ANTLR3_API pANTLR3_BITSET antlr3BitsetLoad (pANTLR3_BITSET_LIST blist); +ANTLR3_API void antlr3BitsetSetAPI (pANTLR3_BITSET bitset); + + +ANTLR3_API pANTLR3_BASE_RECOGNIZER antlr3BaseRecognizerNew (ANTLR3_UINT32 type, ANTLR3_UINT32 sizeHint, pANTLR3_RECOGNIZER_SHARED_STATE state); +ANTLR3_API void antlr3RecognitionExceptionNew (pANTLR3_BASE_RECOGNIZER recognizer); +ANTLR3_API void antlr3MTExceptionNew (pANTLR3_BASE_RECOGNIZER recognizer); +ANTLR3_API void antlr3MTNExceptionNew (pANTLR3_BASE_RECOGNIZER recognizer); +ANTLR3_API pANTLR3_HASH_TABLE antlr3HashTableNew (ANTLR3_UINT32 sizeHint); +ANTLR3_API ANTLR3_UINT32 antlr3Hash (void * key, ANTLR3_UINT32 keylen); +ANTLR3_API pANTLR3_HASH_ENUM antlr3EnumNew (pANTLR3_HASH_TABLE table); +ANTLR3_API pANTLR3_LIST antlr3ListNew (ANTLR3_UINT32 sizeHint); +ANTLR3_API pANTLR3_VECTOR_FACTORY antlr3VectorFactoryNew (ANTLR3_UINT32 sizeHint); +ANTLR3_API pANTLR3_VECTOR antlr3VectorNew (ANTLR3_UINT32 sizeHint); +ANTLR3_API pANTLR3_STACK antlr3StackNew (ANTLR3_UINT32 sizeHint); +ANTLR3_API void antlr3SetVectorApi (pANTLR3_VECTOR vector, ANTLR3_UINT32 sizeHint); +ANTLR3_API ANTLR3_UCHAR antlr3c8toAntlrc (ANTLR3_INT8 inc); +ANTLR3_API pANTLR3_TOPO antlr3TopoNew(); + +ANTLR3_API pANTLR3_EXCEPTION antlr3ExceptionNew (ANTLR3_UINT32 exception, void * name, void * message, ANTLR3_BOOLEAN freeMessage); + + +ANTLR3_API pANTLR3_INPUT_STREAM antlr3FileStreamNew (pANTLR3_UINT8 fileName, ANTLR3_UINT32 encoding); +ANTLR3_API pANTLR3_INPUT_STREAM antlr3StringStreamNew (pANTLR3_UINT8 data, ANTLR3_UINT32 encoding, ANTLR3_UINT32 size, pANTLR3_UINT8 name); + +ANTLR3_API pANTLR3_INT_STREAM antlr3IntStreamNew (void); + +ANTLR3_API pANTLR3_STRING_FACTORY antlr3StringFactoryNew (ANTLR3_UINT32 encoding); + +ANTLR3_API pANTLR3_COMMON_TOKEN antlr3CommonTokenNew (ANTLR3_UINT32 ttype); +ANTLR3_API pANTLR3_TOKEN_FACTORY antlr3TokenFactoryNew (pANTLR3_INPUT_STREAM input); +ANTLR3_API void antlr3SetTokenAPI (pANTLR3_COMMON_TOKEN token); + +ANTLR3_API pANTLR3_LEXER antlr3LexerNewStream (ANTLR3_UINT32 sizeHint, pANTLR3_INPUT_STREAM input, pANTLR3_RECOGNIZER_SHARED_STATE state); +ANTLR3_API pANTLR3_LEXER antlr3LexerNew (ANTLR3_UINT32 sizeHint, pANTLR3_RECOGNIZER_SHARED_STATE state); +ANTLR3_API pANTLR3_PARSER antlr3ParserNewStreamDbg (ANTLR3_UINT32 sizeHint, pANTLR3_TOKEN_STREAM tstream, pANTLR3_DEBUG_EVENT_LISTENER dbg, pANTLR3_RECOGNIZER_SHARED_STATE state); +ANTLR3_API pANTLR3_PARSER antlr3ParserNewStream (ANTLR3_UINT32 sizeHint, pANTLR3_TOKEN_STREAM tstream, pANTLR3_RECOGNIZER_SHARED_STATE state); +ANTLR3_API pANTLR3_PARSER antlr3ParserNew (ANTLR3_UINT32 sizeHint, pANTLR3_RECOGNIZER_SHARED_STATE state); + +ANTLR3_API pANTLR3_COMMON_TOKEN_STREAM antlr3CommonTokenStreamSourceNew (ANTLR3_UINT32 hint, pANTLR3_TOKEN_SOURCE source); +ANTLR3_API pANTLR3_COMMON_TOKEN_STREAM antlr3CommonTokenStreamNew (ANTLR3_UINT32 hint); +ANTLR3_API pANTLR3_COMMON_TOKEN_STREAM antlr3CommonTokenDebugStreamSourceNew (ANTLR3_UINT32 hint, pANTLR3_TOKEN_SOURCE source, pANTLR3_DEBUG_EVENT_LISTENER debugger); + +ANTLR3_API pANTLR3_BASE_TREE_ADAPTOR ANTLR3_TREE_ADAPTORNew (pANTLR3_STRING_FACTORY strFactory); +ANTLR3_API pANTLR3_BASE_TREE_ADAPTOR ANTLR3_TREE_ADAPTORDebugNew (pANTLR3_STRING_FACTORY strFactory, pANTLR3_DEBUG_EVENT_LISTENER debugger); +ANTLR3_API pANTLR3_COMMON_TREE antlr3CommonTreeNew (void); +ANTLR3_API pANTLR3_COMMON_TREE antlr3CommonTreeNewFromTree (pANTLR3_COMMON_TREE tree); +ANTLR3_API pANTLR3_COMMON_TREE antlr3CommonTreeNewFromToken (pANTLR3_COMMON_TOKEN tree); +ANTLR3_API pANTLR3_ARBORETUM antlr3ArboretumNew (pANTLR3_STRING_FACTORY factory); +ANTLR3_API void antlr3SetCTAPI (pANTLR3_COMMON_TREE tree); +ANTLR3_API pANTLR3_BASE_TREE antlr3BaseTreeNew (pANTLR3_BASE_TREE tree); + +ANTLR3_API void antlr3BaseTreeAdaptorInit (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_DEBUG_EVENT_LISTENER debugger); + +ANTLR3_API pANTLR3_TREE_PARSER antlr3TreeParserNewStream (ANTLR3_UINT32 sizeHint, pANTLR3_COMMON_TREE_NODE_STREAM ctnstream, pANTLR3_RECOGNIZER_SHARED_STATE state); + +ANTLR3_API ANTLR3_INT32 antlr3dfaspecialTransition (void * ctx, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_INT_STREAM is, pANTLR3_CYCLIC_DFA dfa, ANTLR3_INT32 s); +ANTLR3_API ANTLR3_INT32 antlr3dfaspecialStateTransition (void * ctx, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_INT_STREAM is, pANTLR3_CYCLIC_DFA dfa, ANTLR3_INT32 s); +ANTLR3_API ANTLR3_INT32 antlr3dfapredict (void * ctx, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_INT_STREAM is, pANTLR3_CYCLIC_DFA cdfa); + +ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3CommonTreeNodeStreamNewTree (pANTLR3_BASE_TREE tree, ANTLR3_UINT32 hint); +ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3CommonTreeNodeStreamNew (pANTLR3_STRING_FACTORY strFactory, ANTLR3_UINT32 hint); +ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3UnbufTreeNodeStreamNewTree (pANTLR3_BASE_TREE tree, ANTLR3_UINT32 hint); +ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3UnbufTreeNodeStreamNew (pANTLR3_STRING_FACTORY strFactory, ANTLR3_UINT32 hint); +ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3CommonTreeNodeStreamNewStream (pANTLR3_COMMON_TREE_NODE_STREAM inStream); +ANTLR3_API pANTLR3_TREE_NODE_STREAM antlr3TreeNodeStreamNew (); +ANTLR3_API void fillBufferExt (pANTLR3_COMMON_TOKEN_STREAM tokenStream); + +ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM + antlr3RewriteRuleTOKENStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description); +ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM + antlr3RewriteRuleTOKENStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void * oneElement); +ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM + antlr3RewriteRuleTOKENStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector); + +ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM + antlr3RewriteRuleNODEStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description); +ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM + antlr3RewriteRuleNODEStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void * oneElement); +ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM + antlr3RewriteRuleNODEStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector); + +ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM + antlr3RewriteRuleSubtreeStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description); +ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM + antlr3RewriteRuleSubtreeStreamNewAEE(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void * oneElement); +ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM + antlr3RewriteRuleSubtreeStreamNewAEV(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector); + +ANTLR3_API pANTLR3_DEBUG_EVENT_LISTENER antlr3DebugListenerNew(); + +#ifdef __cplusplus +} +#endif + +#endif /* _ANTLR3DEFS_H */ diff --git a/antlr/libantlr3c-3.4/include/antlr3encodings.h b/antlr/libantlr3c-3.4/include/antlr3encodings.h new file mode 100644 index 0000000..f706735 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3encodings.h @@ -0,0 +1,38 @@ +#ifndef _ANTLR3_ENCODINGS_H +#define _ANTLR3_ENCODINGS_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + + + +#endif + diff --git a/antlr/libantlr3c-3.4/include/antlr3errors.h b/antlr/libantlr3c-3.4/include/antlr3errors.h new file mode 100644 index 0000000..4419ee3 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3errors.h @@ -0,0 +1,53 @@ +#ifndef _ANTLR3ERRORS_H +#define _ANTLR3ERRORS_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#define ANTLR3_SUCCESS 0 +#define ANTLR3_FAIL 1 + +#define ANTLR3_TRUE 1 +#define ANTLR3_FALSE 0 + +/** Indicates end of character stream and is an invalid Unicode code point. */ +#define ANTLR3_CHARSTREAM_EOF 0xFFFFFFFF + +/** Indicates memoizing on a rule failed. + */ +#define MEMO_RULE_FAILED 0xFFFFFFFE +#define MEMO_RULE_UNKNOWN 0xFFFFFFFF + + +#define ANTLR3_ERR_BASE 0 +#define ANTLR3_ERR_NOMEM (ANTLR3_ERR_BASE + 1) +#define ANTLR3_ERR_NOFILE (ANTLR3_ERR_BASE + 2) +#define ANTLR3_ERR_HASHDUP (ANTLR3_ERR_BASE + 3) + +#endif /* _ANTLR3ERRORS_H */ diff --git a/antlr/libantlr3c-3.4/include/antlr3exception.h b/antlr/libantlr3c-3.4/include/antlr3exception.h new file mode 100644 index 0000000..8fab8da --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3exception.h @@ -0,0 +1,218 @@ +/** \file + * Contains the definition of a basic ANTLR3 exception structure created + * by a recognizer when errors are found/predicted. + */ +#ifndef _ANTLR3_EXCEPTION_H +#define _ANTLR3_EXCEPTION_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +/** Indicates that the recognizer received a token + * in the input that was not predicted. + */ +#define ANTLR3_RECOGNITION_EXCEPTION 1 + +/** Name of exception #ANTLR3_RECOGNITION_EXCEPTION + */ +#define ANTLR3_RECOGNITION_EX_NAME "org.antlr.runtime.RecognitionException" + +/** Indicates that the recognizer was expecting one token and found a + * a different one. + */ +#define ANTLR3_MISMATCHED_TOKEN_EXCEPTION 2 + +/** Name of #ANTLR3_MISMATCHED_TOKEN_EXCEPTION + */ +#define ANTLR3_MISMATCHED_EX_NAME "org.antlr.runtime.MismatchedTokenException" + +/** Recognizer could not find a valid alternative from the input + */ +#define ANTLR3_NO_VIABLE_ALT_EXCEPTION 3 + +/** Name of #ANTLR3_NO_VIABLE_ALT_EXCEPTION + */ +#define ANTLR3_NO_VIABLE_ALT_NAME "org.antlr.runtime.NoViableAltException" + +/* Character in a set was not found + */ +#define ANTLR3_MISMATCHED_SET_EXCEPTION 4 + +/* Name of #ANTLR3_MISMATCHED_SET_EXCEPTION + */ +#define ANTLR3_MISMATCHED_SET_NAME "org.antlr.runtime.MismatchedSetException" + +/* A rule predicting at least n elements found less than that, + * such as: WS: " "+; + */ +#define ANTLR3_EARLY_EXIT_EXCEPTION 5 + +/* Name of #ANTLR3_EARLY_EXIT_EXCEPTION + */ +#define ANTLR3_EARLY_EXIT_NAME "org.antlr.runtime.EarlyExitException" + +#define ANTLR3_FAILED_PREDICATE_EXCEPTION 6 +#define ANTLR3_FAILED_PREDICATE_NAME "org.antlr.runtime.FailedPredicateException" + +#define ANTLR3_MISMATCHED_TREE_NODE_EXCEPTION 7 +#define ANTLR3_MISMATCHED_TREE_NODE_NAME "org.antlr.runtime.MismatchedTreeNodeException" + +#define ANTLR3_REWRITE_EARLY_EXCEPTION 8 +#define ANTLR3_REWRITE_EARLY_EXCEPTION_NAME "org.antlr.runtime.tree.RewriteEarlyExitException" + +#define ANTLR3_UNWANTED_TOKEN_EXCEPTION 9 +#define ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME "org.antlr.runtime.UnwantedTokenException" + +#define ANTLR3_MISSING_TOKEN_EXCEPTION 10 +#define ANTLR3_MISSING_TOKEN_EXCEPTION_NAME "org.antlr.runtime.MissingTokenException" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Base structure for an ANTLR3 exception tracker + */ +typedef struct ANTLR3_EXCEPTION_struct +{ + /// Set to one of the exception type defines: + /// + /// - #ANTLR3_RECOGNITION_EXCEPTION + /// - #ANTLR3_MISMATCHED_TOKEN_EXCEPTION + /// - #ANTLR3_NO_VIABLE_ALT_EXCEPTION + /// - #ANTLR3_MISMATCHED_SET_EXCEPTION + /// - #ANTLR3_EARLY_EXIT_EXCEPTION + /// - #ANTLR3_FAILED_PREDICATE_EXCEPTION + /// - #ANTLR3_EARLY_EXIT_EXCEPTION + /// + ANTLR3_UINT32 type; + + /** The string name of the exception + */ + void * name; + + /** The printable message that goes with this exception, in your preferred + * encoding format. ANTLR just uses ASCII by default but you can ignore these + * messages or convert them to another format or whatever of course. They are + * really internal messages that you then decide how to print out in a form that + * the users of your product will understand, as they are unlikely to know what + * to do with "Recognition exception at: [[TOK_GERUND..... " ;-) + */ + void * message; + + /** Name of the file/input source for reporting. Note that this may be NULL!! + */ + pANTLR3_STRING streamName; + + /** If set to ANTLR3_TRUE, this indicates that the message element of this structure + * should be freed by calling ANTLR3_FREE() when the exception is destroyed. + */ + ANTLR3_BOOLEAN freeMessage; + + /** Indicates the index of the 'token' we were looking at when the + * exception occurred. + */ + ANTLR3_MARKER index; + + /** Indicates what the current token/tree was when the error occurred. Since not + * all input streams will be able to retrieve the nth token, we track it here + * instead. This is for parsers, and even tree parsers may set this. + */ + void * token; + + /** Indicates the token we were expecting to see next when the error occurred + */ + ANTLR3_UINT32 expecting; + + /** Indicates a set of tokens that we were expecting to see one of when the + * error occurred. It is a following bitset list, so you can use load it and use ->toIntList() on it + * to generate an array of integer tokens that it represents. + */ + pANTLR3_BITSET_LIST expectingSet; + + /** If this is a tree parser exception then the node is set to point to the node + * that caused the issue. + */ + void * node; + + /** The current character when an error occurred - for lexers. + */ + ANTLR3_UCHAR c; + + /** Track the line at which the error occurred in case this is + * generated from a lexer. We need to track this since the + * unexpected char doesn't carry the line info. + */ + ANTLR3_UINT32 line; + + /** Character position in the line where the error occurred. + */ + ANTLR3_INT32 charPositionInLine; + + /** decision number for NVE + */ + ANTLR3_UINT32 decisionNum; + + /** State for NVE + */ + ANTLR3_UINT32 state; + + /** Rule name for failed predicate exception + */ + void * ruleName; + + /** Pointer to the next exception in the chain (if any) + */ + struct ANTLR3_EXCEPTION_struct * nextException; + + /** Pointer to the input stream that this exception occurred in. + */ + pANTLR3_INT_STREAM input; + + /** Pointer for you, the programmer to add anything you like to an exception. + */ + void * custom; + + /** Pointer to a routine that is called to free the custom exception structure + * when the exception is destroyed. Set to NULL if nothing should be done. + */ + void (*freeCustom) (void * custom); + void (*print) (struct ANTLR3_EXCEPTION_struct * ex); + void (*freeEx) (struct ANTLR3_EXCEPTION_struct * ex); + +} + ANTLR3_EXCEPTION; + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3filestream.h b/antlr/libantlr3c-3.4/include/antlr3filestream.h new file mode 100644 index 0000000..b06eb45 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3filestream.h @@ -0,0 +1,50 @@ +#ifndef _ANTLR3_FILESTREAM_H +#define _ANTLR3_FILESTREAM_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +ANTLR3_API ANTLR3_FDSC antlr3Fopen (pANTLR3_UINT8 filename, const char * mode); +ANTLR3_API void antlr3Fclose (ANTLR3_FDSC fd); + +ANTLR3_API ANTLR3_UINT32 antlr3Fsize (pANTLR3_UINT8 filename); +ANTLR3_API ANTLR3_UINT32 antlr3read8Bit (pANTLR3_INPUT_STREAM input, pANTLR3_UINT8 fileName); +ANTLR3_API ANTLR3_UINT32 antlr3Fread (ANTLR3_FDSC fdsc, ANTLR3_UINT32 count, void * data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3input.h b/antlr/libantlr3c-3.4/include/antlr3input.h new file mode 100644 index 0000000..3b01ae6 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3input.h @@ -0,0 +1,281 @@ +/** \file + * Defines the basic structures used to manipulate character + * streams from any input source. Any character size and encoding + * can in theory be used, so long as a set of functinos is provided that + * can return a 32 bit Integer representation of their characters amd efficiently mark and revert + * to specific offsets into their input streams. + */ +#ifndef _ANTLR3_INPUT_H +#define _ANTLR3_INPUT_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + + +/// Master context structure for an ANTLR3 C runtime based input stream. +/// \ingroup apistructures +/// +typedef struct ANTLR3_INPUT_STREAM_struct +{ + /** Interfaces that provide streams must all provide + * a generic ANTLR3_INT_STREAM interface and an ANTLR3_INPUT_STREAM + * is no different. + */ + pANTLR3_INT_STREAM istream; + + /** Whatever super structure is providing the INPUT stream needs a pointer to itself + * so that this can be passed back to it whenever the api functions + * are called back from this interface. + */ + void * super; + + /** Pointer the start of the input string, characters may be + * taken as offsets from here and in original input format encoding. + */ + void * data; + + /** Indicates if the data pointer was allocated by us, and so should be freed + * when the stream dies. + */ + int isAllocated; + + /** String factory for this input stream + */ + pANTLR3_STRING_FACTORY strFactory; + + + /** Pointer to the next character to be consumed from the input data + * This is cast to point at the encoding of the original file that + * was read by the functions installed as pointer in this input stream + * context instance at file/string/whatever load time. + */ + void * nextChar; + + /** Number of characters that can be consumed at this point in time. + * Mostly this is just what is left in the pre-read buffer, but if the + * input source is a stream such as a socket or something then we may + * call special read code to wait for more input. + */ + ANTLR3_UINT32 sizeBuf; + + /** The line number we are traversing in the input file. This gets incremented + * by a newline() call in the lexer grammar actions. + */ + ANTLR3_UINT32 line; + + /** Pointer into the input buffer where the current line + * started. + */ + void * currentLine; + + /** The offset within the current line of the current character + */ + ANTLR3_INT32 charPositionInLine; + + /** Tracks how deep mark() calls are nested + */ + ANTLR3_UINT32 markDepth; + + /** List of mark() points in the input stream + */ + pANTLR3_VECTOR markers; + + /** File name string, set to pointer to memory if + * you set it manually as it will be free()d + */ + pANTLR3_STRING fileName; + + /** File number, needs to be set manually to some file index of your devising. + */ + ANTLR3_UINT32 fileNo; + + /* API */ + + + /** Pointer to function that closes the input stream + */ + void (*close) (struct ANTLR3_INPUT_STREAM_struct * input); + void (*free) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to function that resets the input stream + */ + void (*reset) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to a function that reuses and resets an input stream by + * supplying a new 'source' + */ + void (*reuse) (struct ANTLR3_INPUT_STREAM_struct * input, pANTLR3_UINT8 inString, ANTLR3_UINT32 size, pANTLR3_UINT8 name); + + /** + * Pointer to function that installs a version of LA that always + * returns upper case. Only valid for character streams and creates a case + * insensitive lexer if the lexer tokens are described in upper case. The + * tokens will preserve case in the token text. + */ + void (*setUcaseLA) (pANTLR3_INPUT_STREAM input, ANTLR3_BOOLEAN flag); + + /** Pointer to function to return input stream element at 1 based + * offset from nextChar. Same as _LA for char stream, but token + * streams etc. have one of these that does other stuff of course. + */ + void * (*_LT) (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_INT32 lt); + + /** Pointer to function to return the total size of the input buffer. For streams + * this may be just the total we have available so far. This means of course that + * the input stream must be careful to accumulate enough input so that any backtracking + * can be satisfied. + */ + ANTLR3_UINT32 (*size) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to function to return a substring of the input stream. String is returned in allocated + * memory and is in same encoding as the input stream itself, NOT internal ANTLR3_UCHAR form. + */ + pANTLR3_STRING (*substr) (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_MARKER start, ANTLR3_MARKER stop); + + /** Pointer to function to return the current line number in the input stream + */ + ANTLR3_UINT32 (*getLine) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to function to return the current line buffer in the input stream + * The pointer returned is directly into the input stream so you must copy + * it if you wish to manipulate it without damaging the input stream. Encoding + * is obviously in the same form as the input stream. + * \remark + * - Note taht this function wil lbe inaccurate if setLine is called as there + * is no way at the moment to position the input stream at a particular line + * number offset. + */ + void * (*getLineBuf) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to function to return the current offset in the current input stream line + */ + ANTLR3_UINT32 (*getCharPositionInLine) (struct ANTLR3_INPUT_STREAM_struct * input); + + /** Pointer to function to set the current line number in the input stream + */ + void (*setLine) (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 line); + + /** Pointer to function to set the current position in the current line. + */ + void (*setCharPositionInLine) (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 position); + + /** Pointer to function to override the default newline character that the input stream + * looks for to trigger the line/offset and line buffer recording information. + * \remark + * - By default the chracter '\n' will be installed as the newline trigger character. When this + * character is seen by the consume() function then the current line number is incremented and the + * current line offset is reset to 0. The Pointer for the line of input we are consuming + * is updated to point to the next character after this one in the input stream (which means it + * may become invalid if the last newline character in the file is seen (so watch out). + * - If for some reason you do not want the counters and pointers to be restee, you can set the + * chracter to some impossible character such as '\0' or whatever. + * - This is a single character only, so choose the last character in a sequence of two or more. + * - This is only a simple aid to error reporting - if you have a complicated binary input structure + * it may not be adequate, but you can always override every function in the input stream with your + * own of course, and can even write your own complete input stream set if you like. + * - It is your responsiblity to set a valid character for the input stream type. There is no point + * setting this to 0xFFFFFFFF if the input stream is 8 bit ASCII, as this will just be truncated and never + * trigger as the comparison will be (INT32)0xFF == (INT32)0xFFFFFFFF + */ + void (*SetNewLineChar) (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 newlineChar); + + /// Character that automatically causes an internal line count + /// increment. + /// + ANTLR3_UCHAR newlineChar; + + /// Indicates the size, in 8 bit units, of a single character. Note that + /// the C runtime does not deal with surrogates as this would be + /// slow and complicated. If this is a UTF-8 stream then this field + /// will be set to 0. Generally you are best working internally with 32 bit characters + /// as this is the most efficient. + /// + ANTLR3_UINT8 charByteSize; + + /// Indicates the encoding scheme used in this input stream + /// + ANTLR3_UINT32 encoding; +} + + ANTLR3_INPUT_STREAM; + + +/** \brief Structure for track lex input states as part of mark() + * and rewind() of lexer. + */ +typedef struct ANTLR3_LEX_STATE_struct +{ + /** Pointer to the next character to be consumed from the input data + * This is cast to point at the encoding of the original file that + * was read by the functions installed as pointer in this input stream + * context instance at file/string/whatever load time. + */ + void * nextChar; + + /** The line number we are traversing in the input file. This gets incremented + * by a newline() call in the lexer grammer actions. + */ + ANTLR3_UINT32 line; + + /** Pointer into the input buffer where the current line + * started. + */ + void * currentLine; + + /** The offset within the current line of the current character + */ + ANTLR3_INT32 charPositionInLine; + +} + ANTLR3_LEX_STATE; + +/* Prototypes + */ +void antlr38BitSetupStream (pANTLR3_INPUT_STREAM input); +void antlr3UTF16SetupStream (pANTLR3_INPUT_STREAM input, ANTLR3_BOOLEAN machineBigEndian, ANTLR3_BOOLEAN inputBigEndian); +void antlr3UTF32SetupStream (pANTLR3_INPUT_STREAM input, ANTLR3_BOOLEAN machineBigEndian, ANTLR3_BOOLEAN inputBigEndian); +void antlr3UTF8SetupStream (pANTLR3_INPUT_STREAM input); +void antlr3EBCDICSetupStream (pANTLR3_INPUT_STREAM input); +void antlr3GenericSetupStream (pANTLR3_INPUT_STREAM input); +#ifdef __cplusplus +} +#endif + +#endif /* _ANTLR3_INPUT_H */ diff --git a/antlr/libantlr3c-3.4/include/antlr3interfaces.h b/antlr/libantlr3c-3.4/include/antlr3interfaces.h new file mode 100644 index 0000000..160e04d --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3interfaces.h @@ -0,0 +1,239 @@ +/** \file + * Declarations for all the antlr3 C runtime interfaces/classes. This + * allows the structures that define the interfaces to contain pointers to + * each other without trying to sort out the cyclic interdependencies that + * would otherwise result. + */ +#ifndef _ANTLR3_INTERFACES_H +#define _ANTLR3_INTERFACES_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_INT_STREAM_struct *pANTLR3_INT_STREAM; + +/// Pointer to an instantiation of the 'class' #ANTLR3_BASE_RECOGNIZER +/// \ingroup ANTLR3_BASE_RECOGNIZER +/// +typedef struct ANTLR3_BASE_RECOGNIZER_struct *pANTLR3_BASE_RECOGNIZER; +/// Pointer to an instantiation of 'class' #ANTLR3_RECOGNIZER_SHARED_STATE +/// \ingroup ANTLR3_RECOGNIZER_SHARED_STATE +/// +typedef struct ANTLR3_RECOGNIZER_SHARED_STATE_struct *pANTLR3_RECOGNIZER_SHARED_STATE; + +/// Pointer to an instantiation of 'class' #ANTLR3_BITSET_LIST +/// \ingroup ANTLR3_BITSET_LIST +/// +typedef struct ANTLR3_BITSET_LIST_struct *pANTLR3_BITSET_LIST; + +/// Pointer to an instantiation of 'class' #ANTLR3_BITSET +/// \ingroup ANTLR3_BITSET +/// +typedef struct ANTLR3_BITSET_struct *pANTLR3_BITSET; + +/// Pointer to an instantiation of 'class' #ANTLR3_TOKEN_FACTORY +/// \ingroup ANTLR3_TOKEN_FACTORY +/// +typedef struct ANTLR3_TOKEN_FACTORY_struct *pANTLR3_TOKEN_FACTORY; +/// Pointer to an instantiation of 'class' #ANTLR3_COMMON_TOKEN +/// \ingroup ANTLR3_COMMON_TOKEN +/// +typedef struct ANTLR3_COMMON_TOKEN_struct *pANTLR3_COMMON_TOKEN; + +/// Pointer to an instantiation of 'class' #ANTLR3_EXCEPTION +/// \ingroup ANTLR3_EXCEPTION +/// +typedef struct ANTLR3_EXCEPTION_struct *pANTLR3_EXCEPTION; + +/// Pointer to an instantiation of 'class' #ANTLR3_HASH_BUCKET +/// \ingroup ANTLR3_HASH_BUCKET +/// +typedef struct ANTLR3_HASH_BUCKET_struct *pANTLR3_HASH_BUCKET; +/// Pointer to an instantiation of 'class' #ANTLR3_HASH_ENTRY +/// \ingroup ANTLR3_HASH_ENTRY +/// +typedef struct ANTLR3_HASH_ENTRY_struct *pANTLR3_HASH_ENTRY; +/// Pointer to an instantiation of 'class' #ANTLR3_HASH_ENUM +/// \ingroup ANTLR3_HASH_ENUM +/// +typedef struct ANTLR3_HASH_ENUM_struct *pANTLR3_HASH_ENUM; +/// Pointer to an instantiation of 'class' #ANTLR3_HASH_TABLE +/// \ingroup ANTLR3_HASH_TABLE +/// +typedef struct ANTLR3_HASH_TABLE_struct *pANTLR3_HASH_TABLE; + +/// Pointer to an instantiation of 'class' #ANTLR3_LIST +/// \ingroup ANTLR3_LIST +/// +typedef struct ANTLR3_LIST_struct *pANTLR3_LIST; +/// Pointer to an instantiation of 'class' #ANTLR3_VECTOR_FACTORY +/// \ingroup ANTLR3_VECTOR_FACTORY +/// +typedef struct ANTLR3_VECTOR_FACTORY_struct *pANTLR3_VECTOR_FACTORY; +/// Pointer to an instantiation of 'class' #ANTLR3_VECTOR +/// \ingroup ANTLR3_VECTOR +/// +typedef struct ANTLR3_VECTOR_struct *pANTLR3_VECTOR; +/// Pointer to an instantiation of 'class' #ANTLR3_STACK +/// \ingroup ANTLR3_STACK +/// +typedef struct ANTLR3_STACK_struct *pANTLR3_STACK; + +/// Pointer to an instantiation of 'class' #ANTLR3_TOPO +/// \ingroup ANTLR3_TOPO +/// +typedef struct ANTLR3_TOPO_struct *pANTLR3_TOPO; + +/// Pointer to an instantiation of 'class' #ANTLR3_INPUT_STREAM +/// \ingroup ANTLR3_INPUT_STREAM +/// +typedef struct ANTLR3_INPUT_STREAM_struct *pANTLR3_INPUT_STREAM; +/// Pointer to an instantiation of 'class' #ANTLR3_LEX_STATE +/// \ingroup ANTLR3_LEX_STATE +/// +typedef struct ANTLR3_LEX_STATE_struct *pANTLR3_LEX_STATE; + +/// Pointer to an instantiation of 'class' #ANTLR3_STRING_FACTORY +/// \ingroup ANTLR3_STRING_FACTORY +/// +typedef struct ANTLR3_STRING_FACTORY_struct *pANTLR3_STRING_FACTORY; +/// Pointer to an instantiation of 'class' #ANTLR3_STRING +/// \ingroup ANTLR3_STRING +/// +typedef struct ANTLR3_STRING_struct *pANTLR3_STRING; + +/// Pointer to an instantiation of 'class' #ANTLR3_TOKEN_SOURCE +/// \ingroup ANTLR3_TOKEN_SOURCE +/// +typedef struct ANTLR3_TOKEN_SOURCE_struct *pANTLR3_TOKEN_SOURCE; +/// Pointer to an instantiation of 'class' #ANTLR3_TOKEN_STREAM +/// \ingroup ANTLR3_TOKEN_STREAM +/// +typedef struct ANTLR3_TOKEN_STREAM_struct *pANTLR3_TOKEN_STREAM; +/// Pointer to an instantiation of 'class' #ANTLR3_COMMON_TOKEN_STREAM +/// \ingroup ANTLR3_COMMON_TOKEN_STREAM +/// +typedef struct ANTLR3_COMMON_TOKEN_STREAM_struct *pANTLR3_COMMON_TOKEN_STREAM; + +/// Pointer to an instantiation of 'class' #ANTLR3_CYCLIC_DFA +/// \ingroup ANTLR3_CYCLIC_DFA +/// +typedef struct ANTLR3_CYCLIC_DFA_struct *pANTLR3_CYCLIC_DFA; + +/// Pointer to an instantiation of 'class' #ANTLR3_LEXER +/// \ingroup ANTLR3_LEXER +/// +typedef struct ANTLR3_LEXER_struct *pANTLR3_LEXER; +/// Pointer to an instantiation of 'class' #ANTLR3_PARSER +/// \ingroup ANTLR3_PARSER +/// +typedef struct ANTLR3_PARSER_struct *pANTLR3_PARSER; + +/// Pointer to an instantiation of 'class' #ANTLR3_BASE_TREE +/// \ingroup ANTLR3_BASE_TREE +/// +typedef struct ANTLR3_BASE_TREE_struct *pANTLR3_BASE_TREE; +/// Pointer to an instantiation of 'class' #ANTLR3_COMMON_TREE +/// \ingroup ANTLR3_COMMON_TREE +/// +typedef struct ANTLR3_COMMON_TREE_struct *pANTLR3_COMMON_TREE; +/// Pointer to an instantiation of 'class' #ANTLR3_ARBORETUM +/// \ingroup ANTLR3_ARBORETUM +/// +typedef struct ANTLR3_ARBORETUM_struct *pANTLR3_ARBORETUM; +/// Pointer to an instantiation of 'class' #ANTLR3_PARSE_TREE +/// \ingroup ANTLR3_PARSE_TREE +/// +typedef struct ANTLR3_PARSE_TREE_struct *pANTLR3_PARSE_TREE; + +/// Pointer to an instantiation of 'class' #ANTLR3_TREE_NODE_STREAM +/// \ingroup ANTLR3_TREE_NODE_STREAM +/// +typedef struct ANTLR3_TREE_NODE_STREAM_struct *pANTLR3_TREE_NODE_STREAM; +/// Pointer to an instantiation of 'class' #ANTLR3_COMMON_TREE_NODE_STREAM +/// \ingroup ANTLR3_COMMON_TREE_NODE_STREAM +/// +typedef struct ANTLR3_COMMON_TREE_NODE_STREAM_struct *pANTLR3_COMMON_TREE_NODE_STREAM; +/// Pointer to an instantiation of 'class' #ANTLR3_TREE_WALK_STATE +/// \ingroup ANTLR3_TREE_WALK_STATE +/// +typedef struct ANTLR3_TREE_WALK_STATE_struct *pANTLR3_TREE_WALK_STATE; + +/// Pointer to an instantiation of 'class' #ANTLR3_BASE_TREE_ADAPTOR +/// \ingroup ANTLR3_BASE_TREE_ADAPTOR +/// +typedef struct ANTLR3_BASE_TREE_ADAPTOR_struct *pANTLR3_BASE_TREE_ADAPTOR; +/// Pointer to an instantiation of 'class' #ANTLR3_COMMON_TREE_ADAPTOR +/// \ingroup ANTLR3_COMMON_TREE_ADAPTOR +/// +typedef struct ANTLR3_COMMON_TREE_ADAPTOR_struct *pANTLR3_COMMON_TREE_ADAPTOR; + +/// Pointer to an instantiation of 'class' #ANTLR3_TREE_PARSER +/// \ingroup ANTLR3_TREE_PARSER +/// +typedef struct ANTLR3_TREE_PARSER_struct *pANTLR3_TREE_PARSER; + +/// Pointer to an instantiation of 'class' #ANTLR3_INT_TRIE +/// \ingroup ANTLR3_INT_TRIE +/// +typedef struct ANTLR3_INT_TRIE_struct *pANTLR3_INT_TRIE; + +/// Pointer to an instantiation of 'class' #ANTLR3_REWRITE_RULE_ELEMENT_STREAM +/// \ingroup ANTLR3_REWRITE_RULE_ELEMENT_STREAM +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *pANTLR3_REWRITE_RULE_ELEMENT_STREAM; +/// Pointer to an instantiation of 'class' #ANTLR3_REWRITE_RULE_ELEMENT_STREAM +/// \ingroup ANTLR3_REWRITE_RULE_ELEMENT_STREAM +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *pANTLR3_REWRITE_RULE_TOKEN_STREAM; + +/// Pointer to an instantiation of 'class' #ANTLR3_REWRITE_RULE_SUBSTREE_STREAM +/// \ingroup ANTLR3_REWRITE_RULE_SUBTREE_STREAM +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *pANTLR3_REWRITE_RULE_SUBTREE_STREAM; + +/// Pointer to an instantiation of 'class' #ANTLR3_REWRITE_RULE_NODE_STREAM +/// \ingroup ANTLR3_REWRITE_RULE_NODE_STREAM +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *pANTLR3_REWRITE_RULE_NODE_STREAM; + +/// Pointer to an instantiation of 'class' #ANTLR3_DEBUG_EVENT_LISTENER +/// \ingroup ANTLR3_DEBUG_EVENT_LISTENER +/// +typedef struct ANTLR3_DEBUG_EVENT_LISTENER_struct *pANTLR3_DEBUG_EVENT_LISTENER; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3intstream.h b/antlr/libantlr3c-3.4/include/antlr3intstream.h new file mode 100644 index 0000000..21bac5b --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3intstream.h @@ -0,0 +1,205 @@ +/** \file + * Defines the the class interface for an antlr3 INTSTREAM. + * + * Certain functionality (such as DFAs for instance) abstract the stream of tokens + * or characters in to a steam of integers. Hence this structure should be included + * in any stream that is able to provide the output as a stream of integers (which is anything + * basically. + * + * There are no specific implementations of the methods in this interface in general. Though + * for purposes of casting and so on, it may be necesssary to implement a function with + * the signature in this interface which abstracts the base immplementation. In essence though + * the base stream provides a pointer to this interface, within which it installs its + * normal match() functions and so on. Interaces such as DFA are then passed the pANTLR3_INT_STREAM + * and can treat any input as an int stream. + * + * For instance, a lexer implements a pANTLR3_BASE_RECOGNIZER, within which there is a pANTLR3_INT_STREAM. + * However, a pANTLR3_INPUT_STREAM also provides a pANTLR3_INT_STREAM, which it has constructed from + * it's normal interface when it was created. This is then pointed at by the pANTLR_BASE_RECOGNIZER + * when it is intialized with a pANTLR3_INPUT_STREAM. + * + * Similarly if a pANTLR3_BASE_RECOGNIZER is initialized with a pANTLR3_TOKEN_STREAM, then the + * pANTLR3_INT_STREAM is taken from the pANTLR3_TOKEN_STREAM. + * + * If a pANTLR3_BASE_RECOGNIZER is initialized with a pANTLR3_TREENODE_STREAM, then guess where + * the pANTLR3_INT_STREAM comes from? + * + * Note that because the context pointer points to the actual interface structure that is providing + * the ANTLR3_INT_STREAM it is defined as a (void *) in this interface. There is no direct implementation + * of an ANTLR3_INT_STREAM (unless someone did not understand what I was doing here =;?P + */ +#ifndef _ANTLR3_INTSTREAM_H +#define _ANTLR3_INTSTREAM_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +/** Type indicator for a character stream + * \remark if a custom stream is created but it can be treated as + * a char stream, then you may OR in this value to your type indicator + */ +#define ANTLR3_CHARSTREAM 0x0001 + +/** Type indicator for a Token stream + * \remark if a custom stream is created but it can be treated as + * a token stream, then you may OR in this value to your type indicator + */ +#define ANTLR3_TOKENSTREAM 0x0002 + +/** Type indicator for a common tree node stream + * \remark if a custom stream is created but it can be treated as + * a common tree node stream, then you may OR in this value to your type indicator + */ +#define ANTLR3_COMMONTREENODE 0x0004 + +/** Type mask for input stream so we can switch in the above types + * \remark DO NOT USE 0x0000 as a stream type! + */ +#define ANTLR3_INPUT_MASK 0x0007 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_INT_STREAM_struct +{ + /** Input stream type indicator. Sometimes useful for error reporting etc. + */ + ANTLR3_UINT32 type; + + /** Potentially useful in error reporting and so on, this string is + * an identification of the input source. It may be NULL, so anything + * attempting to access it needs to check this and substitute a sensible + * default. + */ + pANTLR3_STRING streamName; + + /** Pointer to the super structure that contains this interface. This + * will usually be a token stream or a tree stream. + */ + void * super; + + /** Last marker position allocated + */ + ANTLR3_MARKER lastMarker; + + // Return a string that identifies the input source + // + pANTLR3_STRING (*getSourceName) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** Consume the next 'ANTR3_UINT32' in the stream + */ + void (*consume) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** Get ANTLR3_UINT32 at current input pointer + i ahead where i=1 is next ANTLR3_UINT32 + */ + ANTLR3_UINT32 (*_LA) (struct ANTLR3_INT_STREAM_struct * intStream, ANTLR3_INT32 i); + + /** Tell the stream to start buffering if it hasn't already. Return + * current input position, index(), or some other marker so that + * when passed to rewind() you get back to the same spot. + * rewind(mark()) should not affect the input cursor. + */ + ANTLR3_MARKER (*mark) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** Return the current input symbol index 0..n where n indicates the + * last symbol has been read. + */ + ANTLR3_MARKER (*index) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** Reset the stream so that next call to index would return marker. + * The marker will usually be index() but it doesn't have to be. It's + * just a marker to indicate what state the stream was in. This is + * essentially calling release() and seek(). If there are markers + * created after this marker argument, this routine must unroll them + * like a stack. Assume the state the stream was in when this marker + * was created. + */ + void (*rewind) (struct ANTLR3_INT_STREAM_struct * intStream, ANTLR3_MARKER marker); + + /** Reset the stream to the last marker position, witouh destryoing the + * last marker position. + */ + void (*rewindLast) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** You may want to commit to a backtrack but don't want to force the + * stream to keep bookkeeping objects around for a marker that is + * no longer necessary. This will have the same behavior as + * rewind() except it releases resources without the backward seek. + */ + void (*release) (struct ANTLR3_INT_STREAM_struct * intStream, ANTLR3_MARKER mark); + + /** Set the input cursor to the position indicated by index. This is + * normally used to seek ahead in the input stream. No buffering is + * required to do this unless you know your stream will use seek to + * move backwards such as when backtracking. + * + * This is different from rewind in its multi-directional + * requirement and in that its argument is strictly an input cursor (index). + * + * For char streams, seeking forward must update the stream state such + * as line number. For seeking backwards, you will be presumably + * backtracking using the mark/rewind mechanism that restores state and + * so this method does not need to update state when seeking backwards. + * + * Currently, this method is only used for efficient backtracking, but + * in the future it may be used for incremental parsing. + */ + void (*seek) (struct ANTLR3_INT_STREAM_struct * intStream, ANTLR3_MARKER index); + + /** Only makes sense for streams that buffer everything up probably, but + * might be useful to display the entire stream or for testing. + */ + ANTLR3_UINT32 (*size) (struct ANTLR3_INT_STREAM_struct * intStream); + + /** Because the indirect call, though small in individual cases can + * mount up if there are thousands of tokens (very large input streams), callers + * of size can optionally use this cached size field. + */ + ANTLR3_UINT32 cachedSize; + + /** Frees any resources that were allocated for the implementation of this + * interface. Usually this is just releasing the memory allocated + * for the structure itself, but it may of course do anything it need to + * so long as it does not stamp on anything else. + */ + void (*free) (struct ANTLR3_INT_STREAM_struct * stream); + +} + ANTLR3_INT_STREAM; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/antlr/libantlr3c-3.4/include/antlr3lexer.h b/antlr/libantlr3c-3.4/include/antlr3lexer.h new file mode 100644 index 0000000..6cc10ef --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3lexer.h @@ -0,0 +1,193 @@ +/** \file + * Base interface for any ANTLR3 lexer. + * + * An ANLTR3 lexer builds from two sets of components: + * + * - The runtime components that provide common functionality such as + * traversing character streams, building tokens for output and so on. + * - The generated rules and struutre of the actual lexer, which call upon the + * runtime components. + * + * A lexer class contains a character input stream, a base recognizer interface + * (which it will normally implement) and a token source interface (which it also + * implements. The Tokensource interface is called by a token consumer (such as + * a parser, but in theory it can be anything that wants a set of abstract + * tokens in place of a raw character stream. + * + * So then, we set up a lexer in a sequence akin to: + * + * - Create a character stream (something which implements ANTLR3_INPUT_STREAM) + * and initialize it. + * - Create a lexer interface and tell it where it its input stream is. + * This will cause the creation of a base recognizer class, which it will + * override with its own implementations of some methods. The lexer creator + * can also then in turn override anything it likes. + * - The lexer token source interface is then passed to some interface that + * knows how to use it, byte calling for a next token. + * - When a next token is called, let ze lexing begin. + * + */ +#ifndef _ANTLR3_LEXER +#define _ANTLR3_LEXER + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* Definitions + */ +#define ANTLR3_STRING_TERMINATOR 0xFFFFFFFF + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_LEXER_struct +{ + /** If there is a super structure that is implementing the + * lexer, then a pointer to it can be stored here in case + * implementing functions are overridden by this super structure. + */ + void * super; + + /** A generated lexer has an mTokens() function, which needs + * the context pointer of the generated lexer, not the base lexer interface + * this is stored here and initialized by the generated code (or manually + * if this is a manually built lexer. + */ + void * ctx; + + /** A pointer to the character stream whence this lexer is receiving + * characters. + * TODO: I may come back to this and implement charstream outside + * the input stream as per the java implementation. + */ + pANTLR3_INPUT_STREAM input; + + /** Pointer to the implementation of a base recognizer, which the lexer + * creates and then overrides with its own lexer oriented functions (the + * default implementation is parser oriented). This also contains a + * token source interface, which the lexer instance will provide to anything + * that needs it, which is anything else that implements a base recognizer, + * such as a parser. + */ + pANTLR3_BASE_RECOGNIZER rec; + + /** Pointer to a function that sets the charstream source for the lexer and + * causes it to be reset. + */ + void (*setCharStream) (struct ANTLR3_LEXER_struct * lexer, pANTLR3_INPUT_STREAM input); + + /** Pointer to a function that switches the current character input stream to + * a new one, saving the old one, which we will revert to at the end of this + * new one. + */ + void (*pushCharStream) (struct ANTLR3_LEXER_struct * lexer, pANTLR3_INPUT_STREAM input); + + /** Pointer to a function that abandons the current input stream, whether it + * is empty or not and reverts to the previous stacked input stream. + */ + void (*popCharStream) (struct ANTLR3_LEXER_struct * lexer); + + /** Pointer to a function that emits the supplied token as the next token in + * the stream. + */ + void (*emitNew) (struct ANTLR3_LEXER_struct * lexer, pANTLR3_COMMON_TOKEN token); + + /** Pointer to a function that constructs a new token from the lexer stored information + */ + pANTLR3_COMMON_TOKEN (*emit) (struct ANTLR3_LEXER_struct * lexer); + + /** Pointer to the user provided (either manually or through code generation + * function that causes the lexer rules to run the lexing rules and produce + * the next token if there iss one. This is called from nextToken() in the + * pANTLR3_TOKEN_SOURCE. Note that the input parameter for this funciton is + * the generated lexer context (stored in ctx in this interface) it is a generated + * function and expects the context to be the generated lexer. + */ + void (*mTokens) (void * ctx); + + /** Pointer to a function that attempts to match and consume the specified string from the input + * stream. Note that strings muse be passed as terminated arrays of ANTLR3_UCHAR. Strings are terminated + * with 0xFFFFFFFF, which is an invalid UTF32 character + */ + ANTLR3_BOOLEAN (*matchs) (struct ANTLR3_LEXER_struct * lexer, ANTLR3_UCHAR * string); + + /** Pointer to a function that matches and consumes the specified character from the input stream. + * The input stream is required to provide characters via LA() as UTF32 characters. The default lexer + * implementation is source encoding agnostic and so input streams do not generally need to + * override the default implmentation. + */ + ANTLR3_BOOLEAN (*matchc) (struct ANTLR3_LEXER_struct * lexer, ANTLR3_UCHAR c); + + /** Pointer to a function that matches any character in the supplied range (I suppose it could be a token range too + * but this would only be useful if the tokens were in tsome guaranteed order which is + * only going to happen with a hand crafted token set). + */ + ANTLR3_BOOLEAN (*matchRange) (struct ANTLR3_LEXER_struct * lexer, ANTLR3_UCHAR low, ANTLR3_UCHAR high); + + /** Pointer to a function that matches the next token/char in the input stream + * regardless of what it actaully is. + */ + void (*matchAny) (struct ANTLR3_LEXER_struct * lexer); + + /** Pointer to a function that recovers from an error found in the input stream. + * Generally, this will be a #ANTLR3_EXCEPTION_NOVIABLE_ALT but it could also + * be from a mismatched token that the (*match)() could not recover from. + */ + void (*recover) (struct ANTLR3_LEXER_struct * lexer); + + /** Pointer to function to return the current line number in the input stream + */ + ANTLR3_UINT32 (*getLine) (struct ANTLR3_LEXER_struct * lexer); + ANTLR3_MARKER (*getCharIndex) (struct ANTLR3_LEXER_struct * lexer); + ANTLR3_UINT32 (*getCharPositionInLine)(struct ANTLR3_LEXER_struct * lexer); + + /** Pointer to function to return the text so far for the current token being generated + */ + pANTLR3_STRING (*getText) (struct ANTLR3_LEXER_struct * lexer); + + + /** Pointer to a function that knows how to free the resources of a lexer + */ + void (*free) (struct ANTLR3_LEXER_struct * lexer); + +} + ANTLR3_LEXER; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3memory.h b/antlr/libantlr3c-3.4/include/antlr3memory.h new file mode 100644 index 0000000..5e2d4c9 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3memory.h @@ -0,0 +1,36 @@ +#ifndef _ANTLR3MEMORY_H +#define _ANTLR3MEMORY_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + + +#endif /* _ANTLR3MEMORY_H */ diff --git a/antlr/libantlr3c-3.4/include/antlr3parser.h b/antlr/libantlr3c-3.4/include/antlr3parser.h new file mode 100644 index 0000000..95b7d18 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3parser.h @@ -0,0 +1,93 @@ +/** \file + * Base implementation of an ANTLR3 parser. + * + * + */ +#ifndef _ANTLR3_PARSER_H +#define _ANTLR3_PARSER_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** This is the main interface for an ANTLR3 parser. + */ +typedef struct ANTLR3_PARSER_struct +{ + /** All superstructure implementers of this interface require a pointer to their selves, + * which they can reference using the super pointer here. + */ + void * super; + + /** A pointer to the base recognizer, where most of the parser functions actually + * live because they are shared between parser and tree parser and this is the + * easier way than copying the interface all over the place. Macros hide this + * for the generated code so it is easier on the eye (though not the debugger ;-). + */ + pANTLR3_BASE_RECOGNIZER rec; + + /** A provider of a tokenstream interface, for the parser to consume + * tokens from. + */ + pANTLR3_TOKEN_STREAM tstream; + + /** A pointer to a function that installs a debugger object (it also + * installs the debugging versions of the parser methods. This means that + * a non debug parser incurs no overhead because of the debugging stuff. + */ + void (*setDebugListener) (struct ANTLR3_PARSER_struct * parser, pANTLR3_DEBUG_EVENT_LISTENER dbg); + + /** A pointer to a function that installs a token stream + * for the parser. + */ + void (*setTokenStream) (struct ANTLR3_PARSER_struct * parser, pANTLR3_TOKEN_STREAM); + + /** A pointer to a function that returns the token stream for this + * parser. + */ + pANTLR3_TOKEN_STREAM (*getTokenStream) (struct ANTLR3_PARSER_struct * parser); + + /** Pointer to a function that knows how to free resources of an ANTLR3 parser. + */ + void (*free) (struct ANTLR3_PARSER_struct * parser); + +} + ANTLR3_PARSER; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3parsetree.h b/antlr/libantlr3c-3.4/include/antlr3parsetree.h new file mode 100644 index 0000000..0e8c157 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3parsetree.h @@ -0,0 +1,85 @@ +/** \file + * Abstraction of Common tree to provide payload and string representation of node. + * + * \todo May not need this in the end + */ + +#ifndef ANTLR3_PARSETREE_H +#define ANTLR3_PARSETREE_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANTLR3_PARSE_TREE_struct +{ + /** Any interface that implements methods in this interface + * may need to point back to itself using this pointer to its + * super structure. + */ + void * super; + + /** The payload that the parse tree node passes around + */ + void * payload; + + /** An encapsulated BASE TREE strcuture (NOT a pointer) + * that perfoms a lot of the dirty work of node management + */ + ANTLR3_BASE_TREE baseTree; + + /** How to dup this node + */ + pANTLR3_BASE_TREE (*dupNode) (struct ANTLR3_PARSE_TREE_struct * tree); + + /** Return the type of this node + */ + ANTLR3_UINT32 (*getType) (struct ANTLR3_PARSE_TREE_struct * tree); + + /** Return the string representation of the payload (must be installed + * when the payload is added and point to a function that knwos how to + * manifest a pANTLR3_STRING from a node. + */ + pANTLR3_STRING (*toString) (struct ANTLR3_PARSE_TREE_struct * payload); + + void (*free) (struct ANTLR3_PARSE_TREE_struct * tree); + +} + ANTLR3_PARSE_TREE; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3recognizersharedstate.h b/antlr/libantlr3c-3.4/include/antlr3recognizersharedstate.h new file mode 100644 index 0000000..9e024d8 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3recognizersharedstate.h @@ -0,0 +1,218 @@ +/** \file + * While the C runtime does not need to model the state of + * multiple lexers and parsers in the same way as the Java runtime does + * it is no overhead to reflect that model. In fact the + * C runtime has always been able to share recognizer state. + * + * This 'class' therefore defines all the elements of a recognizer + * (either lexer, parser or tree parser) that are need to + * track the current recognition state. Multiple recognizers + * may then share this state, for instance when one grammar + * imports another. + */ + +#ifndef _ANTLR3_RECOGNIZER_SHARED_STATE_H +#define _ANTLR3_RECOGNIZER_SHARED_STATE_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** All the data elements required to track the current state + * of any recognizer (lexer, parser, tree parser). + * May be share between multiple recognizers such that + * grammar inheritance is easily supported. + */ +typedef struct ANTLR3_RECOGNIZER_SHARED_STATE_struct +{ + /** If set to ANTLR3_TRUE then the recognizer has an exception + * condition (this is tested by the generated code for the rules of + * the grammar). + */ + ANTLR3_BOOLEAN error; + + /** Points to the first in a possible chain of exceptions that the + * recognizer has discovered. + */ + pANTLR3_EXCEPTION exception; + + /** Track around a hint from the creator of the recognizer as to how big this + * thing is going to get, as the actress said to the bishop. This allows us + * to tune hash tables accordingly. This might not be the best place for this + * in the end but we will see. + */ + ANTLR3_UINT32 sizeHint; + + /** Track the set of token types that can follow any rule invocation. + * Stack structure, to support: List. + */ + pANTLR3_STACK following; + + + /** This is true when we see an error and before having successfully + * matched a token. Prevents generation of more than one error message + * per error. + */ + ANTLR3_BOOLEAN errorRecovery; + + /** The index into the input stream where the last error occurred. + * This is used to prevent infinite loops where an error is found + * but no token is consumed during recovery...another error is found, + * ad nauseam. This is a failsafe mechanism to guarantee that at least + * one token/tree node is consumed for two errors. + */ + ANTLR3_MARKER lastErrorIndex; + + /** In lieu of a return value, this indicates that a rule or token + * has failed to match. Reset to false upon valid token match. + */ + ANTLR3_BOOLEAN failed; + + /** When the recognizer terminates, the error handling functions + * will have incremented this value if any error occurred (that was displayed). It can then be + * used by the grammar programmer without having to use static globals. + */ + ANTLR3_UINT32 errorCount; + + /** If 0, no backtracking is going on. Safe to exec actions etc... + * If >0 then it's the level of backtracking. + */ + ANTLR3_INT32 backtracking; + + /** ANTLR3_VECTOR of ANTLR3_LIST for rule memoizing. + * Tracks the stop token index for each rule. ruleMemo[ruleIndex] is + * the memoization table for ruleIndex. For key ruleStartIndex, you + * get back the stop token for associated rule or MEMO_RULE_FAILED. + * + * This is only used if rule memoization is on. + */ + pANTLR3_INT_TRIE ruleMemo; + + /** Pointer to an array of token names + * that are generally useful in error reporting. The generated parsers install + * this pointer. The table it points to is statically allocated as 8 bit ascii + * at parser compile time - grammar token names are thus restricted in character + * sets, which does not seem to terrible. + */ + pANTLR3_UINT8 * tokenNames; + + /** User programmable pointer that can be used for instance as a place to + * store some tracking structure specific to the grammar that would not normally + * be available to the error handling functions. + */ + void * userp; + + /** The goal of all lexer rules/methods is to create a token object. + * This is an instance variable as multiple rules may collaborate to + * create a single token. For example, NUM : INT | FLOAT ; + * In this case, you want the INT or FLOAT rule to set token and not + * have it reset to a NUM token in rule NUM. + */ + pANTLR3_COMMON_TOKEN token; + + /** The goal of all lexer rules being to create a token, then a lexer + * needs to build a token factory to create them. + */ + pANTLR3_TOKEN_FACTORY tokFactory; + + /** A lexer is a source of tokens, produced by all the generated (or + * hand crafted if you like) matching rules. As such it needs to provide + * a token source interface implementation. + */ + pANTLR3_TOKEN_SOURCE tokSource; + + /** The channel number for the current token + */ + ANTLR3_UINT32 channel; + + /** The token type for the current token + */ + ANTLR3_UINT32 type; + + /** The input line (where it makes sense) on which the first character of the current + * token resides. + */ + ANTLR3_INT32 tokenStartLine; + + /** The character position of the first character of the current token + * within the line specified by tokenStartLine + */ + ANTLR3_INT32 tokenStartCharPositionInLine; + + /** What character index in the stream did the current token start at? + * Needed, for example, to get the text for current token. Set at + * the start of nextToken. + */ + ANTLR3_MARKER tokenStartCharIndex; + + /** Text for the current token. This can be overridden by setting this + * variable directly or by using the SETTEXT() macro (preferred) in your + * lexer rules. + */ + pANTLR3_STRING text; + + /** User controlled variables that will be installed in a newly created + * token. + */ + ANTLR3_UINT32 user1, user2, user3; + void * custom; + + /** Input stream stack, which allows the C programmer to switch input streams + * easily and allow the standard nextToken() implementation to deal with it + * as this is a common requirement. + */ + pANTLR3_STACK streams; + + /// A stack of token/tree rewrite streams that are available for use + /// by a parser or tree parser that is using rewrites to generate + /// an AST. This saves each rule in the recongizer from having to + /// allocate and deallocate rewtire streams on entry and exit. As + /// the parser recurses throgh the rules it will reach a steady state + /// of the maximum number of allocated streams, which instead of + /// deallocating them at rule exit, it will place on this stack for + /// reuse. The streams are then all finally freed when this stack + /// is freed. + /// + pANTLR3_VECTOR rStreams; + +} + ANTLR3_RECOGNIZER_SHARED_STATE; + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/antlr/libantlr3c-3.4/include/antlr3rewritestreams.h b/antlr/libantlr3c-3.4/include/antlr3rewritestreams.h new file mode 100644 index 0000000..bf83fe9 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3rewritestreams.h @@ -0,0 +1,180 @@ +#ifndef ANTLR3REWRITESTREAM_H +#define ANTLR3REWRITESTREAM_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// A generic list of elements tracked in an alternative to be used in +/// a -> rewrite rule. +/// +/// In the C implementation, all tree oriented streams return a pointer to +/// the same type: pANTLR3_BASE_TREE. Anything that has subclassed from this +/// still passes this type, within which there is a super pointer, which points +/// to it's own data and methods. Hence we do not need to implement this as +/// the equivalent of an abstract class, but just fill in the appropriate interface +/// as usual with this model. +/// +/// Once you start next()ing, do not try to add more elements. It will +/// break the cursor tracking I believe. +/// +/// +/// \see #pANTLR3_REWRITE_RULE_NODE_STREAM +/// \see #pANTLR3_REWRITE_RULE_ELEMENT_STREAM +/// \see #pANTLR3_REWRITE_RULE_SUBTREE_STREAM +/// +/// TODO: add mechanism to detect/puke on modification after reading from stream +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct +{ + + /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(), + /// which bumps it to 1 meaning no more elements. + /// + ANTLR3_UINT32 cursor; + + /// Track single elements w/o creating a list. Upon 2nd add, alloc list + /// + void * singleElement; + + /// The list of tokens or subtrees we are tracking + /// + pANTLR3_VECTOR elements; + + /// Indicates whether we should free the vector or it was supplied to us + /// + ANTLR3_BOOLEAN freeElements; + + /// The element or stream description; usually has name of the token or + /// rule reference that this list tracks. Can include rulename too, but + /// the exception would track that info. + /// + void * elementDescription; + + /// Pointer to the tree adaptor in use for this stream + /// + pANTLR3_BASE_TREE_ADAPTOR adaptor; + + /// Once a node / subtree has been used in a stream, it must be dup'ed + /// from then on. Streams are reset after sub rules so that the streams + /// can be reused in future sub rules. So, reset must set a dirty bit. + /// If dirty, then next() always returns a dup. + /// + ANTLR3_BOOLEAN dirty; + + // Pointer to the recognizer shared state to which this stream belongs + // + pANTLR3_BASE_RECOGNIZER rec; + + // Methods + + /// Reset the condition of this stream so that it appears we have + /// not consumed any of its elements. Elements themselves are untouched. + /// + void (*reset) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + /// Add a new pANTLR3_BASE_TREE to this stream + /// + void (*add) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void *el, void (ANTLR3_CDECL *freePtr)(void *)); + + /// Return the next element in the stream. If out of elements, throw + /// an exception unless size()==1. If size is 1, then return elements[0]. + /// + void * (*next) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + pANTLR3_BASE_TREE (*nextTree) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + void * (*nextToken) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + void * (*_next) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + /// When constructing trees, sometimes we need to dup a token or AST + /// subtree. Dup'ing a token means just creating another AST node + /// around it. For trees, you must call the adaptor.dupTree(). + /// + void * (*dup) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el); + + /// Ensure stream emits trees; tokens must be converted to AST nodes. + /// AST nodes can be passed through unmolested. + /// + pANTLR3_BASE_TREE (*toTree) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el); + + /// Returns ANTLR3_TRUE if there is a next element available + /// + ANTLR3_BOOLEAN (*hasNext) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + /// Treat next element as a single node even if it's a subtree. + /// This is used instead of next() when the result has to be a + /// tree root node. Also prevents us from duplicating recently-added + /// children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration + /// must dup the type node, but ID has been added. + /// + /// Referencing to a rule result twice is ok; dup entire tree as + /// we can't be adding trees; e.g., expr expr. + /// + pANTLR3_BASE_TREE (*nextNode) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + /// Number of elements available in the stream + /// + ANTLR3_UINT32 (*size) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + /// Returns the description string if there is one available (check for NULL). + /// + void * (*getDescription) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + + void (*free) (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); + +} + ANTLR3_REWRITE_RULE_ELEMENT_STREAM; + +/// This is an implementation of a token stream, which is basically an element +/// stream that deals with tokens only. +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_TOKEN_STREAM; + +/// This is an implementation of a subtree stream which is a set of trees +/// modelled as an element stream. +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_SUBTREE_STREAM; + +/// This is an implementation of a node stream, which is basically an element +/// stream that deals with tree nodes only. +/// +typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_NODE_STREAM; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3string.h b/antlr/libantlr3c-3.4/include/antlr3string.h new file mode 100644 index 0000000..4a96e76 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3string.h @@ -0,0 +1,272 @@ +/** \file + * Simple string interface allows indiscriminate allocation of strings + * such that they can be allocated all over the place and released in + * one chunk via a string factory - saves lots of hassle in remembering what + * strings were allocated where. + */ +#ifndef _ANTLR3_STRING_H +#define _ANTLR3_STRING_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Base string class tracks the allocations and provides simple string + * tracking functions. Mostly you can work directly on the string for things + * that don't reallocate it, like strchr() etc. Perhaps someone will want to provide implementations for UTF8 + * and so on. + */ +typedef struct ANTLR3_STRING_struct +{ + + /** The factory that created this string + */ + pANTLR3_STRING_FACTORY factory; + + /** Pointer to the current string value (starts at NULL unless + * the string allocator is told to create it with a pre known size. + */ + pANTLR3_UINT8 chars; + + /** Current length of the string up to and not including, the trailing '\0' + * Note that the actual allocation (->size) + * is always at least one byte more than this to accommodate trailing '\0' + */ + ANTLR3_UINT32 len; + + /** Current size of the string in bytes including the trailing '\0' + */ + ANTLR3_UINT32 size; + + /** Index of string (allocation number) in case someone wants + * to explicitly release it. + */ + ANTLR3_UINT32 index; + + /** Occasionally it is useful to know what the encoding of the string + * actually is, hence it is stored here as one the ANTLR3_ENCODING_ values + */ + ANTLR3_UINT8 encoding; + + /** Pointer to function that sets the string value to a specific string in the default encoding + * for this string. For instance, if this is 8 bit, then this function is the same as set8 + * but if the encoding is UTF16, then the pointer is assumed to point to UTF16 characters, not + * 8 bit. + */ + pANTLR3_UINT8 (*set) (struct ANTLR3_STRING_struct * string, const char * chars); + + /** Pointer to function that sets the string value to a specific 8 bit string in the default encoding + * for this string. For instance, if this is an 8 bit string, then this function is the same as set8 + * but if the encoding is UTF16, then the pointer is assumed to point to 8 bit characters that must + * be converted to UTF16 characters on the fly. + */ + pANTLR3_UINT8 (*set8) (struct ANTLR3_STRING_struct * string, const char * chars); + + /** Pointer to function adds a raw char * type pointer in the default encoding + * for this string. For instance, if this is 8 bit, then this function is the same as append8 + * but if the encoding is UTF16, then the pointer is assumed to point to UTF16 characters not + * 8 bit. + */ + pANTLR3_UINT8 (*append) (struct ANTLR3_STRING_struct * string, const char * newbit); + + /** Pointer to function adds a raw char * type pointer in the default encoding + * for this string. For instance, if this is a UTF16 string, then this function assumes the pointer + * points to 8 bit characters that must be converted on the fly. + */ + pANTLR3_UINT8 (*append8) (struct ANTLR3_STRING_struct * string, const char * newbit); + + /** Pointer to function that inserts the supplied string at the specified + * offset in the current string in the default encoding for this string. For instance, if this is an 8 + * bit string, then this is the same as insert8, but if this is a UTF16 string, then the pointer + * must point to UTF16 characters. + */ + pANTLR3_UINT8 (*insert) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, const char * newbit); + + /** Pointer to function that inserts the supplied string at the specified + * offset in the current string in the default encoding for this string. For instance, if this is a UTF16 string + * then the pointer is assumed to point at 8 bit characteres that must be converted on the fly. + */ + pANTLR3_UINT8 (*insert8) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, const char * newbit); + + /** Pointer to function that sets the string value to a copy of the supplied string (strings must be in the + * same encoding. + */ + pANTLR3_UINT8 (*setS) (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * chars); + + /** Pointer to function appends a copy of the characters contained in another string. Strings must be in the + * same encoding. + */ + pANTLR3_UINT8 (*appendS) (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * newbit); + + /** Pointer to function that inserts a copy of the characters in the supplied string at the specified + * offset in the current string. strings must be in the same encoding. + */ + pANTLR3_UINT8 (*insertS) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, struct ANTLR3_STRING_struct * newbit); + + /** Pointer to function that inserts the supplied integer in string form at the specified + * offset in the current string. + */ + pANTLR3_UINT8 (*inserti) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, ANTLR3_INT32 i); + + /** Pointer to function that adds a single character to the end of the string, in the encoding of the + * string - 8 bit, UTF16, utf-8 etc. Input is a single UTF32 (32 bits wide integer) character. + */ + pANTLR3_UINT8 (*addc) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 c); + + /** Pointer to function that adds the stringified representation of an integer + * to the string. + */ + pANTLR3_UINT8 (*addi) (struct ANTLR3_STRING_struct * string, ANTLR3_INT32 i); + + /** Pointer to function that compares the text of a string to the supplied + * 8 bit character string and returns a result a la strcmp() + */ + ANTLR3_UINT32 (*compare8) (struct ANTLR3_STRING_struct * string, const char * compStr); + + /** Pointer to a function that compares the text of a string with the supplied character string + * (which is assumed to be in the same encoding as the string itself) and returns a result + * a la strcmp() + */ + ANTLR3_UINT32 (*compare) (struct ANTLR3_STRING_struct * string, const char * compStr); + + /** Pointer to a function that compares the text of a string with the supplied string + * (which is assumed to be in the same encoding as the string itself) and returns a result + * a la strcmp() + */ + ANTLR3_UINT32 (*compareS) (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * compStr); + + /** Pointer to a function that returns the character indexed at the supplied + * offset as a 32 bit character. + */ + ANTLR3_UCHAR (*charAt) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 offset); + + /** Pointer to a function that returns a substring of the supplied string a la .subString(s,e) + * in the Java language. + */ + struct ANTLR3_STRING_struct * + (*subString) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 startIndex, ANTLR3_UINT32 endIndex); + + /** Pointer to a function that returns the integer representation of any numeric characters + * at the beginning of the string + */ + ANTLR3_INT32 (*toInt32) (struct ANTLR3_STRING_struct * string); + + /** Pointer to a function that yields an 8 bit string regardless of the encoding of the supplied + * string. This is useful when you want to use the text of a token in some way that requires an 8 bit + * value, such as the key for a hashtable. The function is required to produce a usable string even + * if the text given as input has characters that do not fit in 8 bit space, it will replace them + * with some arbitrary character such as '?' + */ + struct ANTLR3_STRING_struct * + (*to8) (struct ANTLR3_STRING_struct * string); + + /// Pointer to a function that yields a UT8 encoded string of the current string, + /// regardless of the current encoding of the string. Because there is currently no UTF8 + /// handling in the string class, it creates therefore, a string that is useful only for read only + /// applications as it will not contain methods that deal with UTF8 at the moment. + /// + struct ANTLR3_STRING_struct * + (*toUTF8) (struct ANTLR3_STRING_struct * string); + +} + ANTLR3_STRING; + +/** Definition of the string factory interface, which creates and tracks + * strings for you of various shapes and sizes. + */ +typedef struct ANTLR3_STRING_FACTORY_struct +{ + /** List of all the strings that have been allocated by the factory + */ + pANTLR3_VECTOR strings; + + /* Index of next string that we allocate + */ + ANTLR3_UINT32 index; + + /** Pointer to function that manufactures an empty string + */ + pANTLR3_STRING (*newRaw) (struct ANTLR3_STRING_FACTORY_struct * factory); + + /** Pointer to function that manufactures a raw string with no text in it but space for size + * characters. + */ + pANTLR3_STRING (*newSize) (struct ANTLR3_STRING_FACTORY_struct * factory, ANTLR3_UINT32 size); + + /** Pointer to function that manufactures a string from a given pointer and length. The pointer is assumed + * to point to characters in the same encoding as the string type, hence if this is a UTF16 string the + * pointer should point to UTF16 characters. + */ + pANTLR3_STRING (*newPtr) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string, ANTLR3_UINT32 size); + + /** Pointer to function that manufactures a string from a given pointer and length. The pointer is assumed to + * point at 8 bit characters which must be converted on the fly to the encoding of the actual string. + */ + pANTLR3_STRING (*newPtr8) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string, ANTLR3_UINT32 size); + + /** Pointer to function that manufactures a string from a given pointer and works out the length. The pointer is + * assumed to point to characters in the same encoding as the string itself, i.e. UTF16 if a UTF16 + * string and so on. + */ + pANTLR3_STRING (*newStr) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string); + + /** Pointer to function that manufactures a string from a given pointer and length. The pointer should + * point to 8 bit characters regardless of the actual encoding of the string. The 8 bit characters + * will be converted to the actual string encoding on the fly. + */ + pANTLR3_STRING (*newStr8) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string); + + /** Pointer to function that deletes the string altogether + */ + void (*destroy) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_STRING string); + + /** Pointer to function that returns a copy of the string in printable form without any control + * characters in it. + */ + pANTLR3_STRING (*printable)(struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_STRING string); + + /** Pointer to function that closes the factory + */ + void (*close) (struct ANTLR3_STRING_FACTORY_struct * factory); + +} + ANTLR3_STRING_FACTORY; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/antlr/libantlr3c-3.4/include/antlr3tokenstream.h b/antlr/libantlr3c-3.4/include/antlr3tokenstream.h new file mode 100644 index 0000000..a5137ad --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3tokenstream.h @@ -0,0 +1,303 @@ +/** \file + * Defines the interface for an ANTLR3 common token stream. Custom token streams should create + * one of these and then override any functions by installing their own pointers + * to implement the various functions. + */ +#ifndef _ANTLR3_TOKENSTREAM_H +#define _ANTLR3_TOKENSTREAM_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Definition of a token source, which has a pointer to a function that + * returns the next token (using a token factory if it is going to be + * efficient) and a pointer to an ANTLR3_INPUT_STREAM. This is slightly + * different to the Java interface because we have no way to implement + * multiple interfaces without defining them in the interface structure + * or casting (void *), which is too convoluted. + */ +typedef struct ANTLR3_TOKEN_SOURCE_struct +{ + /** Pointer to a function that returns the next token in the stream. + */ + pANTLR3_COMMON_TOKEN (*nextToken)(struct ANTLR3_TOKEN_SOURCE_struct * tokenSource); + + /** Whoever is providing tokens, needs to provide a string factory too + */ + pANTLR3_STRING_FACTORY strFactory; + + /** A special pre-allocated token, which signifies End Of Tokens. Because this must + * be set up with the current input index and so on, we embed the structure and + * return the address of it. It is marked as factoryMade, so that it is never + * attempted to be freed. + */ + ANTLR3_COMMON_TOKEN eofToken; + + /// A special pre-allocated token, which is returned by mTokens() if the + /// lexer rule said to just skip the generated token altogether. + /// Having this single token stops us wasting memory by have the token factory + /// actually create something that we are going to SKIP(); anyway. + /// + ANTLR3_COMMON_TOKEN skipToken; + + /** Whatever is supplying the token source interface, needs a pointer to + * itself so that this pointer can be passed to it when the nextToken + * function is called. + */ + void * super; + + /** When the token source is constructed, it is populated with the file + * name from whence the tokens were produced by the lexer. This pointer is a + * copy of the one supplied by the CharStream (and may be NULL) so should + * not be manipulated other than to copy or print it. + */ + pANTLR3_STRING fileName; +} + ANTLR3_TOKEN_SOURCE; + +/** Definition of the ANTLR3 common token stream interface. + * \remark + * Much of the documentation for this interface is stolen from Ter's Java implementation. + */ +typedef struct ANTLR3_TOKEN_STREAM_struct +{ + /** Pointer to the token source for this stream + */ + pANTLR3_TOKEN_SOURCE tokenSource; + + /** Whatever is providing this interface needs a pointer to itself + * so that this can be passed back to it whenever the api functions + * are called. + */ + void * super; + + /** All input streams implement the ANTLR3_INT_STREAM interface... + */ + pANTLR3_INT_STREAM istream; + + /// Debugger interface, is this is a debugging token stream + /// + pANTLR3_DEBUG_EVENT_LISTENER debugger; + + /// Indicates the initial stream state for dbgConsume() + /// + ANTLR3_BOOLEAN initialStreamState; + + /** Get Token at current input pointer + i ahead where i=1 is next Token. + * i<0 indicates tokens in the past. So -1 is previous token and -2 is + * two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken. + * Return null for LT(0) and any index that results in an absolute address + * that is negative. + */ + pANTLR3_COMMON_TOKEN (*_LT) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, ANTLR3_INT32 k); + + /** Get a token at an absolute index i; 0..n-1. This is really only + * needed for profiling and debugging and token stream rewriting. + * If you don't want to buffer up tokens, then this method makes no + * sense for you. Naturally you can't use the rewrite stream feature. + * I believe DebugTokenStream can easily be altered to not use + * this method, removing the dependency. + */ + pANTLR3_COMMON_TOKEN (*get) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, ANTLR3_UINT32 i); + + /** Where is this stream pulling tokens from? This is not the name, but + * a pointer into an interface that contains a ANTLR3_TOKEN_SOURCE interface. + * The Token Source interface contains a pointer to the input stream and a pointer + * to a function that returns the next token. + */ + pANTLR3_TOKEN_SOURCE (*getTokenSource) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream); + + /** Function that installs a token source for teh stream + */ + void (*setTokenSource) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, + pANTLR3_TOKEN_SOURCE tokenSource); + + /** Return the text of all the tokens in the stream, as the old tramp in + * Leeds market used to say; "Get the lot!" + */ + pANTLR3_STRING (*toString) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream); + + /** Return the text of all tokens from start to stop, inclusive. + * If the stream does not buffer all the tokens then it can just + * return an empty ANTLR3_STRING or NULL; Grammars should not access $ruleLabel.text in + * an action in that case. + */ + pANTLR3_STRING (*toStringSS) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, ANTLR3_UINT32 start, ANTLR3_UINT32 stop); + + /** Because the user is not required to use a token with an index stored + * in it, we must provide a means for two token objects themselves to + * indicate the start/end location. Most often this will just delegate + * to the other toString(int,int). This is also parallel with + * the pTREENODE_STREAM->toString(Object,Object). + */ + pANTLR3_STRING (*toStringTT) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, pANTLR3_COMMON_TOKEN start, pANTLR3_COMMON_TOKEN stop); + + + /** Function that sets the token stream into debugging mode + */ + void (*setDebugListener) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream, pANTLR3_DEBUG_EVENT_LISTENER debugger); + + + + /** Function that knows how to free the memory for an ANTLR3_TOKEN_STREAM + */ + void (*free) (struct ANTLR3_TOKEN_STREAM_struct * tokenStream); +} + ANTLR3_TOKEN_STREAM; + +/** Common token stream is an implementation of ANTLR_TOKEN_STREAM for the default + * parsers and recognizers. You may of course build your own implementation if + * you are so inclined. + */ +typedef struct ANTLR3_COMMON_TOKEN_STREAM_struct +{ + /** The ANTLR3_TOKEN_STREAM interface implementation, which also includes + * the intstream implementation. We could duplicate the pANTLR_INT_STREAM + * in this interface and initialize it to a copy, but this could be confusing + * it just results in one more level of indirection and I think that with + * judicial use of 'const' later, the optimizer will do decent job. + */ + pANTLR3_TOKEN_STREAM tstream; + + /** Whatever is supplying the COMMON_TOKEN_STREAM needs a pointer to itself + * so that this can be accessed by any of the API functions which it implements. + */ + void * super; + + /** Records every single token pulled from the source indexed by the token index. + * There might be more efficient ways to do this, such as referencing directly in to + * the token factory pools, but for now this is convenient and the ANTLR3_LIST is not + * a huge overhead as it only stores pointers anyway, but allows for iterations and + * so on. + */ + pANTLR3_VECTOR tokens; + + /** Override map of tokens. If a token type has an entry in here, then + * the pointer in the table points to an int, being the override channel number + * that should always be used for this token type. + */ + pANTLR3_LIST channelOverrides; + + /** Discared set. If a token has an entry in this table, then it is thrown + * away (data pointer is always NULL). + */ + pANTLR3_LIST discardSet; + + /* The channel number that this token stream is tuned to. For instance, whitespace + * is usually tuned to channel 99, which no token stream would normally tune to and + * so it is thrown away. + */ + ANTLR3_UINT32 channel; + + /** If this flag is set to ANTLR3_TRUE, then tokens that the stream sees that are not + * in the channel that this stream is tuned to, are not tracked in the + * tokens table. When set to false, ALL tokens are added to the tracking. + */ + ANTLR3_BOOLEAN discardOffChannel; + + /** The index into the tokens list of the current token (the next one that will be + * consumed. p = -1 indicates that the token list is empty. + */ + ANTLR3_INT32 p; + + /** A simple filter mechanism whereby you can tell this token stream + * to force all tokens of type ttype to be on channel. For example, + * when interpreting, we cannot exec actions so we need to tell + * the stream to force all WS and NEWLINE to be a different, ignored + * channel. + */ + void (*setTokenTypeChannel) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, + ANTLR3_UINT32 ttype, ANTLR3_UINT32 channel); + + /** Add a particular token type to the discard set. If a token is found to belong + * to this set, then it is skipped/thrown away + */ + void (*discardTokenType) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, ANTLR3_INT32 ttype); + + /** Signal to discard off channel tokens from here on in. + */ + void (*discardOffChannelToks)(struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, ANTLR3_BOOLEAN discard); + + /** Function that returns a pointer to the ANTLR3_LIST of all tokens + * in the stream (this causes the buffer to fill if we have not get any yet) + */ + pANTLR3_VECTOR (*getTokens) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream); + + /** Function that returns all the tokens between a start and a stop index. + * TODO: This is a new list (Ack! Maybe this is a reason to have factories for LISTS and HASHTABLES etc :-( come back to this) + */ + pANTLR3_LIST (*getTokenRange) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, ANTLR3_UINT32 start, ANTLR3_UINT32 stop); + + /** Function that returns all the tokens indicated by the specified bitset, within a range of tokens + */ + pANTLR3_LIST (*getTokensSet) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, + ANTLR3_UINT32 start, ANTLR3_UINT32 stop, pANTLR3_BITSET types); + + /** Function that returns all the tokens indicated by being a member of the supplied List + */ + pANTLR3_LIST (*getTokensList) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, + ANTLR3_UINT32 start, ANTLR3_UINT32 stop, pANTLR3_LIST list); + + /** Function that returns all tokens of a certain type within a range. + */ + pANTLR3_LIST (*getTokensType) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream, + ANTLR3_UINT32 start, ANTLR3_UINT32 stop, ANTLR3_UINT32 type); + + /** Function that resets the token stream so that it can be reused, but + * but that does not free up any resources, such as the token factory + * the factory pool and so on. This prevents the need to keep freeing + * and reallocating the token pools if the thing you are building is + * a multi-shot dameon or somethign like that. It is much faster to + * just reuse all the vectors. + */ + void (*reset) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream); + + /** Function that knows how to free an ANTLR3_COMMON_TOKEN_STREAM + */ + void (*free) (struct ANTLR3_COMMON_TOKEN_STREAM_struct * tokenStream); +} + ANTLR3_COMMON_TOKEN_STREAM; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/antlr/libantlr3c-3.4/include/antlr3treeparser.h b/antlr/libantlr3c-3.4/include/antlr3treeparser.h new file mode 100644 index 0000000..8ee0e58 --- /dev/null +++ b/antlr/libantlr3c-3.4/include/antlr3treeparser.h @@ -0,0 +1,81 @@ +#ifndef ANTLR3TREEPARSER_H +#define ANTLR3TREEPARSER_H + +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Internal structure representing an element in a hash bucket. + * Stores the original key so that duplicate keys can be rejected + * if necessary, and contains function can be supported If the hash key + * could be unique I would have invented the perfect compression algorithm ;-) + */ +typedef struct ANTLR3_TREE_PARSER_struct +{ + /** Pointer to any super class + */ + void * super; + + /** A pointer to the base recognizer, where most of the parser functions actually + * live because they are shared between parser and tree parser and this is the + * easier way than copying the interface all over the place. Macros hide this + * for the generated code so it is easier on the eye (though not the debugger ;-). + */ + pANTLR3_BASE_RECOGNIZER rec; + + /** Pointer to the common tree node stream for the parser + */ + pANTLR3_COMMON_TREE_NODE_STREAM ctnstream; + + /** Set the input stream and reset the parser + */ + void (*setTreeNodeStream) (struct ANTLR3_TREE_PARSER_struct * parser, pANTLR3_COMMON_TREE_NODE_STREAM input); + + /** Return a pointer to the input stream + */ + pANTLR3_COMMON_TREE_NODE_STREAM (*getTreeNodeStream) (struct ANTLR3_TREE_PARSER_struct * parser); + + /** Pointer to a function that knows how to free resources of an ANTLR3 tree parser. + */ + void (*free) (struct ANTLR3_TREE_PARSER_struct * parser); +} + ANTLR3_TREE_PARSER; + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.3