Language Guide
A plcc-ng specification describes a language's tokens, syntax, and semantics.
# Lexical section
skip WHITESPACE /\s+/
token NUM /\d+/
%
# Syntactic section
<Exp> ::= <NUM>
%
# Semantic section
Python
Exp
%%%
def _run(self):
print("Hello")
%%%
# Lexical section
skip WHITESPACE /\s+/
token NUM /\d+/
%
# Syntactic section
<Exp> ::= <NUM>
%
# Semantic section
Java
Exp
%%%
public void _run() {
System.out.println("Hello");
}
%%%
Comments
Comments start with # and end at the end of the current line.
Comments may appear anywhere except in semantic section code blocks.
Section separators
Each section is separated by a line with a single %.
Includes
Although you can define an entire language in a single file, larger
languages are often easier to maintain when split across multiple files
using the %include statement.
%include FILE_PATH
%include is valid in any section, but may not appear in a code block
within the semantic section. FILE_PATH is relative to the directory
containing the file it appears in.
Optional sections
Sections build on one another:
You can start with only a lexical section (no % separator is needed),
or add a syntactic section without defining semantics. This makes it easy
to develop and test a language incrementally.
What next
- Lexical Section —
tokenandskipsyntax, scanning algorithm - Syntactic Section — BNF rules, parse tree class hierarchy
- Semantic Section — embedding code, hooks, target language selection
- Examples — worked examples of increasing complexity