User talk:Sgeo/ffbimp

From Esolang
Jump to navigation Jump to search

You don't need to use <code> or <pre> in the Wiki - if you put a space at the start of each line (including blank lines) the Wiki will handle it for you:

10 Print "Hello World"
20 Get ABetterProgrammingLanguage

--Safalra 21:30, 20 Nov 2005 (GMT)

Pyparsing implicitly skips whitespace

"Currently, you need to manually strip spaces and newlines out of programs... " Why? pyparsing ignores whitespace by default.

Other comments:

1) Purpose of rvars?

2) A disturbing use of looping variable:

   for i in code:
       try:
           i = line.parseString(i)
       ...

Any reason you could not use a different variable for the return value from parseString?

3) You can also use Suppress to keep your "and", "oh my", etc. literals from garbaging up your parsed tokens. Change:

   line = Word(lvars) + "and" + Word(lvars) + "and" + Word(lvars) + ", oh my" + oneOf('! . ...')

to:

   line = Word(lvars) + Suppress("and") + Word(lvars) + Suppress("and") + Word(lvars) + Suppress(", oh my") + oneOf('! . ...')

Then you can remove the del statments from your process_code routine.

4) Or, you could give the important tokens results names, as in:

   line = Word(lvars).setResultsName("A") + "and" + Word(lvars).setResultsName("B") + "and" + Word(lvars).setResultsName("C") + ", oh my" + oneOf('! . ...').setResultsName("D")

and then store the parsed item in p_code (no tuple()'ing or list()'ing, just save the returned ParseResults), and reference the values as v.A, v.B, etc., as in:

   (v.A & v.B) | (v.C & v.D)

(Of course, you'd have to convert the string values to integers first, perhaps using a parse action.)


Glad you're giving pyparsing a try - drop me a note if you have other questions.

--Paul 28 Nov 2005


Nearly fell off my chair laughing when I read the sentence "a disturbing use of looping variable..." Just struck me as extremely funny --ORBAT 23:39, 28 Nov 2005 (GMT)
Removing all whitespace would result in ambiguity, though there's really no reason to put ". ..." anywhere. --Ihope127 21:46, 29 Nov 2005 (GMT)

Well, I shouldn't have said "spaces". Any other issues are due to my lack of experience in programming (a.k.a My fault completely).