<commit_before>=pod

=head1 Basic Syntax

Z<CHP-3>

X<PIR syntax>

PIR has a relatively simple syntax. Every line is a comment, a label, a
statement, or a directive. Each statement or directive stands on its own
line. There is no end-of-line symbol (such as a semicolon in C).

=head2 Comments

X<comments>
A comment begins with the C<#> symbol, and continues until the end of the line.
Comments can stand alone on a line or follow a statement or directive.

=begin PIR

    # This is a regular comment. The PIR
    # interpreter ignores this.

=end PIR

X<Pod documentation>
PIR also treats inline documentation in Pod format as a comment. An
equals sign as the first character of a line marks the start of a Pod
block.  A C<=cut> marker signals the end of a Pod block.

  =head2

  This is Pod documentation, and is treated like a
  comment. The PIR interpreter ignores this.

  =cut

=head2 Labels

X<PIR (Parrot intermediate representation);labels> X<labels (PIR)>
A label attaches a name to a line of code so other statements can refer to it.
Labels can contain letters, numbers, and underscores. By convention, labels use
all capital letters to stand out from the rest of the source code. It's fine to
put a label on the same line as a statement or directive:

=begin PIR_FRAGMENT

    GREET: say "'Allo, 'allo, 'allo."

=end PIR_FRAGMENT

Labels on separate lines improve readability, especially when outdented:

=begin PIR_FRAGMENT

  GREET:
    say "'Allo, 'allo, 'allo."

=end PIR_FRAGMENT

=head2 Statements

Z<CHP-3-SECT-1>

X<statements (PIR)>
X<PIR (Parrot intermediate representation);statements>
A statement is either an opcode or syntactic sugar for one or more opcodes. An
opcode is a native instruction for the virtual machine; it consists of the name
of the instruction followed by zero or more arguments.

=begin PIR_FRAGMENT

  say "Norwegian Blue"

=end PIR_FRAGMENT

PIR also provides higher-level constructs, including symbolic operators:

=begin PIR_FRAGMENT

  $I1 = 2 + 5

=end PIR_FRAGMENT

These special statement forms are just syntactic sugar for regular opcodes. The
C<+> symbol corresponds to the C<add> opcode, the C<-> symbol to the C<sub>
opcode, and so on. The previous example is equivalent to:

=begin PIR_FRAGMENT

  add $I1, 2, 5

=end PIR_FRAGMENT

=head2 Directives

X<directives (PIR)>
X<PIR (Parrot intermediate representation);directives>

Directives resemble opcodes, but they begin with a period (C<.>).  Some
directives specify actions that occur at compile time. Other directives
represent complex operations that require the generation of multiple
instructions.  The C<.local> directive, for example, declares a named variable.

=begin PIR_FRAGMENT

  .local string hello

=end PIR_FRAGMENT

=head2 Literals

X<literals (PIR)>
X<PIR (Parrot intermediate representation);literals>

Integers and floating point numbers are numeric literals. They can be positive
or negative.

=begin PIR_FRAGMENT

  $I0 = 42       # positive
  $I1 = -1       # negative

=end PIR_FRAGMENT

Integer literals can also be binary, octal, or hexadecimal:

=begin PIR_FRAGMENT

  $I1 = 0b01010  # binary
  $I2 = 0o78     # octal
  $I3 = 0xA5     # hexadecimal

=end PIR_FRAGMENT

Floating point number literals have a decimal point, and can use scientific
notation:

=begin PIR_FRAGMENT

  $N0 = 3.14
  $N2 = -1.2e+4

=end PIR_FRAGMENT

X<strings;in PIR>
String literals are enclosed in single or double-quotes.N<See the
section on L<Strings> in Chapter 4 for an explanation of the differences
between the quoting types.>

=begin PIR_FRAGMENT

  $S0 = "This is a valid literal string"
  $S1 = 'This is also a valid literal string'

=end PIR_FRAGMENT

=head2 Variables

X<variables (PIR)>
X<PIR (Parrot intermediate representation);variables>
X<PMC; definition>
<commit_msg>[book] Fixing failing example test, invalid octal constant.<commit_after>=pod

=head1 Basic Syntax

