Module valgol

Description

Parser for the Lesser-Known Language VALGOL.

This is like, a parser for, like, the world's most bitchen programming langugage, written in, like, y'know, the world's second most bitchen programming language?

This program totally demonstrates how to totally do recursive descent parsing in Erlang without using a seperate scanner.

The Gnarly VALGOL Grammar

  Grammar:
  Program   ::= Statement [Program].
  Statement ::= ["LIKE,"] (Command | Expr).
  Command   ::= "START" Program "BAG" ["THIS"] Label
              | "REALLY" Program "GOTO" ["THE"] Label
              | "IF" Expr "THEN" Statement
              | "FOR" Identifier "=" Expression "TO" Expression {Statement} "SURE".
  Expr      ::= E(1) {"AND" E(1) | "OR" E(1)}.
  E(1)      ::= E(2) {"=" E(2) | "-" E(2)}.
  E(2)      ::= E(3) {"+" E(3) | "-" E(3)}.
  E(3)      ::= E(4) {"*" E(4) | "/" E(4)}.
  E(4)      ::= Prim ["**" E(4)].
  Prim      ::= ["LIKE"] Atom ["(" Expr ")"] ["MEAN"].
  Atom      ::= Ident
              | Literal
              | "(" Expr ")"
              | "MAYBE" Expr
              | "TOTALLY" Expr
              | "VALLEY" Expr.
  

Function Index

Exported Functions
parse/1Parses a VALGOL program.
test/1Runs various tests on the VALGOL parser, including the original demo program from the Lesser-Known Languages VALGOL fortune cookie.
Internal Documented Functions
command/2Parses a VALGOL command.
error/2Generates an error.
expect/3Expects a certain token in the input string.
expr/2Parses a VALGOL expression.
optional/3Allows a certain token to be in the input string.
patom/2Parses a VALGOL atom.
prim/2Parses a VALGOL primitive.
program/2Parses a VALGOL program.
statement/2Parses a VALGOL statement.

Exported Functions

parse/1

parse(string()) -> tree()

Parses a VALGOL program. This is the main user interface to the parser.

test/1

test(test_id()) -> tree()

Runs various tests on the VALGOL parser, including the original demo program from the Lesser-Known Languages VALGOL fortune cookie.

Documented Internal Functions

command/2

command(string(), tree()) -> {string(), tree()}

Parses a VALGOL command.

error/2

error(string(), [term()]) -> ok

Generates an error. Not particularly sophisticated.

expect/3

expect(string(), string(), tree()) -> {string(), tree()}

Expects a certain token in the input string. If it is there, it will be consumed; if not, an error is generated.

expr/2

expr(string(), tree()) -> {string(), tree()}

Parses a VALGOL expression.

optional/3

optional(string(), string(), tree()) -> {string(), tree()}

Allows a certain token to be in the input string. If it is there, it will be consumed.

patom/2

patom(string(), tree()) -> {string(), tree()}

Parses a VALGOL atom.

prim/2

prim(string(), tree()) -> {string(), tree()}

Parses a VALGOL primitive.

program/2

program(string(), tree()) -> {string(), tree()}

Parses a VALGOL program. This is the top-level production of the recursive descent parser.

statement/2

statement(string(), tree()) -> {string(), tree()}

Parses a VALGOL statement.