OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
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$
6 */
7
8#include "antlr/LLkParser.hpp"
9#include <iostream>
10
11#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
12namespace antlr {
13#endif
14
15ANTLR_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
27: Parser(state), k(k_)
28{
29}
30
31LLkParser::LLkParser(TokenBuffer& tokenBuf, int k_)
32: Parser(tokenBuf), k(k_)
33{
34}
35
36LLkParser::LLkParser(TokenStream& lexer, int k_)
37: Parser(new TokenBuffer(lexer)), k(k_)
38{
39}
40
41void LLkParser::trace(const char* ee, const char* rname)
42{
44
45 cout << ee << rname << ((inputState->guessing>0)?"; [guessing]":"; ");
46
47 for (int i = 1; i <= k; i++)
48 {
49 if (i != 1) {
50 cout << ", ";
51 }
52 cout << "LA(" << 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 cout << temp;
66 }
67
68 cout << endl;
69}
70
71void LLkParser::traceIn(const char* rname)
72{
73 traceDepth++;
74 trace("> ",rname);
75}
76
77void LLkParser::traceOut(const char* rname)
78{
79 trace("< ",rname);
80 traceDepth--;
81}
82
83#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
84}
85#endif
An LL(k) parser.
Definition LLkParser.hpp:24
LLkParser(const ParserSharedInputState &lexer, int k_)
An LL(k) parser.
Definition LLkParser.cpp:26
int k
the lookahead this LL(k) parser is using.
Definition LLkParser.hpp:55
virtual RefToken LT(unsigned int i)
Return the i-th token of lookahead.
Definition LLkParser.hpp:49
A generic ANTLR parser (LL(k) for k>=1) containing a bunch of utility routines useful at any lookahea...
Definition Parser.hpp:64
virtual void traceIndent()
Set or change the input token buffer.
Definition Parser.cpp:79
int guessing
Are we guessing (guessing>0)?
A Stream of Token objects fed to the parser from a TokenStream that can be rewound via mark()/rewind(...