name 'value' is not defined - Error following tutorial
I'm following this tutorial making a language with python. In my parser, I get the following error:
name 'value' is not defined.
Here is the parser class:
class Parser:
def __init__(self, tokens):
self.tokens = tokens
self.AST =
def addNode(self, parent, node):
for a in self.AST:
if parent in a:
a[parent].append(node)
def buildAST(self):
saved = {}
parent = {}
collect = False
for token in self.tokens:
if token['id'] == 'label':
t = {token['value']: }
if parent != t:
parent = token['value']
self.AST.append(t)
elif token['id'] == 'keyword':
if token['value'] == 'stop':
t = {token['value']: 0}
self.addNode(parent, t)
else:
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token[:value]}
self.addNode(parent, t)
collect = False
elif token['id'] == 'char' or token['id'] == 'atom':
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token['value']}
self.addNode(parent, t)
collect = False
The line causing the error is:
t = {saved['value']: token[:value]}
Any idea what i've done wrong? Thanks
python
add a comment |
I'm following this tutorial making a language with python. In my parser, I get the following error:
name 'value' is not defined.
Here is the parser class:
class Parser:
def __init__(self, tokens):
self.tokens = tokens
self.AST =
def addNode(self, parent, node):
for a in self.AST:
if parent in a:
a[parent].append(node)
def buildAST(self):
saved = {}
parent = {}
collect = False
for token in self.tokens:
if token['id'] == 'label':
t = {token['value']: }
if parent != t:
parent = token['value']
self.AST.append(t)
elif token['id'] == 'keyword':
if token['value'] == 'stop':
t = {token['value']: 0}
self.addNode(parent, t)
else:
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token[:value]}
self.addNode(parent, t)
collect = False
elif token['id'] == 'char' or token['id'] == 'atom':
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token['value']}
self.addNode(parent, t)
collect = False
The line causing the error is:
t = {saved['value']: token[:value]}
Any idea what i've done wrong? Thanks
python
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30
add a comment |
I'm following this tutorial making a language with python. In my parser, I get the following error:
name 'value' is not defined.
Here is the parser class:
class Parser:
def __init__(self, tokens):
self.tokens = tokens
self.AST =
def addNode(self, parent, node):
for a in self.AST:
if parent in a:
a[parent].append(node)
def buildAST(self):
saved = {}
parent = {}
collect = False
for token in self.tokens:
if token['id'] == 'label':
t = {token['value']: }
if parent != t:
parent = token['value']
self.AST.append(t)
elif token['id'] == 'keyword':
if token['value'] == 'stop':
t = {token['value']: 0}
self.addNode(parent, t)
else:
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token[:value]}
self.addNode(parent, t)
collect = False
elif token['id'] == 'char' or token['id'] == 'atom':
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token['value']}
self.addNode(parent, t)
collect = False
The line causing the error is:
t = {saved['value']: token[:value]}
Any idea what i've done wrong? Thanks
python
I'm following this tutorial making a language with python. In my parser, I get the following error:
name 'value' is not defined.
Here is the parser class:
class Parser:
def __init__(self, tokens):
self.tokens = tokens
self.AST =
def addNode(self, parent, node):
for a in self.AST:
if parent in a:
a[parent].append(node)
def buildAST(self):
saved = {}
parent = {}
collect = False
for token in self.tokens:
if token['id'] == 'label':
t = {token['value']: }
if parent != t:
parent = token['value']
self.AST.append(t)
elif token['id'] == 'keyword':
if token['value'] == 'stop':
t = {token['value']: 0}
self.addNode(parent, t)
else:
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token[:value]}
self.addNode(parent, t)
collect = False
elif token['id'] == 'char' or token['id'] == 'atom':
if collect == False:
saved = token
collect = True
else:
t = {saved['value']: token['value']}
self.addNode(parent, t)
collect = False
The line causing the error is:
t = {saved['value']: token[:value]}
Any idea what i've done wrong? Thanks
python
python
edited Jan 3 at 1:32


finefoot
2,81641936
2,81641936
asked Jan 3 at 1:20


Ibrahim FadelIbrahim Fadel
908
908
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30
add a comment |
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30
add a comment |
2 Answers
2
active
oldest
votes
You don't have value
defined inside the function buildAST
.
Did you mean to put saved['value']
or token['value']
instead?
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking forvalue
. It might pop up somewhere unexpected :D
– GeeTransit
Jan 3 at 17:01
add a comment |
Using token[:value]
attempts to access the variable value
. However, there was no variable value
declared in that scope. You must declare the variable to use it on the right side of an equation. If the tutorial said to use token[:value]
there, the tutorial was wrong.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015202%2fname-value-is-not-defined-error-following-tutorial%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't have value
defined inside the function buildAST
.
Did you mean to put saved['value']
or token['value']
instead?
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking forvalue
. It might pop up somewhere unexpected :D
– GeeTransit
Jan 3 at 17:01
add a comment |
You don't have value
defined inside the function buildAST
.
Did you mean to put saved['value']
or token['value']
instead?
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking forvalue
. It might pop up somewhere unexpected :D
– GeeTransit
Jan 3 at 17:01
add a comment |
You don't have value
defined inside the function buildAST
.
Did you mean to put saved['value']
or token['value']
instead?
You don't have value
defined inside the function buildAST
.
Did you mean to put saved['value']
or token['value']
instead?
answered Jan 3 at 1:22


GeeTransitGeeTransit
694316
694316
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking forvalue
. It might pop up somewhere unexpected :D
– GeeTransit
Jan 3 at 17:01
add a comment |
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking forvalue
. It might pop up somewhere unexpected :D
– GeeTransit
Jan 3 at 17:01
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
I tried that, and it's not what's shown in the tutorial... Also when I do that, the output is incorrect.
– Ibrahim Fadel
Jan 3 at 1:24
Check over the tutorial. You might've missed a line. Just skim through looking for
value
. It might pop up somewhere unexpected :D– GeeTransit
Jan 3 at 17:01
Check over the tutorial. You might've missed a line. Just skim through looking for
value
. It might pop up somewhere unexpected :D– GeeTransit
Jan 3 at 17:01
add a comment |
Using token[:value]
attempts to access the variable value
. However, there was no variable value
declared in that scope. You must declare the variable to use it on the right side of an equation. If the tutorial said to use token[:value]
there, the tutorial was wrong.
add a comment |
Using token[:value]
attempts to access the variable value
. However, there was no variable value
declared in that scope. You must declare the variable to use it on the right side of an equation. If the tutorial said to use token[:value]
there, the tutorial was wrong.
add a comment |
Using token[:value]
attempts to access the variable value
. However, there was no variable value
declared in that scope. You must declare the variable to use it on the right side of an equation. If the tutorial said to use token[:value]
there, the tutorial was wrong.
Using token[:value]
attempts to access the variable value
. However, there was no variable value
declared in that scope. You must declare the variable to use it on the right side of an equation. If the tutorial said to use token[:value]
there, the tutorial was wrong.
answered Jan 3 at 1:26


Pikachu the Purple WizardPikachu the Purple Wizard
2,03561429
2,03561429
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015202%2fname-value-is-not-defined-error-following-tutorial%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
token[:value] -- Python is telling you that there is no variable named "value" that has been defined.
– Jason Baumgartner
Jan 3 at 1:22
Sorry, the issue turned out to be a misspelled word in another file.
– Ibrahim Fadel
Jan 3 at 1:30