filmov
tv
How To Make Your Own Programming Language #coding #programming #computerscience

Показать описание
Here’s how to write your OWN programming language.
Step 1. Come up with a grammar. This consists of coming up with the syntax for your language, keywords that are included, and deciding how these parts interact with each other. Are you going to use brackets to denote code blocks or white space?
Step 2. Figure out the semantics. How is your language going to handle data types and variable scope? Is it object-oriented, functional, or procedural, or maybe some weird Frankenstein mix of them?
Step 3. Decide if it’s going to be interpreted or compiled; for now, let’s assume it’s interpreted because that makes our lives easier.
Step 4. Write a *lexer*. This is what breaks down your source code into *tokens*, which are the smallest units of your language, the keywords you defined in your grammar. Things like while, if, etc.
Step 5. Write a *parser*. The parser takes the tokens from the lexer and based on the rules in your grammar constructs an Abstract Syntax Tree (AST). An AST represents the structure of your code. A parent node might be an if statement, and a child node the statement to evaluate if the if statement is true.
Step 6. Implement the semantics. Now that you have an AST, you can move on to actually evaluating the program! This step consists of writing a traversal program for the tree that obeys the rules of your language. Once the tree is fully evaluated, you’ll have the output for the program in your programming language!
Step 7: Add bells and whistles like error handling, optimization, etc., etc..
And boom, you now have a programming language.
These are the three best things about being a computer science major and why you should major in computer science.
Current Sub Count: 17,337
Music In This Video:
(I do get benefits from the above link)
WHO AM I?
Step 1. Come up with a grammar. This consists of coming up with the syntax for your language, keywords that are included, and deciding how these parts interact with each other. Are you going to use brackets to denote code blocks or white space?
Step 2. Figure out the semantics. How is your language going to handle data types and variable scope? Is it object-oriented, functional, or procedural, or maybe some weird Frankenstein mix of them?
Step 3. Decide if it’s going to be interpreted or compiled; for now, let’s assume it’s interpreted because that makes our lives easier.
Step 4. Write a *lexer*. This is what breaks down your source code into *tokens*, which are the smallest units of your language, the keywords you defined in your grammar. Things like while, if, etc.
Step 5. Write a *parser*. The parser takes the tokens from the lexer and based on the rules in your grammar constructs an Abstract Syntax Tree (AST). An AST represents the structure of your code. A parent node might be an if statement, and a child node the statement to evaluate if the if statement is true.
Step 6. Implement the semantics. Now that you have an AST, you can move on to actually evaluating the program! This step consists of writing a traversal program for the tree that obeys the rules of your language. Once the tree is fully evaluated, you’ll have the output for the program in your programming language!
Step 7: Add bells and whistles like error handling, optimization, etc., etc..
And boom, you now have a programming language.
These are the three best things about being a computer science major and why you should major in computer science.
Current Sub Count: 17,337
Music In This Video:
(I do get benefits from the above link)
WHO AM I?
Комментарии