Comments on: Pyparsing introduction: BNF to code http://eikke.com/pyparsing-introduction-bnf-to-code/ 'cause this is what I do Tue, 04 Dec 2012 00:03:23 +0000 hourly 1 http://wordpress.org/?v=3.4.1 By: Wayne http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-88650 Wayne Tue, 04 Dec 2012 00:03:23 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-88650 Good introduction to pyparsing. Thanks Nicolas! Good introduction to pyparsing. Thanks Nicolas!

]]>
By: lerry http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-46616 lerry Mon, 14 Mar 2011 04:45:53 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-46616 hi poh,, what if the expr is like this A=B+c? hi poh,, what if the expr is like this A=B+c?

]]>
By: GDR! http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-30022 GDR! Fri, 18 Dec 2009 10:20:00 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-30022 Good introduction - thank you! Although I share the feelings of "sb" about pagination. Good introduction – thank you!

Although I share the feelings of “sb” about pagination.

]]>
By: Nicolas http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-2734 Nicolas Sat, 19 Apr 2008 13:17:29 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-2734 Francis: I guess you're referring to the snippet on page 2? It says: from pyparsing import OneOrMore sentence = OneOrMore(word) The definition of 'word' is given on the previous page: word = Word(lowercase) where 'lowercase' is imported from the 'string' module and equals abcdefghijklmnopqrstuvwxyz The definition of the BNF type 'word' is Word(lowercase), ie. a concatenation of any character in the string (or list, so you want) 'lowercase', which is a-z. A sentence is defined as OneOrMore words. The string 'Hello world' can not be parsed since it does not match OneOrMore(word): the first item in it ('Hello') contains characters not matching the definition of word: the 'H' (since we defined a word to be a concatenation of lowercase characters, it shouldn't contain any uppercase characters). As you can see, on page 3 a better definition of sentence is constructed using a 'startword' definition which should be a concatenation of one uppercase character, followed by zero or more lowercase characters.The example shows 'A valid sentence.' can be parsed and validated. The string 'Hello world!' would be valid in this BNF construct too. 'Hello world' would not match since we're missing a punctuation sign. Using the definitions from page 3 almost_valid_sentence = startword + body or (even more limited) hello_caps = startword + word would validate and parse 'Hello world'. Francis: I guess you’re referring to the snippet on page 2? It says:

from pyparsing import OneOrMore
sentence = OneOrMore(word)

The definition of ‘word’ is given on the previous page:

word = Word(lowercase)

where ‘lowercase’ is imported from the ‘string’ module and equals

abcdefghijklmnopqrstuvwxyz

The definition of the BNF type ‘word’ is Word(lowercase), ie. a concatenation of any character in the string (or list, so you want) ‘lowercase’, which is a-z.

A sentence is defined as OneOrMore words.

The string ‘Hello world’ can not be parsed since it does not match OneOrMore(word): the first item in it (‘Hello’) contains characters not matching the definition of word: the ‘H’ (since we defined a word to be a concatenation of lowercase characters, it shouldn’t contain any uppercase characters).

As you can see, on page 3 a better definition of sentence is constructed using a ‘startword’ definition which should be a concatenation of one uppercase character, followed by zero or more lowercase characters.The example shows ‘A valid sentence.’ can be parsed and validated. The string ‘Hello world!’ would be valid in this BNF construct too. ‘Hello world’ would not match since we’re missing a punctuation sign.

Using the definitions from page 3

almost_valid_sentence = startword + body

or (even more limited)

hello_caps = startword + word

would validate and parse ‘Hello world’.

]]>
By: Francis http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-2726 Francis Sat, 19 Apr 2008 08:22:25 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-2726 I don't see the difference in (except for the whitespaces) print sentence.parseString('hello world') # notice >1 spaces # returns ['hello', 'world'] print sentence.parseString('Hello world') # raises a ParseException Why does the second one raise an exception ? I don’t see the difference in (except for the whitespaces)

print sentence.parseString(‘hello world’) # notice >1 spaces
# returns ['hello', 'world']
print sentence.parseString(‘Hello world’)
# raises a ParseException

Why does the second one raise an exception ?

]]>
By: Olivier Berger http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-189 Olivier Berger Mon, 21 Jan 2008 10:15:40 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-189 What's the difference to other parser systems like simpleparse ? Regards, What’s the difference to other parser systems like simpleparse ?

Regards,

]]>
By: jauco http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-185 jauco Mon, 21 Jan 2008 06:22:21 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-185 very nice tutorial! thanks! very nice tutorial! thanks!

]]>
By: sb http://eikke.com/pyparsing-introduction-bnf-to-code/comment-page-1/#comment-174 sb Sun, 20 Jan 2008 17:09:30 +0000 http://eikke.com/pyparsing-introduction-bnf-to-code/#comment-174 Six pages?? Ouch. And no next button. Any chance you could put it all on one page next time? I feel like I'm reading some ad-infested hardware blog. Six pages?? Ouch. And no next button. Any chance you could put it all on one page next time? I feel like I’m reading some ad-infested hardware blog.

]]>