work-site/en/parsing-upec.org
2018-09-30 21:40:27 +02:00

2.6 KiB

Basic Parsing

/scolobb/work-site/media/commit/8ca5f7d3c4663bf0a6fdb0bae3718e30925b1f6d/content/imgs/fr.png /scolobb/work-site/media/commit/8ca5f7d3c4663bf0a6fdb0bae3718e30925b1f6d/content/imgs/home.png

I taught the part of a course on formal languages which was related to the Chomsky hierarchy and parsing.

/scolobb/work-site/media/commit/8ca5f7d3c4663bf0a6fdb0bae3718e30925b1f6d/content/imgs/ccby.png

The materials of my course are distributed under the Creative Commons Attribution Alone licence.

Slides

The slides for this course are available here (in French).

Practical assignment

The exercises for the practical assignment (in French) can be downloaded here.

Source code

In this course I show a simple interpreter for a language of variable assignments. The variables can either be strings or integer numbers. A program in this language may look as follows:

  String var1 = "hello world 1 + 2";
  int var2 = 1 - (2 + 3);
  int var3 = 4 + var2;

This archive contains the complete source code of the interpreter as well as several example programs.

To build the project, run the following commands:

  jflex arith.flex
  jacc arith.jacc
  javac ArithEval.java

The following command runs just the scanner on the first example:

  java Yylex examples/example1.duck

The following command runs the interpreter on the first example:

  java ArithEval examples/example1.duck

Toolchain

The project relies on JFlex scanner generator and Jacc parser generator. Both tools generate Java code. Here is a short overview of a typical workflow.

This toolchain was suggested by Frédéric Gava (section Parsing de fichiers en Java). This page also contains other slides about parsing.