• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Making an interpreter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making an interpreter


  • Subject: Re: Making an interpreter
  • From: Brian Gilman <email@hidden>
  • Date: Mon, 09 Jun 2003 09:54:52 -0400

On 6/7/03 4:09 AM, "Jason Alexander" <email@hidden> wrote:

Just to follow up:

If you're a java/C++ coder you can use Antlr which is a more "modern"
approach to writing lexer-parsers. You can find this at:

www.antlr.org

It has a nice tutorial section as well as pointers to other tutorials
and code. It also comes with a handful of useful grammars including SQL,
HTML, C#, Java, C++, etc.

-B

>> At 5:12 PM +0200 6/6/03, Daniele M. wrote:
>>
>> hello, i would to make an interpreter for a "new scripting language"
>> of mine. Unfortunatly i don't know more about this topic
>> (parse/translate and code interpreting) so i'm searching for books/pdf
>> and other docs. Anyon can help me?
>> Is there around the net some example? book?
>
> If you actually want to write your own interpreter, and the language
> isn't too complex, use lex and yacc  or their more modern GNU
> equivalents, flex and bison. I think they are included "for free" on a
> standard OS X install. If not, get them via fink.
>
> Flex is a lexical analyzer  use it to write the interpreter that
> converts an input stream to tokens. Bison generates a parser  the
> tool that provides the semantics for the sequence of tokens.
>
> Both allow you to specify the language using regexs and BNF-type
> notation. They are very powerful and should suffice, as long as the
> language isn't too complex (i.e., context dependent). I think it would
> be a real chore to write perl in Bison, for example.
>
> You'll probably want a book explaining how to use them. The GNU
> documentation is pretty good. Alternatively, you can get the book: Lex
> & Yacc by John R. Levine, Tony Mason, Doug Brown. (Flex and Bison are
> supersets of lex and yacc, so this will get you started.)
>
> In short, here's how they work. You write the tokenizer using a
> special file format understood by flex. You name this file something
> like tokenizer.l. You write the parser using a special file format
> understood by bison. You name this file something like parser.y. Then
> process both tokenizer.l and parser.y with flex and bison,
> respectively. This generates two C files which you can compile and
> integrate in your program.
>
> It may sound like a lot of work, at first, but the fact that you can
> specify the language constructs in the parser like
>
> NUMBER: DIGITS
> | DIGITS .
> | SIGN DIGITS
> | SIGN DIGITS .
> | DIGITS . DIGITS
> | SIGN DIGITS . DIGITS
>
> and not worry about how to handle the fine details of each of those
> cases is a real savings. Especially when your language grows and
> collects new features (which it probably will).
>
> Cheers,
>
> Jason
> --
> J. McKenzie Alexander
> Department of Philosophy, Logic and Scientific Method
> London School of Economics and Political Science
> Houghton Street, London WC2A 2AE
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
>

--
Brian Gilman <email@hidden>
Group Leader Medical & Population Genetics Dept.
MIT/Whitehead Inst. Center for Genome Research
One Kendall Square, Bldg. 300 / Cambridge, MA 02139-1561 USA
phone +1 617 252 1069 / fax +1 617 252 1902
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Making an interpreter (From: Jason Alexander <email@hidden>)

  • Prev by Date: Re: The Little NSOutlineView That Couldn't
  • Next by Date: Re: C question for you old guys ;-)
  • Previous by thread: Re: XML plist to NSArray
  • Next by thread: Making an interpreter
  • Index(es):
    • Date
    • Thread