
Arithmetic
(implementation,
source,
output)
A left-recursive (non-LL(1))
Grammarfor simple arithmetic expressions. The embeddedSemanticsevaluate an arithmetic expression in one pass as the source stream is read. Try using an LL(1) recursive descent parser around thisGrammar. It descends forever on all but the simplest expressions, since the productions that recurse are put into theGrammarafter those that terminate recursion, giving them higher precedence when descending the parse tree. TheGrammarsubmits to SLR(1) and LR(1) parsers without conflict.
ArithmeticLL
(implementation,
source,
output)
An LL(1)
Grammarequivalent toArithmeticobtained by removing left recursion. The embeddedSemanticsevaluate an arithmetic expression in one pass as the source stream is read. TheGrammarsubmits to all parsers without conflict.
BitLexer
(implementation,
source,
output)
Illustrates use of a
Lexiconalone as a lexical analyzer.
CodeGenerator
(implementation,
source,
output)
An LL(1)
Grammarfor a small programming language with statements and expressions. The embeddedSemanticsgenerate assembler code for a simple stack-oriented machine in one pass as the source stream is read.
ERE
(implementation)
A
Grammarfor POSIX extended regular expressions (EREs), as used in egrep. The embeddedSemanticsconstruct anExpressionfrom aStringcontaining an ERE. It is used in the Generic Interpreter to implement theLexicon.expression(String)method.
Java10
(implementation)
An allegedly LALR(1) (and therefore LR(1))
Grammarfor Java 1.0. I encounter conflicts when parsing aConstructorBodywith a lookahead terminal likethis, which could appear first in anExplicitConstructorInvocationlikethis(argument);or a
Statementlikethis.field = argument;There are no embedded
Semantics.
Java12
(implementation)
A
Grammarfor Java 1.2. There are no embeddedSemantics.
Java20
(implementation)
A
Grammarfor Java 2.0. There are no embeddedSemantics... I don't have that much free time ;)
TypeChecker
(implementation,
source,
output)
An LL(1)
Grammarfor a small subset of Pascal. The embeddedSemanticsperform type checking in one pass as the source stream is read. If no semantic errors occur, an attributedParseTreeis printed.
PureLisp
(implementation,
source,
output)
An SLR(1)
Grammarfor Pure Lisp, an original version of Lisp authored by John McCarthy. The embeddedSemanticsinterpret Pure Lisp expressions. The example source shows a Tower of Hanoi (what else) algorithm in Pure Lisp.
VirtualMachine
(implementation,
source,
output)
An SLR(1)
Grammarfor an assembler language, such as that generated by theCodeGeneratorexample above. The embedded semantics operate a simple stack-oriented machine with a runtime stack, memory, instruction counter and comparator, and print the state of the machine after executing assembler code.