-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramming_lang.py
More file actions
77 lines (71 loc) · 3.35 KB
/
programming_lang.py
File metadata and controls
77 lines (71 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Language:
# define class attributes
Grammar = "a set of rules that describe how words and phrases are arranged in a language"
Languages = {
"Python": {
"Field": "General-purpose",
"Recognizing_Automaton": "Python virtual machine",
"Production_rules": "Python syntax and semantics",
"Examples": ["print('Hello, world!')", "x = 5 + 3", "import math"]
},
"Java": {
"Field": "General-purpose",
"Recognizing_Automaton": "Java Virtual Machine (JVM)",
"Production_rules": "Java syntax and semantics",
"Examples": ["System.out.println('Hello, world!');", "int x = 5 + 3;", "import java.util.*;"]
},
"C": {
"Field": "Systems programming",
"Recognizing_Automaton": "C compiler",
"Production_rules": "C syntax and semantics",
"Examples": ["printf('Hello, world!');", "int x = 5 + 3;", "#include <stdio.h>"]
},
"Fortran": {
"Field": "Scientific computing",
"Recognizing_Automaton": "Fortran compiler",
"Production_rules": "Fortran syntax and semantics",
"Examples": ["WRITE(*,*) 'Hello, world!'", "REAL :: x = 5.0 + 3.0", "USE math_module"]
},
"Ruby": {
"Field": "Web development",
"Recognizing_Automaton": "Ruby interpreter",
"Production_rules": "Ruby syntax and semantics",
"Examples": ["puts 'Hello, world!'", "x = 5 + 3", "require 'math'"]
}
# Add more programming languages and their attributes here...
}
def __init__(self, name):
# define instance attribute
self.name = name
def __str__(self):
# return a string representation of the instance
return f"This is an instance of the Language class with the name {self.name}"
@classmethod
def recognize(cls, language_name):
if language_name in cls.Languages:
language = cls(language_name)
print(f"Recognized language: {language.name}")
print(f"Field of implementation: {cls.Languages[language.name]['Field']}")
print(f"Grammar: {cls.Grammar}")
print(f"Recognizing Automaton: {cls.Languages[language.name]['Recognizing_Automaton']}")
print(f"Production Rules (Constraints): {cls.Languages[language.name]['Production_rules']}")
print(f"Examples using {language.name}:")
for example in cls.Languages[language.name]['Examples']:
print(f"- {example}")
else:
print("Language not recognized.")
def recognize_programming_language():
print("Welcome to the Programming Language Recognition System!")
print("This system can provide information about various programming languages.")
print("Here are the available languages:")
print(list(Language.Languages.keys()))
while True:
language_name = input("Enter the name of a programming language or 'exit' to quit: ")
if language_name.lower() == "exit":
print("Thank you for using the Programming Language Recognition System. Goodbye!")
break
else:
Language.recognize(language_name)
print()
# Example usage:
recognize_programming_language()