mirror of
				https://git.sfja.dk/Mikkel/slige.git
				synced 2025-10-29 04:18:30 +00:00 
			
		
		
		
	parser stuff
This commit is contained in:
		
							parent
							
								
									b96dc867ab
								
							
						
					
					
						commit
						35f2574957
					
				
							
								
								
									
										30
									
								
								example-no-types.slg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								example-no-types.slg
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| 
 | ||||
| 
 | ||||
| fn add(a, b) { | ||||
|     + a b | ||||
| } | ||||
| //  | ||||
| // add(2,3); // -> 5 | ||||
| //  | ||||
| // let a = "Hello"; | ||||
| //  | ||||
| // let b = "world"; | ||||
| //  | ||||
| // println(a + " " + b + "!"); // -> "Hello world!" | ||||
| //  | ||||
| // if a == b { | ||||
| //     println("whaaaat"); | ||||
| // } | ||||
| // else { | ||||
| //     println(":o"); | ||||
| // } | ||||
| //  | ||||
| // loop { | ||||
| //     let i = 0; | ||||
| //  | ||||
| //     if i >= 10 { | ||||
| //         break; | ||||
| //     } | ||||
| //  | ||||
| //     i = i + 1; | ||||
| // } | ||||
| @ -109,7 +109,7 @@ export class Lexer { | ||||
|             if (this.test("/")) { | ||||
|                 while (!this.done() && !this.test("\n")) | ||||
|                     this.step(); | ||||
|                 return this.token("//", pos) | ||||
|                 return this.next() | ||||
|             } | ||||
|             return this.token("/", pos) | ||||
|         } | ||||
|  | ||||
| @ -2,7 +2,7 @@ import { Expr, ExprKind, Param, Stmt, StmtKind, BinaryType} from "./ast.ts"; | ||||
| import { Lexer } from "./Lexer.ts"; | ||||
| import { Pos, Token } from "./Token.ts"; | ||||
| 
 | ||||
| class Parser { | ||||
| export class Parser { | ||||
|     private currentToken: Token | null; | ||||
|     private nextNodeId = 0; | ||||
| 
 | ||||
| @ -11,7 +11,7 @@ class Parser { | ||||
|     } | ||||
| 
 | ||||
|     private step() { this.currentToken = this.lexer.next() } | ||||
|     private done(): boolean { return this.currentToken == null; } | ||||
|     public done(): boolean { return this.currentToken == null; } | ||||
|     private current(): Token { return this.currentToken!; } | ||||
|     private pos(): Pos { | ||||
|         if (this.done()) | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -1,13 +1,13 @@ | ||||
| import { Lexer } from "./Lexer.ts"; | ||||
| import { readFileSync } from 'node:fs'; | ||||
| import { Parser } from "./Parser.ts"; | ||||
| 
 | ||||
| 
 | ||||
| const text = readFileSync("example.slg").toString() | ||||
| const text = readFileSync("example-no-types.slg").toString() | ||||
| 
 | ||||
| const lexer = new Lexer(text); | ||||
| let token = lexer.next(); | ||||
| while (token !== null) { | ||||
|     const value = token.identValue ?? token.intValue ?? token.stringValue ?? ""; | ||||
|     console.log(`${token.type}\t${value}`) | ||||
|     token = lexer.next(); | ||||
| const parser = new Parser(lexer) | ||||
| while (!parser.done()) { | ||||
|     const result = parser.parseExpr() | ||||
|     console.log(result) | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user