Seiten

  • Startseite
  • Impressum
  • Inhalt
  • MINT
  • Sprache
  • Soziales
  • Geist
  • Kunst
  • Gemischtes
  • Gedichte

Samstag, 17. Oktober 2015

Parsing function with tree result 8-)


English

Today I have programmed my first top-down pars­er. The input has to be a con­text-free, non-recursive grammar and a word to check. The out­put is the parse (if it exists) and a tree. (Al­though the tree is not the most beautiful one, it took me the most time to imple­ment it.)
And here comes the code:

Just copy ’n’ paste it! There is no guar­antee that there’re no more bugs in it—I just tested it with a couple of grammars and words.
You can test it on­line, too. Simply write your grammar and a word in­side the fol­lowing text fields, as I did before1, and click the parse button.
In­structions
  1. the first rule must have the start symbol on the left side
  2. non-terminals can consist out of cap­ital letters, optionally fol­lowed by a _ and ev­ery­thing, and 's; ev­ery non-non-terminal is a terminal (sounds weird, right?)
  3. left and right side of a rule shall be seperated by a ->
  4. be­tween ev­ery terminals and non-terminals has to be a seperating space


1grammar example abtracted from here, page 2

Keine Kommentare:

Kommentar veröffentlichen