Arithmetic evaluation/Ada: Difference between revisions
Content added Content deleted
m (moved Arithmetic Evaluator/Ada to Arithmetic evaluation/Ada) |
m (Fixing syntax highlighting tags) |
||
Line 6: | Line 6: | ||
The implementation provides an advanced error handling and skipping blanks and Ada comments (these are taken from the library). |
The implementation provides an advanced error handling and skipping blanks and Ada comments (these are taken from the library). |
||
< |
<syntaxhighlight lang="ada"> |
||
with Ada.Unchecked_Deallocation; |
with Ada.Unchecked_Deallocation; |
||
with Parsers.String_Source; use Parsers.String_Source; |
with Parsers.String_Source; use Parsers.String_Source; |
||
Line 98: | Line 98: | ||
); |
); |
||
end Parsers.Simple; |
end Parsers.Simple; |
||
</syntaxhighlight> |
|||
</lang> |
|||
Here is the implementation of the package. |
Here is the implementation of the package. |
||
< |
<syntaxhighlight lang="ada"> |
||
with Ada.Characters.Handling; use Ada.Characters.Handling; |
with Ada.Characters.Handling; use Ada.Characters.Handling; |
||
with Ada.Exceptions; use Ada.Exceptions; |
with Ada.Exceptions; use Ada.Exceptions; |
||
Line 269: | Line 269: | ||
end Parsers.Simple; |
end Parsers.Simple; |
||
</syntaxhighlight> |
|||
</lang> |
|||
The next is a little test. It reads a line from the keyboard and then evaluates it. The program stops when the input is empty: |
The next is a little test. It reads a line from the keyboard and then evaluates it. The program stops when the input is empty: |
||
< |
<syntaxhighlight lang="ada"> |
||
with Ada.Exceptions; use Ada.Exceptions; |
with Ada.Exceptions; use Ada.Exceptions; |
||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 312: | Line 312: | ||
end loop; |
end loop; |
||
end Test_Simple_Parser; |
end Test_Simple_Parser; |
||
</syntaxhighlight> |
|||
</lang> |
|||
Sample exchange. When the expression is evaluated its range in the source string is indicated. Upon errors, the location of is shown as well: |
Sample exchange. When the expression is evaluated its range in the source string is indicated. Upon errors, the location of is shown as well: |
||
<pre> |
<pre> |