473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

lexical analysis of html

Hi

I am trying to make lexical analysis of some simplified html code with
flex tool. However that kind of work is new to me and I don't know
where to start. I have searched a web but I didn't find anything
useful. I found tools like LEXHTML.CXX library but I have no need for
that.

What I need is simple overview of working ideas of most usual html
lexical analysators like ones inside IE or Gecko. Something like good
article or post where is described how lexical atoms or operators and
similar particles are recognized in HTML (what is what and where it
goes).

Kudos for your help..

Jul 20 '05 #1
4 4376
Hi, bariole,

Generally speaking it is impossible to create scanner and parser of SGML
(HTML and XML) using flex/bison and the like.
These are special languages as they require building the parser dynamically
on the fly, based on a Document Type Declaration (DTD).

Moreover, practical HTML scanner and parser shall include also parser for
JavaScript (or its subset) as you may bump into following:
<SCRIPT>
function foo() { a.write("</SCRIPT>"); }
</SCRIPT>
(not recommended by spec but happens)

To be short I think you will not find ready to use lex/y files for HTML.

"Finite state automata" of HTML parser is not so hard to write.
And there are plenty of examples in the Net.
For example : http://www.do.org/products/parser/

"Per aspera ad astra!" :)

Andrew Fedoniouk.
http://terrainformatica.com

"bariole" <ba*******@SPAMyahoo.com> wrote in message
news:ls********************************@4ax.com...
Hi

I am trying to make lexical analysis of some simplified html code with
flex tool. However that kind of work is new to me and I don't know
where to start. I have searched a web but I didn't find anything
useful. I found tools like LEXHTML.CXX library but I have no need for
that.

What I need is simple overview of working ideas of most usual html
lexical analysators like ones inside IE or Gecko. Something like good
article or post where is described how lexical atoms or operators and
similar particles are recognized in HTML (what is what and where it
goes).

Kudos for your help..

Jul 20 '05 #2
bariole wrote:
Hi

I am trying to make lexical analysis of some simplified html code with
flex tool. However that kind of work is new to me and I don't know
where to start. I have searched a web but I didn't find anything
useful. I found tools like LEXHTML.CXX library but I have no need for
that.

What I need is simple overview of working ideas of most usual html
lexical analysators like ones inside IE or Gecko. Something like good
article or post where is described how lexical atoms or operators and
similar particles are recognized in HTML (what is what and where it
goes).


As Andrew wrote, arbitrary valid HTML is too "fluffy" to be easily
defined as flex requires.

If you are writing the HTML yourself, you can make it a bit stricter by
doing things like always closing elements which will help you. By
writing Appendix C-compliant XHTML-1.0, you can make your code into
valid XML as well, which will make it a lot easier to parse.

--
Mark.
Jul 20 '05 #3
On Wed, 19 May 2004 04:05:32 GMT, "Andrew Fedoniouk"
<ne**@terrainformatica.com> wrote:
Generally speaking it is impossible to create scanner and parser of SGML
(HTML and XML) using flex/bison and the like.
These are special languages as they require building the parser dynamically
on the fly, based on a Document Type Declaration (DTD).

Moreover, practical HTML scanner and parser shall include also parser for
JavaScript (or its subset) as you may bump into following:
<SCRIPT>
function foo() { a.write("</SCRIPT>"); }
</SCRIPT>
(not recommended by spec but happens)
I was thinking about similar problems. To me lex seems like very
"strict" tool, actually to strict to be used for language like html.
To be short I think you will not find ready to use lex/y files for HTML.


I didn't ask for that although it would be very nice for me to see
that files if they existed somewhere. Lex and lexical analysis are
something new to me and I needed ideas how those things are done.

However I am pleased to say that after two days of thinking I found a
solution for my problem.

Thank you for your replay. Your post was more helpful than you can
imagine..

Jul 20 '05 #4
On Wed, 19 May 2004 08:06:35 +0100, Mark Tranchant
<ma**@tranchant.plus.com> wrote:
bariole wrote: As Andrew wrote, arbitrary valid HTML is too "fluffy" to be easily
defined as flex requires.

If you are writing the HTML yourself, you can make it a bit stricter by
doing things like always closing elements which will help you. By
writing Appendix C-compliant XHTML-1.0, you can make your code into
valid XML as well, which will make it a lot easier to parse.


Thanks Mark. I will do something like that.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Collin VanDyck | last post by:
Hello! I have set up a pluggable SAX transformation pipeline which is made up of individual nodes that transform the source XML, and for the most part it works well. Each node in the pipeline...
3
by: dayzman | last post by:
Hi, I've read somewhere that feature-based analysis can be used to extract the semantic structure of HTML documents. By semantic structure, they mean the model of the rendered view a reader...
13
by: Lucas Zimmerman | last post by:
Is there any Lex code available that describes how to scan C programs? I'd like to read someting related to this. One of my doubs is how C deals with ambiguities, for example, `a = x/*p;' or `a =...
2
by: Frank-René Schäfer | last post by:
penSource Project 'Quex': http://quex.sf.net Last weekend, the lexical analyser generator 'Quex' has been released on SourceForge. Quex provides advanced features for mode definitions and...
9
by: Bo Yang | last post by:
Hi, guys. I am now developing an application in which I need to fetch some html page, and then parsing it to get some intended content in it. Because HTML is not a standard XML format, so I am...
0
by: tavares | last post by:
--------------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) Symposium...
6
by: enaeher | last post by:
I would expect this code: globalFnArray = ; for (var i = 0; i < 5; i++) { globalFnArray.push (function () { alert (i) }); } for (var j = 0; j < 5; j++) { globalFnArray(); } to alert 0, 1, 2,...
14
by: Khookie | last post by:
Woah... is it just me or do C programmers don't bother talking about how cool C can be (compared to Lisp, Haskell, etc.) - functionally speaking? // Lexical scoping - via nested functions...
3
by: globalrev | last post by:
i cant figure outif python has lexical or general scope. it seems functions have lexical scope but with some restrictions and some non-function scopes are dynamic?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.