Writing A C Compiler Early Access Nora Sandler 2024 Scribd Download
Writing A C Compiler Early Access Nora Sandler 2024 Scribd Download
com
OR CLICK BUTTON
DOWLOAD NOW
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://ebookmeta.com/product/engineering-a-compiler-3rd-edition-
keith-d-cooper/
https://ebookmeta.com/product/osteopathy-and-obstetrics-stephen-
sandler/
https://ebookmeta.com/product/windows-security-internals-with-
powershell-early-access-james-forshaw/
https://ebookmeta.com/product/devops-for-the-desperate-a-hands-
on-survival-guide-early-access-1st-edition-bradley-smith/
Grokking Concurrency (Manning Early Access Program
Version 3) MEAP Kirill Bobrov
https://ebookmeta.com/product/grokking-concurrency-manning-early-
access-program-version-3-meap-kirill-bobrov/
https://ebookmeta.com/product/nora-heysen-a-portrait-anne-louise-
willoughby-2/
https://ebookmeta.com/product/nora-heysen-a-portrait-anne-louise-
willoughby/
https://ebookmeta.com/product/react-18-design-patterns-and-best-
practices-fourth-edition-early-access-anonymous/
https://ebookmeta.com/product/the-machine-learning-solutions-
architect-handbook-2nd-edition-early-access-david-ping/
R L Y
E A S S
C E
AC
NO S TA RCH PRE SS
E A R LY A C C E S S P R O G R A M :
FEEDBACK WELCOME!
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press,
Inc. Other product and company names mentioned herein may be the trademarks of their
respective owners. Rather than use a trademark symbol with every occurrence of a trade-
marked name, we are using the names only in an editorial fashion and to the benefit of the
trademark owner, with no intention of infringement of the trademark.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or by any informa-
tion storage or retrieval system, without the prior written permission of the copyright owner
and the publisher.
The information in this book is distributed on an “As Is” basis, without warranty. While every
precaution has been taken in the preparation of this work, neither the author nor No Starch
Press, Inc. shall have any liability to any person or entity with respect to any loss or damage
caused or alleged to be caused directly or indirectly by the information contained in it.
CONTENTS
Introduction
2
RETURNING AN INTEGER
which represents the program in a form that we can easily traverse and
analyze.
The code generation pass converts the AST into assembly. At this
stage, we still represent the assembly instructions in a data structure that
the compiler can understand, not as text.
The code emission pass writes the assembly to a file so the assembler
and linker can turn it into an executable.
This is a pretty normal way of structuring a compiler, although the
exact stages and intermediate representations vary. It’s also overkill for this
chapter; the programs you’ll handle here could be compiled in just one pass!
But setting up this structure now will make it easier to expand your compiler
in future chapters. As you implement more language features, you’ll extend
these compiler stages and add a few new ones. Each chapter in the book
starts with a diagram of the compiler's architecture in that chapter, including
the stages you've already implemented and any you'll need to add. Figure 2-
1 shows the four stages you'll implement in this chapter.
Before you start coding, let’s take a quick look at how to compile C to
assembly with GCC, and how to read assembly programs.
Hello, Assembly!
The simplest possible C program looks like this:
1 int main() {
2 return 32;
}
Listing 2-2 The program from Listing 2-1 translated into assembly.
NOTE All the assembly listings in this book use AT&T syntax. Elsewhere, you’ll sometimes
see x64 assembly written in Intel syntax. They’re just two different notations
for the same language; the biggest difference is that they put instruction
operands in different order.
Your .s file might contain a few other assembler directives, but you can
safely ignore them for now. The four lines in Listing 2-2 are a complete
assembly program. Assembly programs have several kinds of statements.
The first line, .globl main 1 , is an assembler directive, a statement
that provides directions for the assembler. Assembler directives always
starts with a period. Here, main is a symbol, a placeholder for a memory
address. An assembly instruction can include a symbol when it needs to
refer to the address of a particular function or variable, but the compiler
doesn’t know where that function or variable will end up in memory. Later,
after the linker has combined the different object files that make up the
executable, it can associate each symbol with a memory address; this
process is called symbol resolution. Then the linker will update every place
that uses a symbol to use the corresponding address instead; this is called
relocation.
The .globl main directive tells the assembler that main is a global
symbol. By default, a symbol can only be used in the same assembly file
(and therefore the same object file) where it’s defined. But because main is
global, other object files can refer to it too. The assembler will record this
fact in a section of the object file called the symbol table. The symbol table
contains information about all the symbols in an object file or executable.
The linker relies on the symbol table during symbol resolution. If the
symbol table doesn’t list main as a global symbol, but another object file
tries to refer to it, linking will fail.
Next, we use main 2 as a label for the code that follows it. Labels
consist of a string or number followed by a colon. This label marks the
location that the symbol main refers to. For example, the instruction jmp
Writing a C Compiler (Early Access) © 2022 by Nora Sandler
main should cause the program to jump to the instruction at line 3. But the
label can’t indicate the final location of main; like I mentioned earlier, we
won’t know that until link time. Instead, it defines main as an offset from
the start of the current section in this object file. (An object file includes
different sections for machine instructions, global variables, debug
information, and so on, which are loaded into different parts of the
program's address space at runtime. The object file produced from Listing 2-
2 will only have one section: the text section, which contains machine
instructions.) Because 3 is the very first machine instruction in this file, the
offset of main will be 0. The assembler will record this offset in the symbol
table so the linker can use it to determine the final address of main during
symbol resolution.
• Ian Lance Taylor’s 20-part essay on linkers goes into a lot more depth. The first post is at
https://www.airs.com/blog/archives/38, and there’s a table of contents at
https://lwn.net/Articles/276782/.
• “Position Independent Code (PIC) in shared libraries,” a blog post by Eli Bendersky, provides an
overview of how compilers, linkers, and assemblers work together to produce position-
independent code, focusing on 32-bit machines
(https://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/).
• “Position Independent Code (PIC) in shared libraries on x64,” also by Eli Bendersky, builds on
the previous article, focusing on 64-bit systems
(https://eli.thegreenplace.net/2011/11/11/position-independent-code-pic-in-shared-libraries-on-
x64).
3. Invokes the exit system call, passing it the return value from main.
Then exit handles whatever work needs to happen inside the
operating system to terminate the process and turn the return value
into an exit code.
The bottom line is that you don’t need to worry about process startup or
teardown; you can treat main like a normal function.
To verify that the assembly in Listing 2-2 works correctly, you can
assemble and link it, run it, and check the exit code with the $? shell
operator:
$ gcc return_2.s -o return_2
$ ./return_2
$ echo $?
2
Note that you can pass an assembly file to GCC just like a regular
source file. GCC assumes any input files with a .s extension contain
assembly, so it will just assemble and link those files without trying to
compile them first.
Writing a C Compiler (Early Access) © 2022 by Nora Sandler
3. Compile the preprocessed source file, and output an assembly file with
a .s extension. You’ll have to stub out this step, since you haven’t
written your compiler yet.
you can start writing the lexer, you need to know what tokens you might
encounter. Here are all the tokens in Listing 2-1:
int: a keyword
main: an identifier, whose value is “main”
( : an open parenthesis
) : a close parenthesis
{ : an open brace
return: a keyword
2: a constant, whose value is “2”
; : a semicolon
} : a close brace
I’ve used two lexer-specific terms here. An identifier is an ASCII letter
followed by a mix of letters and digits; identifiers are case sensitive. An
(integer) constant consists of one or more digits. (C supports hexadecimal
and octal integer constants too, but you can ignore them to keep things
simple. We’ll add character and floating-point constants in part II.)
Note that identifiers and constants have values in the list of tokens
above, but the other types of tokens don’t. There are many possible
identifiers (foo, variable1, or my_cool_function), so each
identifier token produced by the lexer needs to retain its specific name.
Likewise, each constant token needs to hold an integer value. By contrast,
there's only one possible return keyword, so a return keyword token
doesn't need to store any extra information. Even though main is the only
identifier right now, it’s a good idea to build the lexer in a way that can
support arbitrary identifiers later on. Also note that there are no whitespace
tokens. If we were compiling a language like Python, where whitespace is
significant, we’d need to include whitespace tokens.
You can define each token type with a regular expression. Table 2-1
gives the corresponding regular expression for each token in PCRE syntax:
Open parenthesis
\(
Close parenthesis
\)
Open brace
{
Close brace
}
Semicolon
;
Note that identifiers and constants must end at word boundaries. For
example, the first three digits of 123;bar match the regular expression for
a constant, and can be converted into the constant 123. That’s because ;
isn’t in the \w character class, so the boundary between 3 and ; is a word
boundary.
However, the first three digits of 123bar do not match the regular
expression for a constant, because those digits are followed by more
characters in the \w character class instead of a word boundary. If your
lexer sees a string like 123bar it should raise an error, because the start of
the string doesn’t match the regular expression for any token.
You can assume that your C source file only contains ASCII characters.
The C standard provides a mechanism called universal character names to
include non-ASCII characters in identifiers, but we won’t implement them.
Many C implementations let you use Unicode characters directly, but you
don’t need to support that either.
This command just tests whether the lexer succeeds or fails. You may
want to write your own tests to validate that it produces the correct list of
tokens for valid programs and emits an appropriate error for invalid ones.
Implementation Tips
Treat keywords like other identifiers. The regex for identifiers also
matches keywords. Don’t try to simultaneously find the end of the next
token and figure out whether it’s a keyword or not. First, find the end of
the token. Then, if it looks like an identifier, check whether it matches
any of the keywords.
Don’t split on whitespace. It might seem like a good idea to start by
splitting the string on whitespace, but it’s not. It will just complicate
things, because whitespace isn’t the only boundary between tokens. For
example, main() has three tokens and no whitespace.
tools.
Handwritten parsers also have some practical advantages over those
produced by parser generators; they can be faster and easier to debug, and
provide better support for error handling. In fact, both GCC and Clang use
handwritten parsers. So writing a parser by hand isn’t just an academic
exercise.
That said, if you’d rather use a parser generator, that’s fine too! It all
depends on what you’re hoping to get out of the book. But I won’t talk
about how to use them, so you’ll have to figure that out on your own. If you
decide to go that route, make sure to research what parsing libraries are
available in your implementation language of choice.
Whichever option you choose, the first step is designing the abstract
syntax tree you want your compiler to produce. It might help to see an
example of an AST first.
This is an if statement, so we’ll label the root of the AST if. The if
node will have two children:
EVENING “HATE.”
During this period the men not in the front lines were kept busy
unloading supplies at the beaches and transporting them to the
dumps, road-making, trench and well digging, and performing many
other fatigues. The sappers, who had landed on the 9th and 10th of
May, had their hands more than full. The 1st Field Company was in
bivouac near Morto Bay on the right, and the 2nd Field Company on
the left flank near Pink Farm, a solitary building which became a
famous landmark and rendezvous during the campaign. They
directed the construction of trenches, of lines of rifle-pits in front of
the trenches, of dug-outs, and trench-bridges for armoured cars,
improvements of the rough country tracks, work on wells and
appliances for distribution of drinking water, and the manufacture of
bombs. The digging, deepening, and repairing, and, when material
was available, the strengthening of trenches was a never-ending
task, which had to be performed under fire from artillery, machine
guns, and snipers. The soil was mainly a stiff yellow loam, which
stood well unrevetted until rain came, when it was transformed into
peculiarly bad mud, and the water would not drain away. Gorse and
heather, outcroppings of rock, and in one or two sectors, the tough
fir-roots, which interlaced and formed a network at varying depths,
added considerably to the difficulties.
The Field Ambulances on landing had equal difficulties to
encounter, and the way in which they contrived to overcome them
and to makeshift successfully afforded proof of their resource.
Dressing stations had to be made in clefts in the cliffs, with tarpaulin
sheets stretched from boulder to boulder for shelter. The shortage of
appliances and equipment during the first weeks was a serious
handicap. As soon as their equipment arrived they moved up to the
rear of the bivouacs in the centre of the line. The battalion stretcher-
bearers had quickly “made good.” They had had to stand the usual
chaff while training, but within a week of landing they had become
“heroes” in the eyes of their comrades. The Field Ambulances,
lacking tackle, had not been able to provide bearers to evacuate
from First-Aid Posts, and the battalion stretcher-bearers carried the
wounded a distance of three miles to the beach.
Practically everything required for the army in Gallipoli had to be
brought from the base at Mudros, the harbour of the Island of
Lemnos, nearly forty miles away. Even water was conveyed overseas
to supplement the inadequate local supply. Rations, ammunition,
equipment, and material of all sorts were transferred from the ships
to flat-bottomed lighters and landed, frequently in rough weather,
and generally under fire from the Asiatic coast. The small A.S.C. unit
therefore did not enjoy much leisure. No. 2 Transport and Supply
Company had given evidence of its efficiency, for, though within ten
days after landing it had lost forty-one animals killed, it was found
that they possessed one more than the original number landed.
Many loose mules were straying around, and the company upheld
the rather unenviable reputation of which it boasted in pre-war days
of never passing any unconsidered trifles by.
A Divisional Supply dump had been established on the top of the
cliffs above “W” Beach, and there it remained until the evacuation.
Though in a very exposed position and under daily shell fire it
enjoyed a remarkable immunity. The rations were “man-handled”
from the beaches to this dump, where they were issued to the
Regimental Quartermasters, who brought with them their limbers
when they had any, but usually A.S.C. limbers took rations to the
R.Q.M.’s dump, about a mile inland, where they were divided in
proportion to the strength of companies. Here battalion transport
men loaded the pack-animals and led them across country for two or
three miles to Battalion Headquarters, a short distance in the rear of
the trenches, where the stores were unloaded, and the Transport
Officer’s responsibility ended. At Battalion Headquarters a party from
each company in the trenches was waiting to carry the rations to
Company Headquarters, where the C.Q.M.S. issued to the platoon
sergeants the share for their men, and the platoon sergeants in due
course divided the articles among the section commanders.
On paper this simple daily routine is a mere Transport and
matter of efficient organization, but in active Rations
practice it was something more. The Turk had a
very good idea of the routes to be taken, and as he fired more
vigorously during the night than in the daytime, the transport,
whenever possible, moved up soon after noon while he indulged in
his siesta. Rations had, however, often to be taken up at night, and
casualties among the A.S.C. men and trench ration parties were
frequent. None of the pack-animals had previously been under fire.
The load must be packed with equal weight on either side or it will
not reach its destination, for the mule, though a convinced
individualist, has nothing to learn from the best-organized trade
union in the matter of direct action or the lightning strike. The loads
consisted of full boxes and half-filled boxes of bully-beef tins, tins of
biscuits, jars of rum, sacks of loaves, whole cheeses, tins of jam,
bags of tea and sugar, sides of bacon, and on mail-days bags of
letters and parcels. The correct balancing and securing of such
articles, even on a placid, well-trained horse in a paddock at home,
where no more disturbing explosions are to be feared than those
caused by a distant motor-cycle, demands no mean skill and sense
of proportion. But when shells are bursting close at hand, and mules
and horses do their best to prevent the loading and dislodge the
loads, it is a very different affair. When the loading has at last been
accomplished and the animal is asked to move he will probably kick
and buck until the load goes to the winds. Both mules and horses
behaved uncommonly well under fire. On the rough tracks the mule
was far steadier than the horse and could carry an equal weight. He
was more particular about the perfect balance of his load, and would
not attempt to carry an uneven pack.
Having finally completed the packing and persuaded the animals
to start on the journey to Battalion Headquarters the Transport
Officer’s troubles take another turn. He has to find his way in the
dark across an open bullet-swept zone with animals that jib and shy
as the shells burst, or lie down as the fit takes them, and at times
succeed in scattering their packs. These must be collected and
laboriously replaced, the driver meanwhile employing the most
spirited and forcible terms of endearment in his vocabulary. At times
the convoy will be held up by heavy shelling of the area that has to
be crossed. Leaving the open they enter one of the nullahs up and
down which hundreds of troops are moving, and progress is slow
and exasperating. But in spite of all obstacles the transport men
daily got the rations through to their comrades in the line. Nor
should a word of gratitude to the Indian drivers of the A.T. carts and
the Zion Mule Corps be omitted. These men gave efficient help in
the transport of stores and material from the beaches to the dumps,
and their courage under fire was admirable. The pride the Indians
took in the smart and clean turn-out of their mules and carts was
the more noticeable as they did not appear to be subject to the
ordeal of inspection.
The journeys of the ration-parties from Battalion Headquarters to
Company Headquarters were no less exciting than those of the
battalion transport parties. Bearing heavy boxes or bags on heads or
shoulders they crossed from trench to trench in the open, tripping
over wire, stumbling into holes, dodging rifle fire, and, too often,
falling victims to the sniper. But the rations arrived and the men
were fed.
The rations were monotonous and ill-suited to the climate. They
consisted of bacon (for breakfast), bully-beef and biscuit, with a little
jam and cheese, a tin of Maconochie’s vegetable rations being at
first, but not later, considered a treat, but Maconochie was
particularly unsuited to a hot climate. Fruit—even good tinned fruit—
and fresh vegetables would have done much to preserve the health
of the men during the intense heat of the summer. In due course
every man became a more or less expert cook, and to be on visiting
terms was a privilege not unattended by risk, as it involved the
sampling of many weird experiments and decoctions. Bread from the
tents on Bakery Beach was first issued on May 21, and was received
with acclamation.
Firewood was very scarce, as there were few trees or bushes, but
it had to be obtained somehow for the trench fires over which the
men brewed their tea and cooked their food. It was therefore not
uncommon in the Helles area, in spite of orders issued to diminish
waste, to see a caseful of tins of bully-beef tipped out on the
roadside, that the invaluable wooden case might be split up for fuel.
Butts of rifles which lay beside their dead owners met the same fate.
Evidence of the awful waste of war abounded—weapons,
ammunition, equipment, food, clothing, trodden under foot, and left
to rust and decay. Where man could not expose himself by day
these things remained unsalved for months, but elsewhere they
were collected and returned to store. The best place where wood
could be “won” was above Bakery Beach. A sentry was put over the
wood-pile, but interesting conversation and a few cigarettes would
occasionally distract his attention for the needful time.
On May 21 the Brigade Commanders received instructions from
the Divisional Commander on various points connected with the
latest methods and conditions of siege warfare, such as the use of
bombs, sandbags, and loopholes, and the action of snipers. One
officer, one N.C.O. and four men from each company were instructed
in bombing, under the officer commanding the R.E., and each
infantry brigade was allotted 400 bombs. It was found, however,
that no more than 225 bombs were available for distribution among
the three brigades. The bombs were made from empty jam tins sent
down from the trenches to Lancashire Landing, where they were
filled (chiefly by the divisional butchers and bakers at first) with old
nails, bits of shell and of barbed wire, and other scraps of metal and
an explosive charge. At first a time fuse was fitted through the top of
the tin, and this had to be lighted by the aid of a match, but before
long a detonating fuse was fitted. Matches were scarce and valuable,
and in wind and rain many were wasted before the fuse could be
lighted. These bombs were first issued in very small quantities about
an hour before the attack began on June 4.
On the 25th of May occurred the memorable cloud-burst on Achi
Baba, and in a few moments the nullahs were in spate, the trenches
flooded, and thousands of men soaked to the skin. It was an Act of
God which could not be foreseen or provided against, and the
hardship inflicted upon the troops was very great. For a time the
Krithia Nullah was impassable, and many dead Turks were carried
down. The Lancashire Fusiliers Brigade Headquarters was under four
feet of water for several hours, and the Signal Office was washed
away. One battalion was enjoying beef-steaks in the dug-outs when
a roar of water was heard, and a stream twenty feet wide quickly
filled every dug-out. With British tenacity the men held on to chunks
of bread and of steak as they scrambled for higher ground.
Towards the end of the month the submarine The Submarine
menace developed into a very real danger to the Menace
men-of-war in these waters. The battleship
Triumph was torpedoed on May 25 as she lay at anchor with nets
out, off Anzac. She sank in ten minutes with a loss of ten officers
and sixty-eight men. Two days later, the Majestic, Rear-Admiral
Nicholson’s flagship, lying off Cape Helles, fell a victim to the same
German submarine, and sank in six fathoms. Fortunately all but
forty-eight men were saved. This disaster was witnessed by many of
the Territorials on the beaches and cliffs. As other British and French
battleships were attacked by submarines about the same time, it
became clear that naval co-operation must be dispensed with, or
considerably reduced, as ships at anchor offered too easy a target
for torpedoes.
The Queen Elizabeth had been ordered home on the first hint of
danger, and now all the large ships were sent back to the safety of
Mudros, and the regatta-like gathering at the mouth of the
Dardanelles melted away. The Turk promptly seized the opportunity
for propaganda purposes. An ingeniously worded pamphlet, printed
in English, French, and Hindustani, and dropped from aeroplanes,
notified the invaders that all their battleships and transports had
been destroyed, that the Germans had gained control of the seas,
and that no further supplies need be expected. “Don’t take our word
for it, but see for yourselves. Last week you saw a large fleet of all
kinds of vessels off Cape Helles. Look for it to-day. You have fought
bravely; give yourselves up now to an enemy who respects your
valour and will treat you well.” Tommy laughed. He had got his
rations for the day, and the morrow would take care of itself.
On the 25th of May the designation of the Division was changed,
and as the “42nd (East Lancashire) Division” it took precedence in
numerical order of all other Territorial divisions. The Lancashire
Fusilier Brigade became the 125th Infantry Brigade; the East
Lancashire Brigade the 126th; and the Manchester Brigade the
127th. On May 27 the 126th Brigade was split up among various
battalions of the 29th Division in order to bring those depleted
battalions up to strength pending the arrival of drafts from England.
CHAPTER III
GALLIPOLI
(June 1915—January 1916)
Gallipoli Peninsula
Southern Zone
Map shewing British Trenches and Turkish Front Line
On June 3 orders for the attack were issued. The French objective
was the line of the Kereves Dere Nullah. The first objective of the
8th Army Corps (of which the 42nd Division formed the centre, with
the 29th Division and the Indian Brigade on their left, and the R.N.
Division on the right) was the main line of Turkish trenches, about
200 yards from the British first line. The second objective was the
enemy’s third line.
At 8 a.m. the next morning (June 4) the heavy guns and howitzers
would open the bombardment of certain strong positions. At 11.5
a.m. an intense bombardment of the enemy trenches would begin.
At 11.20 all guns except those on the approach lines would cease
fire, and the infantry would cheer, raise their bayonets above the
parapet, as though about to assault, with the object of inducing the
Turk to occupy his front trenches, which would be heavily
bombarded by all guns and howitzers, the machine-guns firing in
bursts as targets presented themselves. At 12 noon the first line of
infantry would advance, without firing, to the assault of the first
objective, the batteries lifting to range on the trenches farther back.
At 12.15 the second wave would advance, pass through the first
line, and attack the second objective.
Divisional conferences were held at the Headquarters of the 125th
Brigade, and General Douglas issued and explained his orders, and
disposed the troops under his command as follows: First wave—two
battalions of the 127th Brigade consisting of a half-battalion each of
the 7th, 5th, 8th and 6th Manchesters, from right to left in the order
named. The objective for this line was the front line of the Turkish
trenches. A half-battalion of the 5th Lancashire Fusiliers was to
follow in support on the left flank. The second wave consisted of the
remaining half-battalions of the 127th Brigade. Their orders were to
rush through the front line of Turkish trenches and gain the second
objective, which was less than a mile from Krithia. A half-battalion of
the 6th L.F., as working party, and the 1st Field Company, R.E., were
to follow the first wave; the other half-battalion and the 2nd Field
Company were to follow the second wave, to consolidate the lines
gained. All the above troops were under the command of Brig.-
General Noel Lee. The remaining half-battalion of the 5th L.F. was to
form the garrison of the line of trenches held as the firing-line before
the attack. The 9th Manchesters were to occupy the second line,
which was strengthened by redoubts. The 7th and 8th Lancashire
Fusiliers were to be in Divisional Reserve. The 9th Manchesters was
the only battalion of the 126th Brigade acting with the Division, the
4th and 5th East Lancashires and the 10th Manchesters being still
split up among the skeleton battalions of the 29th Division.
The bombardment that opened at 8 a.m. on Battle of June 4,
June 4 was the heaviest and most prolonged that 1915
the peninsula had witnessed. At 11 a.m. every
available gun both on land and sea was firing, including six batteries
of four guns each of the famous 75’s, generously lent by the French
Commander. These were firing high-explosive shell. The whole
Turkish line was enveloped in smoke, and it seemed impossible that
any positions could withstand its fury. The village of Krithia and,
indeed, the whole of the hillside appeared to be a mass of flame and
dust. The plan to cease fire on the front trenches at 11.20 a.m. had
the effect intended, and the enemy prepared to meet the expected
assault. A hail of bullets swept over the trenches of the 127th
Brigade, and a few moments later the renewal of the bombardment
caught the Turks as they were manning the trenches or hastening
through the communication trenches to reinforce their thinly held
front line.
The last half-hour of waiting was a severe test of nerves, and it
was a relief both to the imaginative and the stolid when the hour of
noon arrived. But the Manchesters had already been proved. The
operations of the end of May, the digging in No Man’s Land to push
the first line closer to the enemy, while the Turk knew perfectly well
what was intended and had been able, by the light of a waxing
moon, to thin out the working-parties, had been highly dangerous
and trying to the nerves. The losses had been deplorable, but the
will to overcome the difficulties and to face the dangers with
resolution had prevailed, and had given officers, N.C.O.s and men
confidence in one another. Each platoon, each company, knew that it
would not let the others down when the big event should come off.
And now the hour had struck. Promptly at twelve o’clock the leading
wave of the 127th Brigade went over the top for the first time, and
advanced steadily and in good order. They were met by devastating
rifle and machine-gun fire, but those who escaped the bullets
pressed on in a steady line and by bitter hand-to-hand fighting made
good their first objective. In places the wire was untouched by the
bombardment, and men died cutting it that their comrades might
pass through. The second wave followed at the appointed time.
Within five minutes the Turkish first-line trenches had been
captured, and the second in half an hour, and during the afternoon
the fourth line of Turkish trenches had been penetrated. Sappers
accompanying the successive waves found and disconnected buried
mines, and assisted in the construction of new trenches and the
reversal of captured ones. On the left the 29th Division had seized
their first objective, but their further advance was checked, as the
barbed wire on their left remained undamaged, and the Indian
Brigade was held up by this obstacle. The professional soldiers of
this division paid generous tribute to the amateurs of the 4th and
5th East Lancashires and 10th Manchesters, who fought with such
spirit and determination within their ranks.
On the right, however, an initial success was soon followed by a
reverse which had disastrous consequences. The R.N. Division had
gone forward with a dash that did credit to these young untrained
soldiers, and with a considerable measure of success. On their right
the French had rushed a formidable redoubt, called from its shape
“the Haricot,” but unfortunately their colonial troops, magnificent in
attack, lack the confidence and dogged resolution in adversity that
characterize our “native” troops from the Punjab and Nepal. They
gave way before a furious bombardment and counter-attack, and the
Haricot, once more in Turkish possession, proved a fatal obstacle.
With their right flank exposed to the concentrated fire of
innumerable machine-guns the Naval Division, cruelly reduced in
numbers—one brigade losing sixty officers—were compelled to fall
back to their original line, leaving the right flank of the 42nd Division
in the air, the gap being 300 yards from front to rear. The Turk
possesses individual initiative and resource in full measure, and he
was quick to take advantage of the situation. Also, he was amply
provided with bombs, whereas at this date our men had none—a
serious handicap in close fighting. His bombing parties began to eat
their way into this flank, which was also enfiladed by rifle and
machine-gun fire, and in spite of the most determined opposition of
the Manchesters, of the L.F. who were in support, and of a party of
Engineers under Lieutenant Oscar Taunton, who threw back the
enemy’s grenades until wounded, the position became critical.
In the meantime the 7th Lancashire Fusiliers had been moved up
to the old fire trenches when these were vacated by the second
wave, and at 2.45 p.m. two companies of the 8th L.F. were sent to
fill the gap between the right of the 127th Brigade and the R.N.
Division. At 3.35 p.m. it was seen that the enemy was massing
troops in a nullah on this flank, seriously threatening the foremost
line. The French Commander had, however, promised to make a
fresh attack on the Haricot at 4 p.m., and this, by enabling the R.N.
Division to advance, should relieve the pressure. Our Allies were
unable, however, to make this attack, and the position of the 7th
Manchesters on the right becoming quite untenable, the Divisional
Commander, after consulting the Corps Commander, at 6.30 p.m.
ordered the withdrawal of the foremost line to the main Turkish
trench. The retirement was made with the greatest reluctance;
indeed, the few remaining officers had great difficulty in making the
men realize that the order to withdraw must be obeyed. The idea of
giving up the ground they had won was almost unbearable, for the
four Manchester battalions had resolved to hold on to their gains,
whatever the cost might be. “C” Company of the 6th Manchesters
had penetrated to a considerable distance beyond the bifurcation of
the nullahs, but, being enfiladed from the higher ground on the
right, found it impossible to retire. Its commander, Captain H. B.
Pilkington, was mortally wounded in the head, but, propped up in
the trench, he continued to direct and encourage his men. The
company was practically wiped out.
The cost had indeed been great. Of the 770 men of the 6th
Manchesters only 160 answered to the roll-call that night. A
company of the 8th Manchesters which at noon leapt out of the
trenches nearly 200 strong, could only muster 18, and from the
other units there were similar reports. Early in the afternoon Brig.-
General Noel Lee had received a shell-wound in the throat from
which he died on June 21 in hospital at Malta. When he fell, Lieut.-
Colonel Heys, 8th Manchesters, assumed command, until, an hour
later, he was compelled to return to his battalion, as hardly any of its
officers were left; and he was killed soon after he rejoined. The last
remaining officer of this battalion, Captain Oldfield, was killed shortly
after he had organized the withdrawal of the battalion. Lieut.-Colonel
Lord Rochdale, 6th Lancashire Fusiliers, was ordered to succeed
Colonel Heys, and he remained in temporary command of the 127th
Brigade until June 21. The 7th Manchesters had also lost their C.O.,
Major Staveacre, who had succeeded to the command of the
battalion on May 28, when Lieut.-Colonel Gresham was invalided to
Malta.
The work of the Battalion Medical Officers and stretcher-bearers
was beyond praise, but what can be said of the grit of the wounded!
One M.O. records that from the 120 men who passed through his
Regimental Aid Post, many being badly wounded and obviously in
great pain, he did not hear even a whimper. Much difficulty was
experienced in getting the wounded down the crowded and battered
trenches and communication ways. The advanced Dressing Station
of the 3rd Field Ambulance was in the Achi Baba Nullah, half a mile
above Backhouse Post; that of the 1st Field Ambulance was at
Clapham Junction. It was a rough journey for wounded men from
either of these posts to the Central Clearing Station on “W” Beach;
only hand carriage was available for those who could not walk, and
there were many casualties among the bearers, though they were
not fired upon deliberately. The wounded could not be attended to
quickly enough to prevent a line of stretcher cases, waiting to be
dressed, forming outside the stations.
The Territorials had proved themselves in the Division’s first
pitched battle, not merely with credit, but with distinction. Though
the assaulting waves had been exposed to converging fire from
higher ground on either flank their attack had been brilliantly
successful. At the end of the day the front had only been advanced
by 400 yards, yet the Manchesters had gained 1000 yards, and could
have advanced still farther. Indeed, there can be little doubt that the
Turkish centre had been pierced, and that, had not the troops on
their right been compelled to fall back, or had there been reserves to
bring forward, they would have seized the high ground behind the
village of Krithia, the key to the Achi Baba position. The Division had
captured 217 prisoners, including 11 officers.
The 5th of June was mainly given over to the consolidation of the
front to meet the expected counter-attack. On the evening of the
5th the first line was still held by the 127th Brigade, but during the
night part of it was relieved by the 125th Brigade. There were two
weak points—
The result was that a tactical point of some importance had been
won and held by the tenacity of the 125th Brigade, and that a large
Turkish force had been pinned down when urgently needed in the
north. The Turks had, indeed, been massing troops in front of the
Division as they had intended to attack our lines in force, on the 6th
or 7th of August. Sir Ian Hamilton telegraphed to the Corps
Commander: “Your operations have been invaluable, and have given
the Northern Corps the greatest possible help by drawing the main