Hello Alex, both the t_AND and the t_NAME rule match the string 'and' (without the quotes). Since t_AND was previously a string, and t_NAME a function, t_NAME took precedence (see http://www.dabeaz.com/ply/ply.html, section 3.3). You now changed them to both be functions. Then the t_AND takes precedence (it is first in the file). Anyway, the same section 3.3 explains you should not use rules for and/or etc, but include them in the identifier rule (t_NAME in your case).
You could probably have seen this, if you would have called the parse(...) function with debug=2 parameter. This outputs debugging information during parsing. It shows the tokens scanned, parser state, etc. You would have seen that it scans a NAME tokens instead of an AND token... Good luck, Dennis Alex_Gaynor wrote: >I was able to fix the 'and' 'or' 'not' issue by turning their >definitions into functions, instead of just strings, not sure why that >fixed it :/ > >On Oct 7, 7:54 pm, Alex_Gaynor <[EMAIL PROTECTED]> wrote: > > >>I was able to succesfully implement True and False by making them >>tokens(I do want them to be reserved ala py3k), so thanks for the help >>with that! I am also looking over the things on indentation, although >>I suspect that will be something that goes in later. Right now I am >>having some issue implementing 'and' 'or' and 'not'. Right now I have >>them implemented the same way I do other unary and binary operators >>which I suspect isn't working. Right now whenever I try True or >>False, or not True, or True and False I get a syntax error, and I'm >>not sure what causes this. All my code is >>here:http://github.com/alex/alex-s-language/tree/master >> >>On Oct 7, 6:59 pm, Bruce Frederiksen <[EMAIL PROTECTED]> wrote: >> >> >> >>>If you make True/False tokens, that generally means that they are >>>reserved words in your language. That means that nobody can use them >>>for other purposes. >>> >>> >>>If you want to let people use the words "True" and "False" for other >>>purposes, then you probably don't want them to be tokens. In this case, >>>you will probably end up doing a lookup at runtime, which might find >>>some other value. >>> >>> >>>In python 2.5, for example, you can use True and False for other purposes: >>> >>> >>>def False(): print "hi mom!" >>> >>> >>>is OK. But this becomes illegal in python 3.0. >>> >>> >>>I've attached a scanner the does indenting ala python (i.e., the >>>programmer can indent any amount so long as they line up). >>> >>> >>>-bruce >>> >>> >>>Alex_Gaynor wrote: >>> >>> >>>>I'm looking to implement a boolean type in my language, where exactly >>>>should I do this? Should I make True and False both be tokens, and >>>>just set t.value = True/False. Or should the parser handle them? >>>> >>>> >>>>Also, how would I go about implementing a language that uses indent/ >>>>dedent for blocks(ala python)? >>>> >>>> >>>>Alex >>>> >>>> >>> scanner.py >>>19KViewDownload >>> >>> >> > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en -~----------~----~----~----~------~----~------~--~---
