Share & grow the worlds knowledge!
We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
Ngôn ngữ lập trình được tạo ra như thế nào?
Thực sự mình cũng rất muốn hiểu ngôn ngữ lập trình được tạo ra ntn. Bạn có thể nói sơ qua hoặc cho mình vài link để tìm hiểu được không. Tks
programming-language
×
Remain: 5
1 Answer
tvd12
Enlightened
tvd12
Enlightened
Để giải thích ngôn ngữ lập trình được tạo ra như thế nào, trước hết chúng ta phải hiểu kiến trúc máy tính 1 chút đã. Có nhiều loại kiến trúc máy tính, tuy nhiên ở đây chúng ta sẽ chọn một kiến trúc máy tính (đặt tên là YM) đơn giản với 3 thành phần:
- RAM: để lưu các câu lệnh, và dữ liệu.
- CPU: để thực hiện việc tính toán. Bản chất bên trong CPU là các transistor có 2 trạng thái 0 và 1. Từ các transistor này sẽ tạo ra các hàm phần cứng thông qua các phép tính AND, OR, XOR, NOT. Hãy giả sử CPU của chúng ta đã có sẵn hàm ADD để cộng 2 số, hàm GET để lấy dữ liệu từ bộ nhớ, hàm STORE để lưu dữ liệu vào bộ nhớ.
- Clock: đề đặn yêu cầu CPU lấy câu lệnh, và dữ liệu từ RAM và thực thi - Gọi là xung nhịp.
Bây giờ hãy giải sử chúng ta cần cộng 3 số: 1 + 2 + 3 thì máy tính YM sẽ thực thi thế nào? Đầu tiên chúng ta phải nạp vào RAM chương trình thế này:
ADD 1 2 // Thực thi hàm cộng 1 2 ở xung nhịp đầu tiên STORE 0xF // Lưu kết quả hàm cộng vào RAM ở địa chỉ ô nhớ 0xF ở xung nhịp thứ 2 ADD GET(0XF) 3 // Lấy dữ liệu từ RAM ở địa chỉ ô nhớ 0XF và cộng với 3 ở xung nhịp thứ 3 STORE 0XF // Lưu kết quả vào RAM ở địa chỉ ô nhớ 0XF ở xung nhịp thứ 4
Clock sẽ kích hoạt để CPU sẽ thực hiện theo các bước ở như trong comment.
Thì những gì bạn nhìn thấy ở trên đây chính là ngôn ngữ lập trình, và ta có thể gọi nó với từ thân thương đó là assembly.
Tuy nhiên ngôn ngữ assembly này tương đối khó hiểu vì nó không phải ngôn ngữ tự nhiên. Vậy bây giờ chúng ta cần tạo ra một loại ngôn ngữ lập trình mới có tên là C, lúc này chúng ta có thể viết ngắn gọn chương trìn của chúng ta thành:
int add123() { return 1 + 2 + 3; }
Và nhiệm vụ của chúng ta bây giờ là phải tạo ra trình dịch (complier) để dịch
return 1 + 2 + 3; thành chương trình assembly ở trên bằng chính ngôn ngữ assembly. Và chúng ta gọi C là ngôn ngữ biên dịchĐến đây bạn đã dễ hiểu hơn rồi đúng không?
Tuy nhiên chúng ta thấy rằng ngôn ngữ biên dịch khá bất tiện, cứ phải viết mã rồi dịch rồi khởi động lại chương trình thì mới được, vậy nên chúng ta sẽ sẽ tạo ra ngôn ngữ tên là JavaScript, và nhiệm vụ bây giờ của chúng ta là phải tạo ra một cái máy ảo để đi thông dịch cái chương trình javascript ở dạng string sang các câu lệnh của máy ảo ví dụ:
console.log(1 + 2 + 3) thì bên code của máy ảo có thể là:void main() { String script = readScriptFromFile(); String[] strs = script.split(" + "); printf(add123(str[0].toInt(), str[1].toInt(), str[2].toInt())); }
Máy ảo này chúng ta có thể viết bằng C cho đơn giản, và máy ảo cũng sẽ phức tạp hơn ví dụ ở trên rất nhiều.
Một trong những design pattern quan trọng nhất để tạo ra được ngôn ngữ lập trình đó chính là command design pattern anh em nhé.
-
0
- Reply
- Question(s) 1.1K
- Answer(s) 2.2K
- Best answer(s) 136
- User(s) 541
-
Lâm Tấn Lộc added an answer <ul class="markdown-list"><li class="markdown-list-item"> Đầ... 1768014969000 -
-
Related Questions
Recent Activities
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
Top Members
Trending Tags
.net
.net core
.net oop
#formatdate
abstract class
access app
access token
ai
android
ansible
anti-flooding
apache poi
api
app
architecture
artificial intelligence
assembly
async
asyncawait
atomicboolean
authentication
backend
backend nestjs
background
bash script
batch
bean
big project
binding
bitcoin
blockchain
blog
boot-nodes
branch
btree
bucket4j
buffered
build
bundle
c#
c# .net
cache
caching
callback
career
career path
cast
câu hỏi
centos
chat
cloud
cloud reliability
combobox
commit
communication
computer science
concurrent
config-css
connection pool
content-disposition
contract
controllerservice
convert date to number
cookie
cors
cosmos
cosmos-sdk
crawl data
cron
css
database
database migration
datasource
datastructure
datetime
deadlock
debug
decentralized exchange
deep learning
deploy contract
design patterns
design-pattern
dev
devops
dex
di
distraction programing
dns
đồ án tốt nghiệp
docker
download
draw.io
du học
dữ liệu lớn
duration
eclip
editor
elasticsearch
email
erc20
erc721
error
estimation
eth
ethereum
ethereum login
excel
excel-object-mapper
exception
exception handle
exception handler
executor
export compliance
extensions
exyfox
ezydata
ezyfox
ezyfox-boot
ezyfox-server
ezyfoxserver
ezyhttp
ezyjpa
ezymq-kafka
ezyplatform
ezyredis
facebook
fe
filter
floating point
flutter
format json
freetank
front-end
frontend
fullstack
fulltextsearch
future
gallery
game
game-box
game-room
game-server
gateway
get
get file zip
git
glide
go
golang
gorilla
graduation thesis
graphql
grapql
grpc
guide
h2 database
handy terminal
hazelcast
hibernate
hibernateconfig
html
http
https
hyperloglog
image
index
indexing
integration-test
intellij
interface
io
ioc
ipfs
isolate
issue
it
java
java core
java spring
java web
javacore
javascript
javaw
jenkins
jetbrains
job
join
jotform
jpa
jpql
jquery
js
json
json file
json to object
jsonproperty
jsp
jsp & servlet
junit-test
jvm
jwt
kafka
keep promise
kerberos
keycloak
kotlin
languague
laravel
library
list
load balancer
load-balancing
lock
log
log4j
log4j-core
login
lỗi font
lưu trữ
machine learning
macos
mail
mail template
main
map
maria db
markdown
math
maven
merge
mermaid
message queue
messaging
metamask
microservice
microservices
migration
mobile
model
mongo
monitoring
mq
msgpack
multi-threading
multiple tenant
multithread
multithreading
mysql
n
naming
naming convention
nan
netcore
netty
network
networking
nft
nft game
nginx
nio
node.js
nodejs
non-blocking io
null
odoo
oop
opensource
optimize
oracle
orm
otp message
paginaiton
pagination
pancakeswap
panic
partition
pdf
pgpool
phỏng vấn
php
plugin
pointer
postgresql
postman
pre
private_key
procedure
profile
programming
programming-language
project management
promise
properties
push message android
push notification
push-noti
python
python unicode
qr
qrcode
question
queue
rabbitmq
react-native
reactive
reactjs
reactjs download
readmoretextview
recyclerview
redis
refactor
refresh token
regex
replica
repository
request
resilence4j
resource
rest
restful
resttemplate
roadmap
room database
ropssten
ropsten
round robin
rust
rxjava
s3
schedule
scheduled
scheduled spring boot
search
security
send email
send mail
serialization
server
servlet
session
shift jis
singleton
sjis
slack
smart contract
soap
socket
socket server
soft delete
solution
sosanh
spring
spring aop
spring boot
spring data jpa
spring redis
spring security
spring websocket
spring websocket cors
spring-boot-test
spring-jpa
springboot
springsecurity
springwebflux mysql
sql
sql server
sse
ssl
ssl email
stackask
storage
stream
stream api
stress test
stresstest
structure trong spring boot
study
synchronize
synchronized
system environment variables
tcp
test
thiết kế tầng trong dự án
thread
thread pool
threadjava
threadpool
thymeleaf
tomcat
totp
tracking location
transaction
transfer
transfer git
udp
ui
uniswap
unit test
unity
upload
upload file
utf-8 file
validate
validate date
vector
video call
vietqr
view
volatile
vue
vue cli
vuejs
watermark
web
web3
web3 client
webassembly
webflux
webpack
webrtc
websocket
windows 11
winforms
wordpress
work
xss
zip file
zookeeper