Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

[ Forum ] [ Prepackaged Downloads ]

Goldie Home -> Documentation (v0.01/v0.02) -> Sample Apps

THIS IS AN OLD VERSION

For documentation on a newer version of Goldie, see Documentation For Specific Versions.

Goldie: Sample Apps

The following sample apps are included with Goldie (including precompiled binaries for Windows and Linux x86):

Parse Anything

Parses any source file according to any GOLD language and displays basic information about both the language and the parsed source.

Try using the included lang/calc.cgt language on the *.calc files. Or use your own GOLD language and source.

Parse Anything Source

Sample run:

> cat valid_sample2.calc
4*4*3
 /4
- ( 10 + 0 )
* -100
> parseAnything valid_sample2.calc lang/calc.cgt
Grammar Info:
File:   lang/calc.cgt
Name:   Calc
Verson: 0.01
Author: Nick Sabalausky
About:  Basic Calculator Grammar

Root of parse tree:
  type: NonTerminal
  name: Add Exp

First terminal in parse tree:
  type: Terminal
  name: Number
  content: '4'
  line: 1

Last terminal in parse tree:
  type: Terminal
  name: Number
  content: '100'
  line: 4

Root of parse tree has 3 child node(s):
  Node index 0 is a NonTerminal 'Add Exp' with 1 child node(s)
    and content '4*4*3/4'
    and raw content:
4*4*3
 /4
  Node index 1 is a Terminal '-'
  Node index 2 is a NonTerminal 'Mult Exp' with 3 child node(s)
    and content '(10+0)*-100'
    and raw content:
( 10 + 0 )
* -100

Calculator Dynamic

(Until Goldie v0.03, this is just called "Calculator")

A simple arithmetic calculator utilizing a calculator grammar compiled by GOLD. Demonstrates how to use Goldie's dynamic-style.

Calculator Source

Sample run:

> calculator
Calculator
Loading language...done!
Enter an arithmetic expression ('exit' to exit)

calculator>2+2*20
Result: 42.00000
calculator>(1-3) / 2
Result: -1.00000
calculator>10
Result: 10.00000
calculator>123 {;[
ERROR: (1:5): Syntax Error: '{;['

calculator>2 + * 7
ERROR: Parse error: LALR state #11, Token #4 ("*") "*"
calculator>-10 * -20
Result: 200.00000
calculator>exit

Calculator Static

(Will be added in Goldie v0.03)

This is just like Calculator Dynamic, but instead of using the calc language in Goldie's dynamic-style, it uses the static-style that's generated by the Static Lang tool.

See Also