Z<CHP-3>

X<PIR syntax>

PIR has a relatively simple syntax. Every line is a comment, a label, a
statement, or a directive. Each statement or directive stands on its own
line. There is no end-of-line symbol (such as a semicolon in C).

=head2 Comments

X<comments>
A comment begins with the C<#> symbol, and continues until the end of the line.
Comments can stand alone on a line or follow a statement or directive.

=begin PIR

    # This is a regular comment. The PIR
    # interpreter ignores this.

=end PIR

X<Pod documentation>
PIR also treats inline documentation in Pod format as a comment. An
equals sign as the first character of a line marks the start of a Pod
block.  A C<=cut> marker signals the end of a Pod block.

  =head2

  This is Pod documentation, and is treated like a
  comment. The PIR interpreter ignores this.

  =cut

=head2 Labels

X<PIR (Parrot intermediate representation);labels> X<labels (PIR)>
A label attaches a name to a line of code so other statements can refer to it.
Labels can contain letters, numbers, and underscores. By convention, labels use
all capital letters to stand out from the rest of the source code. It's fine to
put a label on the same line as a statement or directive:

=begin PIR_FRAGMENT

    GREET: say "'Allo, 'allo, 'allo."

=end PIR_FRAGMENT

Labels on separate lines improve readability, especially when outdented:

=begin PIR_FRAGMENT

  GREET:
    say "'Allo, 'allo, 'allo."

=end PIR_FRAGMENT

=head2 Statements

Z<CHP-3-SECT-1>

X<statements (PIR)>
X<PIR (Parrot intermediate representation);statements>
A statement is either an opcode or syntactic sugar for one or more opcodes. An
opcode is a native instruction for the virtual machine; it consists of the name
of the instruction followed by zero or more arguments.

=begin PIR_FRAGMENT

  say "Norwegian Blue"

=end PIR_FRAGMENT

PIR also provides higher-level constructs, including symbolic operators:

=begin PIR_FRAGMENT

  $I1 = 2 + 5

=end PIR_FRAGMENT

These special statement forms are just syntactic sugar for regular opcodes. The
C<+> symbol corresponds to the C<add> opcode, the C<-> symbol to the C<sub>
opcode, and so on. The previous example is equivalent to:

=begin PIR_FRAGMENT

  add $I1, 2, 5

=end PIR_FRAGMENT

=head2 Directives

X<directives (PIR)>
X<PIR (Parrot intermediate representation);directives>

Directives resemble opcodes, but they begin with a period (C<.>).  Some
directives specify actions that occur at compile time. Other directives
represent complex operations that require the generation of multiple
instructions.  The C<.local> directive, for example, declares a named variable.

=begin PIR_FRAGMENT

  .local string hello

=end PIR_FRAGMENT

=head2 Literals

X<literals (PIR)>
X<PIR (Parrot intermediate representation);literals>

Integers and floating point numbers are numeric literals. They can be positive
or negative.

=begin PIR_FRAGMENT

  $I0 = 42       # positive
  $I1 = -1       # negative

=end PIR_FRAGMENT

Integer literals can also be binary, octal, or hexadecimal:

=begin PIR_FRAGMENT

  $I1 = 0b01010  # binary
  $I2 = 0o72     # octal
  $I3 = 0xA5     # hexadecimal

=end PIR_FRAGMENT

Floating point number literals have a decimal point and can use scientific
notation:

=begin PIR_FRAGMENT

  $N0 = 3.14
  $N2 = -1.2e+4

=end PIR_FRAGMENT

X<strings;in PIR>
String literals are enclosed in single or double-quotes.N<See the
section on L<Strings> in Chapter 4 for an explanation of the differences
between the quoting types.>

=begin PIR_FRAGMENT

  $S0 = "This is a valid literal string"
  $S1 = 'This is also a valid literal string'

=end PIR_FRAGMENT

=head2 Variables

X<variables (PIR)>
X<PIR (Parrot intermediate representation);variables>
X<PMC; definition>

{'fraction_non_alphanumeric': 0.06553302812295618, 'fraction_numerical': 0.012295618051013734, 'mean_word_length': 4.148821548821549, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6796867', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2396, 'n_words': 1079}