--- /dev/null
+/** \file\r
+ * While the C runtime does not need to model the state of\r
+ * multiple lexers and parsers in the same way as the Java runtime does\r
+ * it is no overhead to reflect that model. In fact the\r
+ * C runtime has always been able to share recognizer state.\r
+ *\r
+ * This 'class' therefore defines all the elements of a recognizer\r
+ * (either lexer, parser or tree parser) that are need to\r
+ * track the current recognition state. Multiple recognizers\r
+ * may then share this state, for instance when one grammar\r
+ * imports another.\r
+ */\r
+\r
+#ifndef _ANTLR3_RECOGNIZER_SHARED_STATE_H\r
+#define _ANTLR3_RECOGNIZER_SHARED_STATE_H\r
+\r
+// [The "BSD licence"]\r
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
+// http://www.temporal-wave.com\r
+// http://www.linkedin.com/in/jimidle\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions\r
+// are met:\r
+// 1. Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+// 2. Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the distribution.\r
+// 3. The name of the author may not be used to endorse or promote products\r
+// derived from this software without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#include <antlr3defs.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/** All the data elements required to track the current state\r
+ * of any recognizer (lexer, parser, tree parser).\r
+ * May be share between multiple recognizers such that \r
+ * grammar inheritance is easily supported.\r
+ */\r
+typedef struct ANTLR3_RECOGNIZER_SHARED_STATE_struct\r
+{\r
+ /** If set to ANTLR3_TRUE then the recognizer has an exception\r
+ * condition (this is tested by the generated code for the rules of\r
+ * the grammar).\r
+ */\r
+ ANTLR3_BOOLEAN error;\r
+\r
+ /** Points to the first in a possible chain of exceptions that the\r
+ * recognizer has discovered.\r
+ */\r
+ pANTLR3_EXCEPTION exception;\r
+\r
+ /** Track around a hint from the creator of the recognizer as to how big this\r
+ * thing is going to get, as the actress said to the bishop. This allows us\r
+ * to tune hash tables accordingly. This might not be the best place for this\r
+ * in the end but we will see.\r
+ */\r
+ ANTLR3_UINT32 sizeHint;\r
+\r
+ /** Track the set of token types that can follow any rule invocation.\r
+ * Stack structure, to support: List<BitSet>.\r
+ */\r
+ pANTLR3_STACK following;\r
+\r
+\r
+ /** This is true when we see an error and before having successfully\r
+ * matched a token. Prevents generation of more than one error message\r
+ * per error.\r
+ */\r
+ ANTLR3_BOOLEAN errorRecovery;\r
+ \r
+ /** The index into the input stream where the last error occurred.\r
+ * This is used to prevent infinite loops where an error is found\r
+ * but no token is consumed during recovery...another error is found,\r
+ * ad nauseam. This is a failsafe mechanism to guarantee that at least\r
+ * one token/tree node is consumed for two errors.\r
+ */\r
+ ANTLR3_MARKER lastErrorIndex;\r
+\r
+ /** In lieu of a return value, this indicates that a rule or token\r
+ * has failed to match. Reset to false upon valid token match.\r
+ */\r
+ ANTLR3_BOOLEAN failed;\r
+\r
+ /** When the recognizer terminates, the error handling functions\r
+ * will have incremented this value if any error occurred (that was displayed). It can then be\r
+ * used by the grammar programmer without having to use static globals.\r
+ */\r
+ ANTLR3_UINT32 errorCount;\r
+\r
+ /** If 0, no backtracking is going on. Safe to exec actions etc...\r
+ * If >0 then it's the level of backtracking.\r
+ */\r
+ ANTLR3_INT32 backtracking;\r
+\r
+ /** ANTLR3_VECTOR of ANTLR3_LIST for rule memoizing.\r
+ * Tracks the stop token index for each rule. ruleMemo[ruleIndex] is\r
+ * the memoization table for ruleIndex. For key ruleStartIndex, you\r
+ * get back the stop token for associated rule or MEMO_RULE_FAILED.\r
+ *\r
+ * This is only used if rule memoization is on.\r
+ */\r
+ pANTLR3_INT_TRIE ruleMemo;\r
+\r
+ /** Pointer to an array of token names\r
+ * that are generally useful in error reporting. The generated parsers install\r
+ * this pointer. The table it points to is statically allocated as 8 bit ascii\r
+ * at parser compile time - grammar token names are thus restricted in character\r
+ * sets, which does not seem to terrible.\r
+ */\r
+ pANTLR3_UINT8 * tokenNames;\r
+\r
+ /** User programmable pointer that can be used for instance as a place to\r
+ * store some tracking structure specific to the grammar that would not normally\r
+ * be available to the error handling functions.\r
+ */\r
+ void * userp;\r
+\r
+ /** The goal of all lexer rules/methods is to create a token object.\r
+ * This is an instance variable as multiple rules may collaborate to\r
+ * create a single token. For example, NUM : INT | FLOAT ;\r
+ * In this case, you want the INT or FLOAT rule to set token and not\r
+ * have it reset to a NUM token in rule NUM.\r
+ */\r
+ pANTLR3_COMMON_TOKEN token;\r
+\r
+ /** The goal of all lexer rules being to create a token, then a lexer\r
+ * needs to build a token factory to create them.\r
+ */\r
+ pANTLR3_TOKEN_FACTORY tokFactory;\r
+\r
+ /** A lexer is a source of tokens, produced by all the generated (or\r
+ * hand crafted if you like) matching rules. As such it needs to provide\r
+ * a token source interface implementation.\r
+ */\r
+ pANTLR3_TOKEN_SOURCE tokSource;\r
+\r
+ /** The channel number for the current token\r
+ */\r
+ ANTLR3_UINT32 channel;\r
+\r
+ /** The token type for the current token\r
+ */\r
+ ANTLR3_UINT32 type;\r
+ \r
+ /** The input line (where it makes sense) on which the first character of the current\r
+ * token resides.\r
+ */\r
+ ANTLR3_INT32 tokenStartLine;\r
+\r
+ /** The character position of the first character of the current token\r
+ * within the line specified by tokenStartLine\r
+ */\r
+ ANTLR3_INT32 tokenStartCharPositionInLine;\r
+\r
+ /** What character index in the stream did the current token start at?\r
+ * Needed, for example, to get the text for current token. Set at\r
+ * the start of nextToken.\r
+ */\r
+ ANTLR3_MARKER tokenStartCharIndex;\r
+\r
+ /** Text for the current token. This can be overridden by setting this \r
+ * variable directly or by using the SETTEXT() macro (preferred) in your\r
+ * lexer rules.\r
+ */\r
+ pANTLR3_STRING text;\r
+\r
+ /** User controlled variables that will be installed in a newly created\r
+ * token.\r
+ */\r
+ ANTLR3_UINT32 user1, user2, user3;\r
+ void * custom;\r
+\r
+ /** Input stream stack, which allows the C programmer to switch input streams \r
+ * easily and allow the standard nextToken() implementation to deal with it\r
+ * as this is a common requirement.\r
+ */\r
+ pANTLR3_STACK streams;\r
+\r
+ /// A stack of token/tree rewrite streams that are available for use\r
+ /// by a parser or tree parser that is using rewrites to generate\r
+ /// an AST. This saves each rule in the recongizer from having to \r
+ /// allocate and deallocate rewtire streams on entry and exit. As\r
+ /// the parser recurses throgh the rules it will reach a steady state\r
+ /// of the maximum number of allocated streams, which instead of\r
+ /// deallocating them at rule exit, it will place on this stack for\r
+ /// reuse. The streams are then all finally freed when this stack\r
+ /// is freed.\r
+ ///\r
+ pANTLR3_VECTOR rStreams;\r
+\r
+}\r
+ ANTLR3_RECOGNIZER_SHARED_STATE;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+\r