comparison jsparser.js @ 8:0c62f0d3ddf7

parser now ensures that it's done when it thinks it is
author Atul Varma <varmaa@toolness.com>
date Sat, 30 May 2009 15:36:57 -0700
parents e758b89c7c92
children bc6f30e0f948
comparison
equal deleted inserted replaced
7:e758b89c7c92 8:0c62f0d3ddf7
128 128
129 if (!tokenFound) 129 if (!tokenFound)
130 throw new Error("I have no idea what this is: " + text); 130 throw new Error("I have no idea what this is: " + text);
131 } 131 }
132 132
133 tokens.push(new Parsing.Symbol({name: "end",
134 charNo: charNo,
135 lineNo: lineNo}));
136 return tokens; 133 return tokens;
137 }; 134 };
138 135
139 Parsing.Parser = function Parser(tokens) { 136 Parsing.Parser = function Parser(tokens) {
140 var self = this; 137 var self = this;
138
139 tokens = tokens.slice();
140
141 tokens.push(new Parsing.Symbol({name: "end of input"}));
141 142
142 tokens.reverse(); 143 tokens.reverse();
143 144
144 this.advance = function advance(expectedToken) { 145 this.advance = function advance(expectedToken) {
145 if (expectedToken && self.token.name != expectedToken) 146 if (expectedToken && self.token.name != expectedToken)
160 return leftValue; 161 return leftValue;
161 }; 162 };
162 163
163 this.parse = function parse() { 164 this.parse = function parse() {
164 this.advance(); 165 this.advance();
165 return this.expression(0); 166 var value = this.expression(0);
167 this.advance("end of input");
168 return value;
166 }; 169 };
167 }; 170 };
168 171
169 function testParsing(print) { 172 function testParsing(print) {
170 var MyLexicon = [ 173 var MyLexicon = [