pycplus 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -91
- data/bin/pycplus +51 -12
- data/lib/nodes.rb +13 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fde7222ccd4137c44659d5df46a12bc2cb57facbb373c129d54af19596aeb93
|
4
|
+
data.tar.gz: b86597ee3514507775c3a2be65e9fd8ed1f2778be48d276b45b99898e0ba8223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1437d02dc107e13a85893882db8d325e42d46e62783eeb27c7c58cbf4ce08bc844103e011084a36686ed465fac755bb3e45f96b274e9df4788637fd64ae33bfc
|
7
|
+
data.tar.gz: 03faa5bad0cd3ca3242d64e236995baa1d03337d68fe013d3152e6f2a82d74919c8311cd2d1c1361486a8ff55515134d7cd7c0e3be9931b9f72533160f6adb74
|
data/README.md
CHANGED
@@ -1,93 +1,3 @@
|
|
1
1
|
# TDP019
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Getting started
|
6
|
-
|
7
|
-
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
8
|
-
|
9
|
-
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
10
|
-
|
11
|
-
## Add your files
|
12
|
-
|
13
|
-
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
14
|
-
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
15
|
-
|
16
|
-
```
|
17
|
-
cd existing_repo
|
18
|
-
git remote add origin https://gitlab.liu.se/andjo858-ip/tdp019.git
|
19
|
-
git branch -M main
|
20
|
-
git push -uf origin main
|
21
|
-
```
|
22
|
-
|
23
|
-
## Integrate with your tools
|
24
|
-
|
25
|
-
- [ ] [Set up project integrations](https://gitlab.liu.se/andjo858-ip/tdp019/-/settings/integrations)
|
26
|
-
|
27
|
-
## Collaborate with your team
|
28
|
-
|
29
|
-
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
30
|
-
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
31
|
-
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
32
|
-
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
33
|
-
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
34
|
-
|
35
|
-
## Test and Deploy
|
36
|
-
|
37
|
-
Use the built-in continuous integration in GitLab.
|
38
|
-
|
39
|
-
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
40
|
-
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
41
|
-
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
42
|
-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
43
|
-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
44
|
-
|
45
|
-
***
|
46
|
-
|
47
|
-
# Editing this README
|
48
|
-
|
49
|
-
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
50
|
-
|
51
|
-
## Suggestions for a good README
|
52
|
-
|
53
|
-
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
54
|
-
|
55
|
-
## Name
|
56
|
-
Choose a self-explaining name for your project.
|
57
|
-
|
58
|
-
## Description
|
59
|
-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
60
|
-
|
61
|
-
## Badges
|
62
|
-
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
63
|
-
|
64
|
-
## Visuals
|
65
|
-
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
66
|
-
|
67
|
-
## Installation
|
68
|
-
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
69
|
-
|
70
|
-
## Usage
|
71
|
-
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
72
|
-
|
73
|
-
## Support
|
74
|
-
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
75
|
-
|
76
|
-
## Roadmap
|
77
|
-
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
78
|
-
|
79
|
-
## Contributing
|
80
|
-
State if you are open to contributions and what your requirements are for accepting them.
|
81
|
-
|
82
|
-
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
83
|
-
|
84
|
-
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
85
|
-
|
86
|
-
## Authors and acknowledgment
|
87
|
-
Show your appreciation to those who have contributed to the project.
|
88
|
-
|
89
|
-
## License
|
90
|
-
For open source projects, say how it is licensed.
|
91
|
-
|
92
|
-
## Project status
|
93
|
-
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
3
|
+
TODO
|
data/bin/pycplus
CHANGED
@@ -1,26 +1,65 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/pcpparse'
|
5
6
|
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# Method to print gem version
|
9
|
+
def print_version
|
10
|
+
spec = Gem::Specification.load('../pycplus.gemspec')
|
11
|
+
puts "#{spec.name} version #{spec.version}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def main
|
15
|
+
# Parse other command-line options using OptionParser
|
16
|
+
options = {}
|
17
|
+
OptionParser.new do |opts|
|
18
|
+
|
19
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] filename"
|
20
|
+
|
21
|
+
# version is handled as a special case as it doesn't make sense to use it alongside the other options
|
22
|
+
opts.on("-v", "--version", "Display version information") do
|
23
|
+
print_version
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-d", "--debug", "Enable debug mode") do
|
28
|
+
options[:debug] = true
|
29
|
+
print("dhsdhshdshds")
|
30
|
+
end
|
31
|
+
end.parse!
|
11
32
|
|
12
|
-
|
33
|
+
# Check if a filename argument is provided
|
34
|
+
if ARGV.empty?
|
35
|
+
puts "Error: No filename or arguments provided."
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
filename = ARGV.shift
|
40
|
+
@lang_parser = Pycplus.new
|
13
41
|
|
14
|
-
if
|
15
|
-
|
42
|
+
# Enable debug mode if specified
|
43
|
+
if options[:debug]
|
44
|
+
@lang_parser.log(true)
|
45
|
+
else
|
46
|
+
@lang_parser.log(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
if File.file?(filename)
|
50
|
+
extension = File.extname(filename)
|
16
51
|
|
17
52
|
if extension == ".pcp"
|
18
|
-
@lang_parser.
|
19
|
-
@lang_parser.parse_file(arg)
|
53
|
+
@lang_parser.parse_file(filename)
|
20
54
|
else
|
21
|
-
puts "File is not a .pcp file
|
55
|
+
puts "Error: File is not a .pcp file. Please provide a file with the correct extension."
|
22
56
|
end
|
23
57
|
else
|
24
|
-
puts "Unable to find file #{
|
58
|
+
puts "Error: Unable to find file #{filename}"
|
25
59
|
end
|
26
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
if __FILE__ == $PROGRAM_NAME
|
64
|
+
main
|
65
|
+
end
|
data/lib/nodes.rb
CHANGED
@@ -2,51 +2,38 @@
|
|
2
2
|
|
3
3
|
require_relative 'STL.rb'
|
4
4
|
|
5
|
-
# Class to handle scopes when evaluating AST.
|
6
5
|
class Scope
|
7
|
-
attr_reader :identifiers,:parent_scope
|
6
|
+
attr_reader :identifiers,:parent_scope
|
8
7
|
def initialize(parent_scope = nil)
|
9
8
|
@identifiers = {}
|
10
|
-
@non_local_variables = []
|
11
9
|
@parent_scope = parent_scope
|
12
10
|
end
|
13
11
|
|
14
|
-
# Set variable in current scope
|
15
12
|
def set_variable(name, op, expression)
|
16
|
-
if @non_local_variables.include?(name)
|
17
|
-
raise NameError, "local identifier #{name} referenced before assignment"
|
18
|
-
end
|
19
13
|
if op == '='
|
20
14
|
@identifiers[name] = expression
|
21
15
|
else
|
22
|
-
|
23
|
-
|
24
|
-
end
|
16
|
+
id_scope = get_scope(name)
|
17
|
+
@identifiers[name] = get_identifier(name) if id_scope
|
25
18
|
if op == '+='
|
19
|
+
@identifiers[name] = 0 if !id_scope
|
26
20
|
@identifiers[name] += expression
|
27
21
|
else
|
22
|
+
@identifiers[name] = 0 if !id_scope
|
28
23
|
@identifiers[name] -= expression
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
33
|
-
def set_non_local_variable(name)
|
34
|
-
unless @non_local_variables.include?(name) && is_function(name)
|
35
|
-
@non_local_variables.append(name)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Get value of identifier in current or parent scope(s) if defined.
|
40
28
|
def get_identifier(name)
|
41
29
|
scope = get_scope(name)
|
42
30
|
if scope
|
43
31
|
return scope.identifiers[name]
|
44
32
|
else
|
45
|
-
raise NameError,"Identifier #{name} not defined
|
33
|
+
raise NameError,"Identifier #{name} not defined."
|
46
34
|
end
|
47
35
|
end
|
48
36
|
|
49
|
-
# Get first scope where identifier is defined.
|
50
37
|
def get_scope(name)
|
51
38
|
if @identifiers.has_key?(name)
|
52
39
|
return self
|
@@ -55,20 +42,17 @@ class Scope
|
|
55
42
|
end
|
56
43
|
end
|
57
44
|
|
58
|
-
# Checks if a identifier is a function.
|
59
45
|
def is_function?(name)
|
60
46
|
scope = get_scope(name)
|
61
47
|
id_value = scope.get_identifier(name) if scope
|
62
48
|
return id_value.is_a?(Hash)
|
63
49
|
end
|
64
50
|
|
65
|
-
# Set a function in current scope.
|
66
51
|
def set_function(name, block, parameters)
|
67
52
|
@identifiers[name] = {:parameters => parameters, :block => block}
|
68
53
|
end
|
69
54
|
end
|
70
55
|
|
71
|
-
|
72
56
|
class BlockNode
|
73
57
|
def initialize(statements = nil)
|
74
58
|
@block = statements
|
@@ -118,10 +102,10 @@ class FunctioncallNode
|
|
118
102
|
return result
|
119
103
|
end
|
120
104
|
|
121
|
-
def evaluate_block(parameters, block,
|
122
|
-
new_scope = Scope.new(
|
105
|
+
def evaluate_block(parameters, block, scope)
|
106
|
+
new_scope = Scope.new(scope)
|
123
107
|
parameters.zip(@arguments).each do |parameter, argument|
|
124
|
-
new_scope.set_variable(parameter, '=', argument.evaluate(
|
108
|
+
new_scope.set_variable(parameter, '=', argument.evaluate(scope))
|
125
109
|
end
|
126
110
|
|
127
111
|
result = block.evaluate(new_scope)
|
@@ -151,7 +135,7 @@ class FunctioncallNode
|
|
151
135
|
parameters = function[:parameters]
|
152
136
|
block = function[:block]
|
153
137
|
validate_arguments(parameters)
|
154
|
-
evaluate_block(parameters, block,scope
|
138
|
+
evaluate_block(parameters, block, scope)
|
155
139
|
end
|
156
140
|
end
|
157
141
|
end
|
@@ -290,12 +274,9 @@ class IdentifierNode < PrimitiveNode
|
|
290
274
|
def evaluate(scope)
|
291
275
|
if scope.is_function?(@value)
|
292
276
|
raise SyntaxError, "Identifier #{@value} is assigned to a function. Please use correct syntax for function call."
|
277
|
+
else
|
278
|
+
return scope.get_identifier(@value)
|
293
279
|
end
|
294
|
-
id_value = scope.get_identifier(@value)
|
295
|
-
unless scope.identifiers.has_key?(@value)
|
296
|
-
scope.set_non_local_variable(@value)
|
297
|
-
end
|
298
|
-
return id_value
|
299
280
|
end
|
300
281
|
end
|
301
282
|
|
@@ -306,5 +287,4 @@ class DigitNode < PrimitiveNode
|
|
306
287
|
end
|
307
288
|
|
308
289
|
class BoolNode < PrimitiveNode
|
309
|
-
end
|
310
|
-
|
290
|
+
end
|