For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > November 2005 > SmaCC examples









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SmaCC examples
Ian Upright

2005-11-14, 7:02 pm

Looking for some XML or HTML parsing examples, or other simple examples for
SmaCC. Any around like this?

Thanks, Ian

---
http://www.upright.net/ian/
Ian Upright

2005-11-16, 3:59 am

Reinout Heeck <reinz@desk.org> wrote:

>Ian Upright wrote:
>
>
>"Should be made more prominent in parcel load tool:"
>Parcel loadParcelByName: 'SmaCC Example Parsers'


This includes a Java, Smalltalk, and C parser. Is there any XML or HTML
parsers in this example or elsewhere -- I didn't see any.. Also didn't see
any example ones that produce trees/nodes instead of flat parsed output.

Ian

>
>"Demonstrates use of error production:"
>Parcel loadParcelByName: 'RBCodeHighlighting'
>
>
>
>HTH,
>
>Reinout
>-------


---
http://www.upright.net/ian/
Reinout Heeck

2005-11-16, 7:04 pm

Ian Upright wrote:
> This includes a Java, Smalltalk, and C parser. Is there any XML or HTML
> parsers in this example or elsewhere -- I didn't see any.


I'm not aware of any.


> Also didn't
> see any example ones that produce trees/nodes instead of flat parsed
> output.


yes, such an example is missing.

Anyway the parser leaves you entirely free in what you consider a parse node
or parse action.
So in the actions of your production rules you could add self sends or sends
to a 'builder' ivar you declare in your parser subclass.

something along the lines of

Element :=
"<" Tag Attribute* ">" Element* "</" tag ">"
{ builder elementWithTag: '2' attributes: '3' elements: '5'}
| "<" Tag Attribute* "/>"
{ builder elementWithTag: '1' attributes: '3' elements: nil}
;


If you want to model a stream of enter/leave events you could try something
like

Element :=
"<" Tag Attribute* ">" { client enterElement: '2' attributes: '3' }
Element *
"</" tag ">" { client leaveElement }
|
"<" Tag Attribute* "/>" { client enterElement: '2' attributes: nil;
leaveElement }
;

But I never tried such streaming, I don't know how parser backtracking
interacts with it (if at all).



HTH,

Reinout
-------

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com