Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
[The "BSD licence"]
Copyright (c) 2006, 2007 Kay Roepke 2010 Alan Condit
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.
*/
/*
* Template group file for the Objective C code generator.
* Heavily based on Java.stg
*
* Written by Kay Roepke
* Modified by Alan Condit
*
* This file is part of ANTLR and subject to the same license as ANTLR itself.
*/
group ObjC implements ANTLRCore;
objcTypeInitMap ::= [
"int" : "0", // Integers start out being 0
"long" : "0", // Longs start out being 0
"float" : "0.0", // Floats start out being 0
"double" : "0.0", // Doubles start out being 0
"BOOL" : "NO", // Booleans start out being Antlr ObjC for false
"byte" : "0", // Bytes start out being 0
"short" : "0", // Shorts start out being 0
"char" : "0", // Chars start out being 0
"id" : "nil", // ids start out being nil
default : "nil" // anything other than an atomic type
]
className() ::= "LexerTreeParser!>"
leadIn(type) ::=
<<
/** \file
* This file was generated by $ANTLR version
*
* - From the grammar source file :
* - On :
* - for the lexer : Lexer
* - for the parser : Parser
* - for the tree parser : TreeParser
*
* Editing it, at least manually, is not wise.
*
* ObjC language generator and runtime by Alan Condit, acondit|hereisanat|ipns|dotgoeshere|com.
*
*
>>
/** The overall file structure of a recognizer; stores methods for rules
* and cyclic DFAs plus support code.
*/
outputFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
buildAST,
rewriteMode,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass,
literals
) ::=
<<
*/
// [The "BSD licence"]
// Copyright (c) 2010 Alan Condit
//
// 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.
// $ANTLR
/* =============================================================================
* This is what the grammar programmer asked us to put at the top of every file.
*/
/* End of Header action.
* =============================================================================
*/
/* -----------------------------------------
* Include the ANTLR3 generated header file.
*/
#import "LexerTreeParser!>.h"
/* ----------------------------------------- */
/** String literals used by that we must do things like MATCHS() with.
* C will normally just lay down 8 bit characters, and you can use L"xxx" to
* get wchar_t, but wchar_t is 16 bits on Windows, which is not UTF32 and so
* we perform this little trick of defining the literals as arrays of UINT32
* and passing in the address of these.
*/
[] = ;}; separator="\n">
/* ============================================================================= */
/* =============================================================================
* Start of recognizer
*/
/* End of code
* =============================================================================
*/
>>
headerFileExtension() ::= ".h"
headerFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
buildAST,
rewriteMode,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass,
literals
) ::=
<<
// $ANTLR
<@imports>
/* =============================================================================
* Standard antlr3 OBJC runtime definitions
*/
#import \
#import "antlr3.h"
/* End of standard antlr3 runtime definitions
* =============================================================================
*/
<@end>
>>
lexerHeaderFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass="ANTLRLexer"
) ::=
<<
/* Start cyclicDFAInterface */
#pragma mark Rule return scopes start
}>
}>
#pragma mark Rule return scopes end
#pragma mark Tokens
}; separator="\n">
<@superClassName>: <@end> { !>
@interface <@superClassName>: <@end> { // line 283
*dfa;}; separator="\n">
Selector;}; separator="\n">
// start of actions.lexer.memVars
// start of action-actionScope-memVars
}
+ ( *)newWithCharStream:(id\)anInput;
}>)m_fragment; }; separator="\n"><\n>
_fragment;}; separator="\n"><\n> !>
@end /* end of interface */<\n>
>>
headerReturnScope(ruleDescriptor) ::= ""
headerReturnType(ruleDescriptor) ::= <<
void
>>
// Produce the lexer output
lexer( grammar,
name,
tokens,
scopes,
rules,
numRules,
labelType="id",
filterMode,
superClass="ANTLRLexer"
) ::= <<
/** As per Terence: No returns for lexer rules! */
}>
}>
#pragma mark Rule return scopes end
!>
@implementation // line 330
+ (void) initialize
{
[ANTLRBaseRecognizer setGrammarFileName:@""];
}
+ (NSString *) tokenNameForType:(NSInteger)aTokenType
{
return [[self getTokenNames] objectAtIndex:aTokenType];
}
+ ( *)newWithCharStream:(id\)anInput
{
return [[ alloc] initWithCharStream:anInput];
}
- (id) initWithCharStream:(id\)anInput
{
if ((self = [super initWithCharStream:anInput State:[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1]]) != nil) {
if ( state.ruleMemo == nil ) {
state.ruleMemo = [[ANTLRRuleStack newANTLRRuleStackWithSize:+1] retain];
}
if ( [state.ruleMemo count] == 0 ) {
// initialize the memoization cache - the indices are 1-based in the runtime code!
for (NSInteger i = 0; i \< ; i++) {
[state.ruleMemo addObject:[ANTLRHashRule newANTLRHashRuleWithLen:17]];
}
}
};separator="\n">
= [DFA newDFAWithRecognizer:self];}; separator="\n">
}
return self;
}
- (void) dealloc
{
release];}; separator="\n">
[super dealloc];
}
/* Start of actions.lexer.methods */
/* start methods() */
<@methods()>
- (void) reset
{
[super reset];
}
/* Start of Rules */
@end /* end of implementation line 397 */
>>
/** A override of Lexer.nextToken() that backtracks over mTokens() looking
* for matches. No error can be generated upon error; just rewind, consume
* a token and then try again. backtracking needs to be set as well.
* Make rule memoization happen only at levels above 1 as we start mTokens
* at backtracking==1.
*/
filteringNextToken() ::= <<
- (id\) nextToken
{
while (YES) {
if ( [input LA:1] == ANTLRCharStreamEOF ) {
return [ANTLRCommonToken eofToken];
}
state.token = nil;
state.channel = ANTLRTokenChannelDefault;
state.tokenStartCharIndex = [input getIndex];
state.tokenStartCharPositionInLine = [input getCharPositionInLine];
state.tokenStartLine = [input getLine];
state.text = nil;
@try {
NSInteger m = [input mark];
state.backtracking = 1; /* means we won't throw slow exception */
state.failed = NO;
[self mTokens];
state.backtracking = 0;
/* mTokens backtracks with synpred at backtracking==2
and we set the synpredgate to allow actions at level 1. */
if ( state.failed == YES ) {
[input rewind:m];
[input consume]; /* advance one char and try again */
} else {
[self emit];
return state.token;
}
}
@catch (ANTLRRecognitionException *re) {
// shouldn't happen in backtracking mode, but...
[self reportError:re];
[self recover:re];
}
}
}
- (void)memoize:(id\)anInput
RuleIndex:(NSInteger)ruleIndex
StartIndex:(NSInteger)ruleStartIndex
{
if ( state.backtracking > 1 ) [super memoize:anInput RuleIndex:ruleIndex StartIndex:ruleStartIndex];
}
- (BOOL)alreadyParsedRule:(id\)anInput RuleIndex:(NSInteger)ruleIndex
{
if ( state.backtracking > 1 ) return [super alreadyParsedRule:anInput RuleIndex:ruleIndex];
return NO;
}
>>
actionGate() ::= "state.backtracking == 0"
filteringActionGate() ::= "state.backtracking == 1"
parserHeaderFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass="ANTLRParser"
) ::=
<<
/* parserHeaderFile */
>>
treeParserHeaderFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass="ANTLRTreeParser"
) ::=
<<
/* treeParserHeaderFile */
>>
genericParserHeaderFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass
) ::=
<<
typedef enum {
ANTLR_EOF = -1,
INVALID,
EOR,
DOWN,
UP,
MIN
} ANTLR3TokenType;
#pragma mark Tokens
}; separator="\n">
#pragma mark Dynamic Global Scopes
}>
#pragma mark Dynamic Rule Scopes
}>
}>
#pragma mark Rule Return Scopes start
}>}>
#pragma mark Rule return scopes end
}>}>}>
#pragma mark Rule return scopes end
!>
<@superClassName>: <@end> { !>
@interface <@superClassName>: <@end> { /* line 572 */
// start of globalAttributeScopeMemVar
}><\n>
// start of action-actionScope-memVars
// start of ruleAttributeScopeMemVar
}><\n>
// Start of memVars
<@memVars()>
*dfa;}; separator="\n">
Selector;}; separator="\n">
}
// start of action-actionScope-methodsDecl
<@methodsdecl()>
}>)_fragment; }; separator="\n"><\n>
_fragment;}; separator="\n"><\n> !>
@end /* end of interface */<\n>
>>
/** How to generate a parser */
genericParser( grammar,
name,
scopes,
tokens,
tokenNames,
rules,
numRules,
cyclicDFAs, // parser init -- initializes the DFAs
bitsets,
inputStreamType,
superClass="ANTLRParser",
ASTLabelType="ANTLRCommonTree",
labelType="id",
members,
rewriteElementType,
filterMode
) ::= <<
#pragma mark Bitsets
_in_}, words64=it.bits)>
#pragma mark Dynamic Global Scopes
}>
#pragma mark Dynamic Rule Scopes
}>
#pragma mark Rule return scopes start
}>
}>
@implementation // line 637
+ (void) initialize
{
#pragma mark Bitsets
_in_}, words64=it.bits)>
[ANTLRBaseRecognizer setTokenNames:[[[NSArray alloc] initWithObjects:@"\", @"\", @"\", @"\", }; separator=", ", wrap="\n ">, nil] retain]];
}>
}
+ ( *)new:()aStream
{
return [[ alloc] initWithTokenStream:aStream];
return [[ alloc] initWithStream:aStream];
<\n>
}
- (id) initWithTokenStream:()aStream
{
if ((self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1] retain]]) != nil) {
- (id) initWithStream:()aStream
{
if ((self = [super initWithStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1] retain]]) != nil) {
<\n>
!>
= [DFA newDFAWithRecognizer:self];}; separator="\n">
}> !>
}>
/* start of actions-actionScope-init */
/* start of init */
<@init()>
}
return self;
}
- (void) dealloc
{
release];}; separator="\n">
}>
<@dealloc()>
[super dealloc];
}
// start actions.actionScope.methods
// start methods()
<@methods()>
// start rules
@end /* end of implementation line 692 */<\n>
>>
parserCtorBody() ::= <<
state.ruleMemo = [[ANTLRRuleStack newANTLRRuleStack:+1] retain];<\n>
= ;}; separator="\n">
>>
parser( grammar,
name,
scopes,
tokens,
tokenNames,
rules,
numRules,
bitsets,
ASTLabelType="ANTLRCommonTree",
superClass="ANTLRParser",
labelType="ANTLRCommonToken",
members={}
) ::= <<
", rewriteElementType="ANTLRCommonToken", ...)>
>>
treeParser( grammar,
name,
scopes,
tokens,
tokenNames,
globalAction,
rules,
numRules,
bitsets,
ASTLabelType="ANTLRCommonTree",
superClass={ANTLRTreeRewriterANTLRTreeFilterANTLRTreeParser},
labelType="ANTLRCommonTree",
members={},
filterMode
) ::= <<
", rewriteElementType="Node", ...)>
>>
/** A simpler version of a rule template that is specific to the imaginary
* rules created for syntactic predicates. As they never have return values
* nor parameters etc..., just give simplest possible method. Don't do
* any of the normal memoization stuff in here either; it's a waste.
* As predicates cannot be inlined into the invoking rule, they need to
* be in a rule by themselves.
*/
synpredRule(ruleName, ruleDescriptor, block, description, nakedBlock) ::=
<<
// $ANTLR start _fragment
- (void) _fragment
{
[self traceIn:\@"_fragment" Index:];
@try {
}
@finally {
[self traceOut:\@"_fragment" Index:];
}
} // $ANTLR end _fragment
>>
synpred(name) ::= <<
SEL Selector = @selector(_fragment);
- (BOOL)
{
state.backtracking++;
<@start()>
NSInteger start = [input mark];
@try {
[self _fragment]; // can never throw exception
}
@catch (ANTLRRecognitionException *re) {
NSLog(@"impossible: %@\n", re);
}
BOOL success = (state.failed == NO);
[input rewind:start];
<@stop()>
state.backtracking--;
state.failed=NO;
return success;
} // $ANTLR end <\n> !>
>>
lexerSynpred(name) ::= <<
>>
ruleMemoization(name) ::= <<
if ( state.backtracking && [self alreadyParsedRule:input RuleIndex:] ) return ;
>>
/** How to test for failure and return from rule */
checkRuleBacktrackFailure() ::= <<
if ( state.failed == YES ) return ;
>>
/** This rule has failed, exit indicating failure during backtrack */
ruleBacktrackFailure() ::= <<
if ( state.backtracking > 0 ) { state.failed = YES; return