Grammar-to-code mappings

Compiler

About

This page shows some generated pseudo-code from rule constructs.

Rule modifiers and grammar attributes (like pin, recoverWhile) will add some lines.

List

Sequence

rule ::= part1 part2 part3
public boolean rule() {
  <header>
  boolean result = false;
  result = part1();
  result = result && part2();
  result = result && part3();
  if (!result) <rollback any state changes>
  <footer>
  return result;
}

Ordered choice

rule ::= part1 | part2 | part3
public boolean rule() {
  <header>
  boolean result = false;
  result = part1();
  if (!result) result = part2();
  if (!result) result = part3();
  if (!result) <rollback any state changes>
  <footer>
  return result;
}

Zero-or-more

rule ::= part *
public boolean rule() {
  <header>
  while (true) {
    if (!part()) break;
  }
  <footer>
  return true;
}





Discover More
Compiler
Grammar - Rule Construct / Basic Rule Expression

This page lists common rule expression in order to describe the structure of the parsed document. A rule expression is a pattern expression that produces a boolean and are therefore predicate. grammar...
Grammar Different Structural Trees For The Same Expression
Language - (Grammar | Syntax | Lexicon)

Grammar in the context of a compiler. Ie how to define it. grammar section In processing computer languages, semantic processing generally comes after syntactic processing, but in some cases semantic...



Share this page:
Follow us:
Task Runner