Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
95fa0f99
Commit
95fa0f99
authored
May 24, 2022
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add operator precedence table
parent
a001b533
No related branches found
No related tags found
1 merge request
!145
git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/userdoc.org
+66
-1
66 additions, 1 deletion
doc/userdoc.org
with
66 additions
and
1 deletion
doc/userdoc.org
+
66
−
1
View file @
95fa0f99
...
...
@@ -1540,7 +1540,72 @@ they follow a few rules.
\end{equation*}
#+end_src
*** TODO High-level types<<high-level-types>>
**** Operator precedence and associativity
To avoid confusions, the operators precedence in ~pugs~ language follow
the same rules as in ~C++~.
This is summarized in the following table, where ~a~ and ~b~ denotes two
expressions.
| Precedence | Operator |
|------------+----------|
| 1 | ~a++~ |
| | ~a--~ |
| | ~a[]~ |
|------------+----------|
| 2 | ~++a~ |
| | ~--a~ |
| | ~not a~ |
|------------+----------|
| 3 | ~a*b~ |
| | ~a/b~ |
|------------+----------|
| 4 | ~a+b~ |
| | ~a-b~ |
|------------+----------|
| 5 | ~a<<b~ |
| | ~a>>b~ |
|------------+----------|
| 6 | ~a<b~ |
| | ~a<=b~ |
| | ~a>b~ |
| | ~a>=b~ |
|------------+----------|
| 7 | ~a==b~ |
| | ~a!=b~ |
|------------+----------|
| 8 | ~a=b~ |
| | ~a+=b~ |
| | ~a-=b~ |
| | ~a*=b~ |
| | ~a/=b~ |
As already said, we forbid some constructions to try to avoid spurious
constructions. By construction associativity of many operators makes
no sense in ~pugs~ language (affectations and increment/decrement
operators for instance).
For all other operators, the associativity rule is *left to right*. Thus
the following code
#+BEGIN_SRC pugs :exports source
- 1 + 3 - 4 + 2;
#+END_SRC
is equivalent to
#+BEGIN_SRC pugs :exports source
(((- 1) + 3) - 4) + 2;
#+END_SRC
Obviously ~pugs~ allows the use of parenthesis to write
expressions. It is enough to give a simple example.
#+NAME: parenthesis-precedence
#+BEGIN_SRC pugs :exports both :results output
cout << " 2 + 3 * 4 = " << 2 + 3 * 4 << "\n";
cout << "(2 + 3) * 4 = " << (2 + 3) * 4 << "\n";
#+END_SRC
the output is
#+RESULTS: parenthesis-precedence
*** High-level types<<high-level-types>>
*** TODO Lists
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment