I am considering writing a markdown parser in Objective C.
Can anyone explain the basic algorithm of doing this?
Is there any library I can look at? I'm not familiar with C. Python or Obj-C implementation would be nice.
The parser should not focus on HTML or any other output. Instead it focuses on detecting the markdown syntax.
Thanks
Markdown is essentially specified by the original Perl script that parses it.
It doesn't fit neatly into a standard parser architecture unfortunately (there isn't a formal grammar as such), it is based on a multi-pass set of string manipulations and regular expression pattern matching/replacement. If you read through the Perl script you will see what I mean.
The best way to achieve your goal is to hand transcode the Perl script into Obj-C, as has been done for other languages.
Related
Can I use the ANTLR Java API to generate the lexer/parser as streams and save them somewhere other than some files?
Also, is there a simple example of using the API to generate the required files from a given grammar?
thanks
I am not 100% sure if I understand your question correctly, but you might want to have a look at https://stackoverflow.com/a/38052798/5068458. This is an in-memory compiler for antlr grammars that generates lexer and parser for a given grammar in-memory. You do not have to do it manually. Code examples are provided there.
Best,
Julian
There are pages that indicate ANTLR works with Objective-C, but I can find no documentation or examples of actually using ANTLR with an Objective-C target. I even dug through the source code and have found no examples.
Any guidance, anyone?
The parser generator that emits Objective-C code is old and doesn't work. You'll have to use the C generator, and the C generator's documentation is worse than useless.
my project this year is to develop a text mining tool (with new features)
so we need a mini script language in this tool to add annotation to texts
this language should be simple and like lisp grammars (left and right side) .
what i need is how to design this language ,i know how to constract the compiler ,
but how to write language grammars ? , and i want to use some mini open source language or any language bnf
please advice me and if there is a language i can use and customize to meet my needs ?
EDIT : if anybody can give a link for grammar (bnf) for lisp or any language like it
many thanks
You can consider us this
http://www.antlr.org/
to design your language.
If possible, I would recommend just using Lua. If you use their interpreter, which is designed to be easily embedded in other programs, it will save you the time of designing, implementing, and testing your own language.
Otherewise, you may be able to re-use the Lua parser code to parse your own Lua-like language.
how do I parse a mail in Cocoa?
I've read the NSScanner tutorial, but struggled.
Do you know any better way than NSScanner?
Is there any sample code?
My example:
http://pastie.org/private/pordph27stkwkyvrx2tiq
Regards
If you cannot find any cocoa libraries to do the job you need done, you can always use C++ or C libraries for your tasks. e.g. Scaling Web's Parser. Apple has documentation on how to use C++ from Objective C
I use C-Client. It's C only, a bit hard to understand but it gets the job done.
I wouldn't take on writing a MIME parser myself - it's lots of work if you look at the RFCs that come into play.
If I were looking to create my own language are there any tools that would help me along? I have heard of yacc but I'm wondering how I would implement features that I want in the language.
Closely related questions (all taken by searching on [compiler] on stackoverflow):
Learning Resources on Parsers, Interpreters, and Compilers
Learning to write a compiler
Constructing a simple interpreter
...
And similar topics (from the same search):
Bootstrapping a language
How much of the compiler should we know?
Writing a compiler in its own language
...
Edit: I know the stackoverflow related question search isn't what we'd like it to be, but
did we really need the nth iteration of this topic? Meh!
The first tool I would recommend is the Dragon Book. That is the reference for building compilers. Designing a language is no easy task, implementing it is even more difficult. The dragon book helps there. The book even reference to the standard unix tools lex and yacc. The gnu equivalent tools are called flex and bison. They both generate lexer and parser. There exist also more modern tools for generating lexer and parser, e.g. for java there are ANTLR (I also remember javacc and CUP, but I used myself only ANTLR). The fact that ANTLR combines parser and lexer and that eclipse plugin is availabe make it very comfortable to use. But to compare them, the type of parser you need, and know for what you need them, you should read the Dragon book. There are also other things you have to consider, like runtime environment, programming paradigm, ....
If you have already certain design ideas and need help for a certain step or detail the anwsers could be more helpful.
ANTLR is a very nice parser generator written in Java. There's a terrific book available, too.
I like Flex (Fast Lex) [Lexical scanner]
and Bison (A Hairy Yacc) [Yet another compiler compiler]
Both are free and available on all *NIX installations. For Windows just install cygwin.
But I old school.
By using these tools you can also find the lex rules and yacc gramers for a lot of popular languages on the internet. Thus providing you with a quick way to get up and running and then you can customize the grammers as you go.
Example: Arithmetic expression handling [order of precedence etc is a done to death problem] you can quickly get the grammer for this from the web.
An alternative to think about is to write a front-end extension to GCC.
Non Trivial but if you want a compiled language it saves a lot of work in the code generation section (you will still need to know love and understand flex/bison).
I never finished the complete language, I had used rply and llvmlite implements a simple foxbase language, in https://github.com/acekingke/foxbase_compiler
so if you want use python, rply or llvmlite is helpful.
if you want use golang, goyacc maybe useful. But you should write a lexical analyzer by hard coding by hand. Or you can use https://github.com/acekingke/lexergo to simplify it.