name 'value' is not defined - Error following tutorial












-1















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










share|improve this question

























  • 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
















-1















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










share|improve this question

























  • 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














-1












-1








-1








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















1














You don't have value defined inside the function buildAST.



Did you mean to put saved['value'] or token['value'] instead?






share|improve this answer
























  • 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



















0














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.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    You don't have value defined inside the function buildAST.



    Did you mean to put saved['value'] or token['value'] instead?






    share|improve this answer
























    • 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
















    1














    You don't have value defined inside the function buildAST.



    Did you mean to put saved['value'] or token['value'] instead?






    share|improve this answer
























    • 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














    1












    1








    1







    You don't have value defined inside the function buildAST.



    Did you mean to put saved['value'] or token['value'] instead?






    share|improve this answer













    You don't have value defined inside the function buildAST.



    Did you mean to put saved['value'] or token['value'] instead?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 for value. 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











    • 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

















    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













    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 1:26









        Pikachu the Purple WizardPikachu the Purple Wizard

        2,03561429




        2,03561429






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith