All posts by raymond

Yacc2Latex: Generate a language grammar reference directly form the yacc file

yacc2latex is  available under LGLP licence (dowload here).

As a language designer, I often faced the problem of writing and maintaining a reference (readable) grammar of my language. This is particularly annoying since the reference grammar actually exists as a yacc (or ocamlyacc) file, so why not use a “compiler” that will derived automaticaly the reference grammar from the yacc file ?

Deriving a readable, and reasonably compact, grammar from yacc is not so easy: basically it means discovering the EBNF grammar the designer had in mind when he wrote the yacc.

I found on the internet a nice tool form Kris Van Hees, y2l, but unfortunately relatively old, writen in AWK, and suffering limitations. In particular it was not possible to use it with mly file (ocamlyacc).

I thus decided around 2011 to write my own  yacc to latex “compiler”
for writing the reference manual of “my” languages (Lustre and Lutin).
The tool is is now fairly tested and stable, and I decided to make it available
(through the LGPL licence), hope it may be helpfull for some people !

The main characteristics of yacc2latex are:

  • It integrates a yacc parser, made from scratch,  that is (intended to be) completely agnostic to the embedded programming language , in particular it was made to support mly files (ocamlyacc sources). Indeed, classical C/C++ yacc should also work.
  • It integrates stategies to found EBNF patterns in the yacc (lists, factorization etc.)
  • For advanced use, it provides pragmas to give directives to the translation, in particular a huge grammar can be organized into “sections”.
  • The generated Latex code is parametric: is is possible to change the look of the document by re-defining a set of latex commands.

The distribution  is here: yacc2latex.

As an example of what yacc2latex can do, here  is the reference manual of Lutin, obtained from the ocamlyacc of Lutin.

 

 

How to upload a nxtOSEK program

Intro

For an appli “MyAppli”, nxtOSEK builds 3 different binaries files:

  • MyAppli_ram.bin, is uploaded in RAM, on bricks without firmware:
    • program is lost when the brick is switched off
    • useful for quick tests
    • on Linux, can be uploaded with fwexec (from libnxt-0.3)
    • no tools (simply) available on Windows
  • MyAppli_rom.bin, is uploaded in ROM, on bricks running a minimal firmware provided by nxtOSEK:
    • the minimal firmware can load a single program
    • on Windows, can be uploaded with appflash.exe, provided by nxtOSEK
    • no tools for Linux
  • MyAppli.rxe, is uploaded in “disk” (actually ROM), on bricks runnig Jon Hansen’s Enhanced Firmware:
    • same extension as the standard Lego byte-code, but NOT COMPATIBLE
    • runs on very complete firware, with the same interface as the Lego firmware
    • uploadable on both Linux and Windows with NexTTool(.exe)
    • uploadable on Linux with t2n (talk2nxt)

The following table summerizes the results, listing the necessary firware (if any) and the tools available for uploading on Linux and (Cyg)Win:

Firmware Linux (Cyg)Win
foo_ram.bin none fwexec
foo_ram.bin
no
foo_rom.bin nxt_bios_rom.rfw no appflash.exe
foo.rxe lms_arm_nbcnxc_128.rfw NeXTTool
/COM=usb -download=foo.rxe(or with the script: loadrxe foo.rxe)ott2n -put
NeXTTool.exe
/COM=usb -download=foo.rxe

 

Flashing a firmware

Intro

Firmware files have the extension
“.rfw”, exemples are:
  • nxt_bios_rom.rfw, from the nxtOSEK distrib (nxtOSEK/ecrobot/bios/)
  • lms_arm_nbcnxc_128.rfw, from Jon Hansen’s NeXTTool
  • or the standard Lego firmware
If any firmware is installed, the brick must be reset first:
  • press the reset button for 4 seconds (tiny button on the hole under the USB socket)
  • press the orange button, the brick will be in uplod mode (blank screen, emiting a tic-tic sound)
On LinuxWarning:
on Linux, only root can access the brick USB port, thus you have to “sudo” the commands (if you can!). On recent Debian/Ubuntu distributions using udev, you can bypath this problem by copying the ad-hoc rule file
70-lego.rules in /etc/udev/rules.d/.
You can use the fwflash command from libnxt-0.3:
fwflash file.rfw
or the Linux port of the NexTTool program:
NeXTTool /COM=usb -firmware=file.rfw

On Windows

Use NexTTool command line in a windows or cygwin terminal:
NeXTTool.exe /COM=usb -firmware=file.rfw
You can also use the Lego Mindstorm graphical interface, if installed (menu Tools/Upgrade Firmware).

Step by step example: using rom.bin programs on Windows

Warning : only works on Windows XP, not Windows 7

Flash the nxt OSEK bios on Windows

This should be done once:
  1. Put the brick on the “tic-tic” mode: remove/clear any firmware running on the brick: push the reset button until the screen becomes empty, press the orange button: the brick should emit a “tic-tic” sound, it is then ready to be flashed.
  2. Flash the nxt OSEK bios with the NeXTTool.exe utility:

          NeXTTool.exe /COM=usb -firmware=nxt_bios_rom.rfwor simply:biosflash.batAlfter flashing, the screen should be:

Upload a rom.bin program

Nxt BIOS should be in the “UPLOAD: READY” mode. Use the appflash.exe utility to upload the binary, for instance the “helloworld” from the nxtOSEK samples:
appflash.exe  helloworld_OSEK_rom.bin
The screen should be, form left to right:


“UPLOAD: READY” mode

To run the application, switch off the brick (dark grey button), then switch it on (orange button): the “NXT OSEK” splash screen is displayed for a few seconds, then the brick enters the appli STP/RUN mode. Press “RUN” to start the program. When the program is running,

Splash screen

 

STP/RUN screen

 

HelloWorld program screen

 

Replace/re-upload a rom.bin program

Once a rom.bin program has been uploaded, it will remains in the rom of the brick, and then, be executed each time the brick is switched on.In order to replace it, we have to put the brick in teh “UPLOAD: READY” mode: put the brick in the “STP/RUN” mode, then press at the same time the buttons STP and ENTR (left arrow+orange) for a few seconds. The screen will remain empty for a while, then the “UPLOAD: READY” screen should appear. Then, upload a program as explained before.