
Hi. I'm starting to write a CSS parser with Alex and Happy. The grammar is defined here: http://www.w3.org/TR/CSS21/grammar.html However I have noted that there are some difference in the syntax between Alex and Flex? What is the rationale? One more thing. Here: http://www.haskell.org/alex/doc/html/alex-files.html it seems that there is an error with macrodef := @smac '=' set | @rmac '=' regexp it should be macrodef := $smac '=' set | @rmac '=' regexp Thanks Manlio Perillo

Manlio Perillo ha scritto:
Hi.
I'm starting to write a CSS parser with Alex and Happy. The grammar is defined here: http://www.w3.org/TR/CSS21/grammar.html
However I have noted that there are some difference in the syntax between Alex and Flex? What is the rationale?
One more thing. Here: http://www.haskell.org/alex/doc/html/alex-files.html it seems that there is an error with macrodef := @smac '=' set | @rmac '=' regexp
it should be macrodef := $smac '=' set | @rmac '=' regexp
Ok, this is not an error, sorry. By the way, here is the list of differences between Alex and Flex I have found, for people interested: 1) Alex make a distinction between "character set macros" and "regular expression macros". 2) Alex support the set '#' set0 syntax for "character set macros" 3) Alex does not support [_a-z0-9-] that must be rewritten as [_a-z0-9\-] 4) In Alex the order of macro definitions is important. A macro must be defined before it is used in another macro definition. 5) For reasons I still don't understand, this: \"([^\n\r\f\\"]|\\@nl|@escape)*\" cause a parse error, but these are ok: \'([^\n\r\f\\']|\\@nl|@escape)*\' \"([^\n\r\f\\"]|\\@nl|@escape)* 6) As with 3), these are not parsed: [^*] [^/*] and must be rewritten as [^\*] [^\/\*] 7) I don't understand why, but this is not parsed: -?@nmstart@nmchar* The -? at the beginning must be removed. How can I fix this? Thanks Manlio Perillo

On Oct 3, 2008, at 09:24 , Manlio Perillo wrote:
Manlio Perillo ha scritto:
However I have noted that there are some difference in the syntax between Alex and Flex? What is the rationale?
By the way, here is the list of differences between Alex and Flex I have found, for people interested:
3) Alex does not support [_a-z0-9-] that must be rewritten as [_a-z0-9\-]
The only *reliable* way to write that cset is to put the '-' as the first item. Likewise for ']' (and if you must match both, "[-]...]"). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Brandon S. Allbery KF8NH ha scritto:
On Oct 3, 2008, at 09:24 , Manlio Perillo wrote:
Manlio Perillo ha scritto:
However I have noted that there are some difference in the syntax between Alex and Flex? What is the rationale?
By the way, here is the list of differences between Alex and Flex I have found, for people interested:
3) Alex does not support [_a-z0-9-] that must be rewritten as [_a-z0-9\-]
The only *reliable* way to write that cset is to put the '-' as the first item. Likewise for ']' (and if you must match both, "[-]...]").
Escaping the character solve the problem, or at least I have tested and it works. It seems, however, that Alex is quite strict in accepted characters. As an example, this rule [ \t\r\n\f] does not match the space character; this character must be escaped: [\ \t\r\n\f] Flex seems to be more "smart", here. Note that the escaping solve the problem 7): \-?@nmstart@nmchar* Thanks Manlio Perillo

Manlio Perillo ha scritto:
Manlio Perillo ha scritto:
Hi.
I'm starting to write a CSS parser with Alex and Happy. The grammar is defined here: http://www.w3.org/TR/CSS21/grammar.html
However I have noted that there are some difference in the syntax between Alex and Flex? What is the rationale?
One more thing. Here: http://www.haskell.org/alex/doc/html/alex-files.html it seems that there is an error with macrodef := @smac '=' set | @rmac '=' regexp
it should be macrodef := $smac '=' set | @rmac '=' regexp
Ok, this is not an error, sorry.
By the way, here is the list of differences between Alex and Flex I have found, for people interested:
[...]
Another problem. In this rule: @comment = \/\*[^\*]*\*+([^\/\*][^\*]*\*+)*\/ [^\*] means "all characters except '*'", but Alex seems to not include the new line character. So a comment like /* A comment */ generates a lexical error. Is this true? Thanks Manlio Perillo

Manlio Perillo ha scritto:
[...] Another problem.
In this rule: @comment = \/\*[^\*]*\*+([^\/\*][^\*]*\*+)*\/
[^\*] means "all characters except '*'", but Alex seems to not include the new line character.
Again sorry. The problem was not here. There was a missing rule for '.', to scan every characters. Regards Manlio Perillo
participants (2)
-
Brandon S. Allbery KF8NH
-
Manlio Perillo