Question: relation to Ohm/OMeta

33 views
Skip to first unread message

Massimiliano Gubinelli

unread,
Jan 5, 2021, 3:18:02 AM1/5/21
to nanopass-framework
Dear all,
 I'm new to nanopass and in general to parser/compiler technology. I was studying the available approaches and I had a couple of question which I hope somebody here could answer.

1) Is there any fundamental reason why the nanopass approach could not be used to also generate tokenisers, i.e. translate from a source language made of a  sequence of characters to a language made of a sequence of tokens and then up to more complex structures? I fail to see the conceptual differences here.

2) Related to question 1). Is there any connection with projects like Ohm (https://github.com/harc/ohm/blob/master/doc/README.md) where they also have a grammar and the associated semantic actions?

3) Overall, I was curious if one can use nanopass to implement general document compilers, e.g. start with an ASCII document and produce an output of some form (not necessarily a program), for example HTML. (think about a Markdown converter, or even a typesetting system)

Best regards,
Massimiliano Gubinelli

amirouche...@gmail.com

unread,
May 16, 2021, 7:09:04 AM5/16/21
to nanopass-framework
Hello Massimiliano :-)

Sorry for the very late reply!

On Tuesday, January 5, 2021 at 9:18:02 AM UTC+1 m.gub...@gmail.com wrote:
Dear all,
 
 I'm new to nanopass and in general to parser/compiler technology. I was studying the available approaches and I had a couple of question which I hope somebody here could answer.

1) Is there any fundamental reason why the nanopass approach could not be used to also generate tokenisers, i.e. translate from a source language made of a  sequence of characters to a language made of a sequence of tokens and then up to more complex structures? I fail to see the conceptual differences here.

Nanopass will take as input a sequence of tokens, but really it takes as input an existing abstract syntax tree (ast), in other words a sequence of tokens that are already structured. As far as I know, It can not be used as tokenizer or parser such as building an ast from a sequence of bytes or characters or even strings. Nanopass grammars are high level constructs compared for instance to a yacc / lex grammars. Those will produce an AST. nanopass can consume that ast and produce another ast.
 
2) Related to question 1). Is there any connection with projects like Ohm (https://github.com/harc/ohm/blob/master/doc/README.md) where they also have a grammar and the associated semantic actions?

I looked through that readme and the project readme. Ohm looks more like a parser, and not like what nanopass does.
 
3) Overall, I was curious if one can use nanopass to implement general document compilers, e.g. start with an ASCII document and produce an output of some form (not necessarily a program), for example HTML. (think about a Markdown converter, or even a typesetting system)

Like I wrote above, nanopass needs a structured input. Think a hierarchical set of tokens. With a markdown abstract syntax tree, you may be able to produce html or even pdf or ps. I guess it will be an interesting project to get started with nanopass. Mind the fact that any markdown syntax tree will map in a almost trivial way to html. For example, the following markdown code:

### Hello *schemer*!

Can be represented with the following ast:

(subsubsubsection "hello " (bold "schemer") "!")

With a search and replace you can produce the following sxml:

(h3 "hello " (b "schemer") "!")

That can itself be translated into html with a few lines of code. To go further down that rabbit hole, one can imagine taking as input the ast of tex document and produce an html page. That would be definitely more involving.
 
I think it is better to think about nanopass framework as abstract syntax tree transformer. if you prefer a macro transformer. In this regard, nanopass is an improvement over define-macro, syntax-rule or even syntax-case.

Best regards,
Massimiliano Gubinelli

I hope I answered your question.

Do not hesitate to ask more questions :-)


All the best,


Amirouche
Reply all
Reply to author
Forward
0 new messages