https://github.com/jsonkao/graphics-compilers
Graphics compiler assignment.
https://github.com/jsonkao/graphics-compilers
Last synced: about 1 year ago
JSON representation
Graphics compiler assignment.
- Host: GitHub
- URL: https://github.com/jsonkao/graphics-compilers
- Owner: jsonkao
- Created: 2018-05-07T14:22:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-09T15:01:18.000Z (about 8 years ago)
- Last Synced: 2025-02-06T10:15:23.809Z (over 1 year ago)
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# compilers
Graphics compiler assignment.
name | input | output
--- | --- | ---
[Lexer](#lexers) | source code | token list
[Parser (syntax)](#parser) | token list | syntax tree
[Semantic Analyzer](#semantic-analyzer) | syntax tree | operation list, symbol table
1. Lexer (input is source code): performs lexical analysis
- Knows valid keywords, literal formats, and identifier formats.
- It does not interpret anything; it only looks for invalid code.
2. Syntactic analyzer: structure, grammar of code
- The lexer's token list is given to the syntactic analyzer, which determines if the order makes sense
3. Semantic analyzer: meaning (e.g. types)
4. Optimizer (optional)
5. Code generator: receives output of semantic analyzer and generates an executable or image (or multiple images).
# Lexers
Types of language tokens:
- grouping symbols (;, {}, (), ...)
- operators
- identifiers
- keywords
- literals
The lexer outputs a list of tokens and gives it to the syntactic analyzer.
We use lex or flex (free lex) to define our tokens. In C, it looks like:
```
[a-zA-Z][\.a-zA-Z0-9_]* {
strcpy(yyval.string, yytext); return STRING;
}
```
# Parser
- Performs syntax analysis
- Checks if token list for valid structure
- Knows the grammar of the language
# Semantic Analyzer
As a program runs, values change. That is the point of the symbol table.