]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/LLkParser.cpp
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / antlr2 / src / LLkParser.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/LLkParser.cpp#2 $
6 */
7
8 #include "antlr/LLkParser.hpp"
9 #include <stdio.h>
10
11 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
12 namespace antlr {
13 #endif
14
15 ANTLR_USING_NAMESPACE(std)
16
17 /**An LL(k) parser.
18 *
19 * @see antlr.Token
20 * @see antlr.TokenBuffer
21 * @see antlr.LL1Parser
22 */
23
24 // LLkParser(int k_);
25
26 LLkParser::LLkParser(const ParserSharedInputState& state, int k_)
27 : Parser(state), k(k_)
28 {
29 }
30
31 LLkParser::LLkParser(TokenBuffer& tokenBuf, int k_)
32 : Parser(tokenBuf), k(k_)
33 {
34 }
35
36 LLkParser::LLkParser(TokenStream& lexer, int k_)
37 : Parser(new TokenBuffer(lexer)), k(k_)
38 {
39 }
40
41 void LLkParser::trace(const char* ee, const char* rname)
42 {
43 traceIndent();
44
45 printf("%s", ((string)ee + rname + ((inputState->guessing>0)?"; [guessing]":"; ")).c_str());
46
47 for (int i = 1; i <= k; i++)
48 {
49 if (i != 1) {
50 printf(", ");
51 }
52 printf("LA(%d)==", i);
53
54 string temp;
55
56 try {
57 temp = LT(i)->getText().c_str();
58 }
59 catch( ANTLRException& ae )
60 {
61 temp = "[error: ";
62 temp += ae.toString();
63 temp += ']';
64 }
65 printf("%s", temp.c_str());
66 }
67
68 printf("\n");;
69 }
70
71 void LLkParser::traceIn(const char* rname)
72 {
73 traceDepth++;
74 trace("> ",rname);
75 }
76
77 void LLkParser::traceOut(const char* rname)
78 {
79 trace("< ",rname);
80 traceDepth--;
81 }
82
83 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
84 }
85 #endif