2

I am trying to develop a simple C style scripting language for educational purposes.

Thing I have done so far:

  • defined syntax of the language
  • written code for tokenizing the language.

The features that I want to include at the moment:

  • Arthematics
  • Conditions
  • while loop (only)

At the moment I don't want to add other features to the language, as it will make development procedure quite complex.

However, I don't know what are the next steps that are involved in developing a language. I have gone through many questions on SO but they weren't very specific in detail. Kindly guide me with this process.

user2498079
  • 2,872
  • 8
  • 32
  • 60

3 Answers3

0

I think these answers are helpful starting out:

If you have defined a EBNF grammar, then you can use a tool like BISON to create a parser. Using that parser to generate an abstract syntax tree you can then proceed to create an interpreter for your language.

Community
  • 1
  • 1
Emil L
  • 20,219
  • 3
  • 44
  • 65
  • Could you tell about Syntactic analysis algorithms? I don't want to use any libraries for parsing or syntactical analysis. I want to write everything from scrathc – user2498079 Mar 30 '14 at 09:32
  • Do you mean that you want to write the parser manually instead of using a parser generator? You would have to (if I understand the process correctly) create some sort of tree from the tokens that your tokenizer produces. I'd recommend using some sort of parser generator, since it makes it easier to experiment with different kinds of language syntax. – Emil L Mar 30 '14 at 13:56
0

Few years back I have been developing my own language too (it was interpreted language) and in phase when language was ready for "others" to try, I found out that there were few things I should have done earlier, or better:

  1. Solve tons of simple programming problems in that language
  2. Solve just a few, but I would call it "hard core" programming problems with it (for example Project Euler)
  3. Write complex language specification, few examples, wiki or FAQ, well anything that will spare you answering the same questions all the time

Hope that helps.

FanaticD
  • 1,416
  • 4
  • 20
  • 36
  • In which language did you write your language? Did you use any libraries for parsing or ast or you wrote everthing from scratch? – user2498079 Mar 30 '14 at 09:29
0

Yes, having done this several times I know it's hard to know where to start. And you really don't need Lex or Yacc or Bison.

  1. Make sure you have the definitions for your lexical elements (tokens) and grammar (in EBNF) nailed down.
  2. Write a lexer for your tokens. It should be able to read a sample program emitting tokens and ending gracefully.
  3. Write a symbol table. This is where you will put symbols as you recognise them. You can put reserved words and literals in here too, or not. It's a design choice.
  4. Write a recursive descent parser, with a function for recognising each production in your grammar. You may need to modify your grammar to let you do this.
  5. Write a tree/node manager for your AST (Abstract Syntax Tree). The parser adds nodes to the tree with links into the symbol table as it recognises productions.

Assuming you get this far, the final two steps are:

  1. Walk the AST performing type and reference resolution, some kinds of optimisation, etc.
  2. Walk the AST to emit code.

The last two steps turn out to be where most of the hard work is.

You will needs some specific references and what you choose depends on your level and what you like to read and what language you like to write. The Dragon Book is an obvious choice, but there are many others. I suggest you look here: Learning to write a compiler.

Community
  • 1
  • 1
david.pfx
  • 10,520
  • 3
  • 30
  • 63